Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <fcntl.h>
- #include <stdlib.h>
- void color();
- main()
- {
- int k;
- int fd;
- char buffer[100];
- double x,xx,y,cx,cy;
- int iteration,hx,hy;
- int itermax = 100; /* how many iterations to do */
- double magnify=1.0; /* no magnification */
- int hxres = 1500; /* horizonal resolution */
- int hyres = 1500; /* vertical resolution */
- char pic[hyres][hxres][3];
- /* header for PPM output */
- printf("%d %d\n255\n",hxres,hyres);
- for (hy=1;hy<=hyres;hy++) {
- for (hx=1;hx<=hxres;hx++) {
- cx = (((float)hx)/((float)hxres)-0.5)/magnify*3.0-0.7;
- cy = (((float)hy)/((float)hyres)-0.5)/magnify*3.0;
- x = 0.000001; y = 0.000001;
- for (iteration=1;iteration<itermax;iteration++) {
- xx = x*x-y*y+cx;
- y = 2.0*x*y+cy;
- x = xx;
- if (x*x+y*y>100.0){
- iteration = 9999999;
- int inset = 0;
- k = iteration;
- }
- }
- if (iteration<9999999){
- color(35,0,0);
- pic[hy][hx][0] = 0;
- pic[hy][hx][1] = 0;
- pic[hy][hx][2] = 0;
- }
- else {
- color(42,0,0);
- pic[hy][hx][0] = k * 255;
- pic[hy][hx][1] = k * 255 / 2;
- pic[hy][hx][2] = k * 255 / 2;
- }
- }
- }
- if ((fd = open("mand.tga", O_RDWR+O_CREAT, 0)) == -1)
- {
- printf("error opening file\n");
- exit(1);
- }
- buffer[0] = 0;
- buffer[1] = 0;
- buffer[2] = 2;
- buffer[8] = 0; buffer[9] = 0;
- buffer[10] = 0; buffer[11] = 0;
- buffer[12] = (hxres & 0x00FF); buffer[13] = (hxres & 0xFF00) >> 8;
- buffer[14] = (hyres & 0x00FF); buffer[15] = (hyres & 0xFF00) >> 8;
- buffer[16] = 24;
- buffer[17] = 0;
- write(fd, buffer, 18);
- write(fd, pic, hxres*hyres*3);
- close(fd);
- }
- void color(int red, int green, int blue) {
- fputc((char)red,stdout);
- fputc((char)green,stdout);
- fputc((char)blue,stdout);
- }
Advertisement
Add Comment
Please, Sign In to add comment