Sea Creature 1
// // seacreature1.c - Creates a fractal "sea creature" // Written by Ted Burke, last updated 3-8-2016 // // gcc seacreature1.c -o seacreature1 -lm // ./seacreature1 // ffmpeg -framerate 20 -i %03d.pgm seacreature1.gif // #include <stdio.h> #include <complex.h> #include <math.h> #define W 640 #define H 640 void main() { unsigned char pixels[H][W]; // n is used to count iterations of the iterating function // x and y and pixel coordinates // t is frame number and T is the total number of frames // z and c are the complex variables in the iterating function // pwx was originally pixel width, but isn't exactly that now int n, x, y, t, T=100; complex double z, c; double pxw = 4.0 / H; char filename[100]; FILE *f; // Generate all frames in the animation for (t=0 ; t<T ; ++t) { // Calculate pixel values for current frame for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x) { c = cexp(I*(t*M_PI*2.0/T)) * cpow(pxw * ((x-W/2) + (y-H/2)*I), -3.0 + 0.0*creal(cexp(I*(2.0*M_PI*t)/(0.5*T)))); z = -0.25 + 0.25*cexp(I*(2.0*M_PI*t)/(0.5*T)); for (n=0 ; n<50 && cabs(z)<4.0 ; ++n) z = z*z + c; pixels[y][x] = 5*n; } // Write current frame to PGM image file sprintf(filename, "%03d.pgm", t); fprintf(stderr, "Writing %s...", filename); f = fopen(filename, "w"); fprintf(f, "P5\n%d %d\n255\n", W, H); fwrite(pixels, 1, W*H, f); fclose(f); fprintf(stderr, "DONE\n"); } }
Sea Creature 2
// // seacreature2.c - Creates a fractal "sea creature" // Written by Ted Burke, last updated 3-8-2016 // // gcc seacreature2.c -o seacreature2 -lm // ./seacreature2 // ffmpeg -framerate 30 -i %03d.pgm -vf reverse seacreature2.gif // #include <stdio.h> #include <complex.h> #include <math.h> #define W 640 #define H 640 void main() { unsigned char pixels[H][W]; // n is used to count iterations of the iterating function // x and y and pixel coordinates // t is frame number and T is the total number of frames // z and c are the complex variables in the iterating function // pwx was originally pixel width, but isn't exactly that now int n, x, y, t, T=100; complex double z, c, centre; double pxw = 6.0 / H; char filename[100]; FILE *f; centre = -0.625 -0.1*I; // Generate all frames in the animation for (t=0 ; t<T ; ++t) { // Calculate pixel values for current frame for (y=0 ; y<H ; ++y) for (x=0 ; x<W ; ++x) { c = 1/(pxw * ((x-W/3) + (y-H/2)*I)); z = centre + 0.175 + 0.075*cexp(I*(2.0*M_PI*t)/T); for (n=0 ; n<50 && cabs(z)<8.0 ; ++n) z = z*z + c; pixels[y][x] = n<2 ? 255 : 5*n; } // Write current frame to PGM image file sprintf(filename, "%03d.pgm", t); fprintf(stderr, "Writing %s...", filename); f = fopen(filename, "w"); fprintf(f, "P5\n%d %d\n255\n", W, H); fwrite(pixels, 1, W*H, f); fclose(f); fprintf(stderr, "DONE\n"); } }
Advertisements
I need your help on a static ac voltage regulator (dynamic voltage regulator)