Skip to content

Commit cc125c1

Browse files
author
Pete Garcin
committed
New recipes
1 parent 3b27230 commit cc125c1

41 files changed

Lines changed: 3521 additions & 1646 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 FB36
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Interactive Mandelbrot Fractal Using HTML5 Canvas
2+
Originally published: 2017-06-06 03:48:09
3+
Last updated: 2017-06-06 03:48:09
4+
Author: FB36
5+
6+
Interactive Mandelbrot Fractal Using HTML5 Canvas.
7+
8+
(Download and save as html file and open it.)
9+
10+
(Tested only using Firefox browser.)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<html>
2+
<head><title>Interactive Mandelbrot Fractal Using HTML5 Canvas</title></head>
3+
<body>
4+
5+
<canvas id="canvas" width="512" height="512">
6+
Your browser does not support HTML5 Canvas.
7+
</canvas>
8+
9+
<br>
10+
<b>Keys:</b>
11+
<br>
12+
<b>+: zoom in</b>
13+
<br>
14+
<b>-: zoom out</b>
15+
<br>
16+
<b>a: move left</b>
17+
<br>
18+
<b>d: move right</b>
19+
<br>
20+
<b>w: move up</b>
21+
<br>
22+
<b>s: move down</b>
23+
24+
<script type="text/javascript">
25+
// FB36 - 201706050 (0:Monday)
26+
// Tested only using Firefox
27+
28+
document.onkeypress = function(evt)
29+
{
30+
evt = evt || window.event;
31+
var charCode = evt.keyCode || evt.which;
32+
var charStr = String.fromCharCode(charCode);
33+
var p = 0.1; // 10 percent
34+
var d = 0.0;
35+
// zoom in
36+
if(charStr == '+')
37+
{
38+
d = (xmax - xmin) * p;
39+
xmin = xmin + d;
40+
xmax = xmax - d;
41+
d = (ymax - ymin) * p;
42+
ymin = ymin + d;
43+
ymax = ymax - d;
44+
};
45+
// zoom out
46+
if(charStr == '-')
47+
{
48+
d = (xmax - xmin) * p;
49+
xmin = xmin - d;
50+
xmax = xmax + d;
51+
d = (ymax - ymin) * p;
52+
ymin = ymin - d;
53+
ymax = ymax + d;
54+
};
55+
// move left
56+
if(charStr == 'a')
57+
{
58+
d = (xmax - xmin) * p;
59+
xmin = xmin - d;
60+
xmax = xmax - d;
61+
};
62+
// move right
63+
if(charStr == 'd')
64+
{
65+
d = (xmax - xmin) * p;
66+
xmin = xmin + d;
67+
xmax = xmax + d;
68+
};
69+
// move up
70+
if(charStr == 'w')
71+
{
72+
d = (ymax - ymin) * p;
73+
ymin = ymin - d;
74+
ymax = ymax - d;
75+
};
76+
// move down
77+
if(charStr == 's')
78+
{
79+
d = (ymax - ymin) * p;
80+
ymin = ymin + d;
81+
ymax = ymax + d;
82+
};
83+
84+
DrawMandelbrotFractal(xmin, xmax, ymin, ymax, mr0, mr1, mg0, mg1, mb0, mb1);
85+
};
86+
87+
function DrawMandelbrotFractal(xmin, xmax, ymin, ymax, mr0, mr1, mg0, mg1, mb0, mb1)
88+
{
89+
var canvas = document.getElementById('canvas');
90+
var context = canvas.getContext('2d');
91+
var xr = context.canvas.width;
92+
var yr = context.canvas.height;
93+
var imgd = context.createImageData(xr, yr);
94+
var pix = imgd.data;
95+
96+
var maxIt = 256;
97+
var x = 0.0; var y = 0.0;
98+
var zx = 0.0; var zx0 = 0.0; var zy = 0.0;
99+
var zx2 = 0.0; var zy2 = 0.0;
100+
101+
for (var ky = 0; ky < yr; ky++)
102+
{
103+
y = ymin + (ymax - ymin) * ky / yr;
104+
for(var kx = 0; kx < xr; kx++)
105+
{
106+
x = xmin + (xmax - xmin) * kx / xr;
107+
zx = x; zy = y;
108+
for(var i = 0; i < maxIt; i++)
109+
{
110+
zx2 = zx * zx; zy2 = zy * zy;
111+
if(zx2 + zy2 > 4.0) break;
112+
zx0 = zx2 - zy2 + x;
113+
zy = 2.0 * zx * zy + y;
114+
zx = zx0;
115+
}
116+
var p = (xr * ky + kx) * 4;
117+
pix[p] = i % mr0 * mr1; // red
118+
pix[p + 1] = i % mg0 * mg1; // green
119+
pix[p + 2] = i % mb0 * mb1; // blue
120+
pix[p + 3] = 255; // alpha
121+
}
122+
}
123+
124+
context.putImageData(imgd, 0, 0);
125+
}
126+
127+
// main
128+
var xmin = -2.0; var xmax = 1.0;
129+
var ymin = -1.5; var ymax = 1.5;
130+
131+
// these are for coloring the image
132+
var mr0 = 0; var mg0 = 0; var mb0 = 0;
133+
while(mr0 == mg0 || mr0 == mb0 || mg0 == mb0)
134+
{
135+
mr0 = Math.pow(2, Math.ceil(Math.random() * 3 + 3));
136+
mg0 = Math.pow(2, Math.ceil(Math.random() * 3 + 3));
137+
mb0 = Math.pow(2, Math.ceil(Math.random() * 3 + 3));
138+
}
139+
var mr1 = 256 / mr0; var mg1 = 256 / mg0; var mb1 = 256 / mb0;
140+
141+
DrawMandelbrotFractal(xmin, xmax, ymin, ymax, mr0, mr1, mg0, mg1, mb0, mb1);
142+
143+
</script>
144+
</body>
145+
</html>

‎recipes/Python/546530_Size_of_Python_objects_revised/LICENSE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2016 Jean Brouwers
1+
Copyright 2017 Jean Brouwers
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## Size of Python objects (revised).
22
Originally published: 2008-02-20 12:12:20
3-
Last updated: 2016-07-15 23:23:40
3+
Last updated: 2017-07-22 15:52:01
44
Author: Jean Brouwers
55

6-
This recipe determines the size of Python objects in bytes and has been further enhanced to handle ints and namedtuples better, including more tests.
6+
This recipe determines the size of Python objects in bytes and has been further enhanced to handle ints, namedtuples, arrays and NumPy types better. Functions *alen* and *itemsize* have been updated. Support for Python 2.5 and earlier and the tests/examples have been removed. See project [Pympler](https://github.com/pympler/pympler) for unit tests.
77

88
See also other, simpler recipes like this [Compute memory footprint of an object and its contents](http://code.activestate.com/recipes/577504).

0 commit comments

Comments
 (0)