Skip to content

Commit 0c1d9c6

Browse files
committed
add more files
1 parent 056762c commit 0c1d9c6

File tree

5 files changed

+719
-2
lines changed

5 files changed

+719
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.swp
2+
.ipynb_checkpoints/

create_fractal.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Python
2+
def create_fractal(image, width, height, iters):
3+
pixel_size_x = 3.0 / width
4+
pixel_size_y = 2.0 / height
5+
for y in range(height):
6+
imag = y * pixel_size_y - 1
7+
yy = y*width
8+
for x in range(width):
9+
real = x * pixel_size_x - 2
10+
color = mandel(real, imag, iters)
11+
image[yy+x] = color
12+
13+
*/
14+
15+
int mandel(int x, int y, int max_iters, unsigned char * val);
16+
17+
void create_fractal(unsigned char * image, int width, int height,
18+
int iters) {
19+
float pixel_size_x = 3.0 / width;
20+
float pixel_size_y = 2.0 / height;
21+
for (int y=0; y<height; y++) {
22+
float imag = y * pixel_size_y - 1;
23+
int yy = y * width;
24+
for (int x=0; x<width; x++) {
25+
float real = x * pixel_size_x - 2;
26+
unsigned char color;
27+
int ret = mandel(real, imag, iters, &color);
28+
image[yy + x] = color;
29+
}
30+
}

main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
int mandel(int x, int y, int max_iters, unsigned char * val);
4+
5+
void create_fractal(unsigned char * image, int width, int height,
6+
int iters);
7+
8+
int write_pbm(unsigned char * image, int width, int height, char * fname)
9+
{
10+
int cnt;
11+
FILE * fid = fopen(fname, "wb");
12+
if (NULL == fid)
13+
return -1;
14+
cnt = f
15+
}
16+
int main(int argc, const char *argv[], const char * env[])
17+
{
18+
return 0;
19+
}

mandel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def mandel(x, y, max_iters):
6868
return 255
6969

7070
@jit
71-
def create_fractal(min_x, max_x, min_y, max_y, image, width, height, iters):
71+
def create_fractal(image, width, height, iters,
72+
min_x=-2.0, max_x=1.0, min_y=-1.0, max_y=1.0):
7273
pixel_size_x = (max_x - min_x) / width
7374
pixel_size_y = (max_y - min_y) / height
7475
for y in range(height):
@@ -95,7 +96,7 @@ def create_fractal(min_x, max_x, min_y, max_y, image, width, height, iters):
9596
fname += '_numpy'
9697
img_as_bytes = image
9798
s = timer()
98-
create_fractal(-2.0, 1.0, -1.0, 1.0, image, width, height, 20)
99+
create_fractal(image, width, height, 20)
99100
e = timer()
100101
print(e - s)
101102
if 0:

pycon2017_cffi.ipynb

Lines changed: 665 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)