Построить фрактал Торн. Thorn Fractal для его построения используються следующие формулы: void main() { #include <stdio.h> #include <stdlib.h> #include <graphics.h> #include <conio.h> #include <time.h> #include <math.h> int main () { int gdriver = DETECT, gmode, errorcode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, "С:\\BORLANDC\\BGI"); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* return with error code */ } struct TComplex { double x; double y; }; int iter = 15; int max = 400; TComplex z, t, c ; double p ; int x, y, n ; int mx, my ; int i ; for (i=0 ; i< 15 ; i++) setpalette(i,i); // задаем палитру for (i=0 ; i< 15 ; i++) setrgbpalette(i,i*4,i*4,i*4); // задаем палитру mx = getmaxx() / 2; //береться маскимальное значение по горизонтали и делиться на 2 my = getmaxy() / 2; //береться маскимальное значение по вертикали и делиться на 2 for (y = -my; y < my; y++) for (x= -mx; x< mx; x++) { n = 0; z.x = x * 0.01; z.y = y * 0.01; c.x = 1; c.y = 1; while (((z.x*z.x) + (z.y*z.y) < max) && (n < iter)) { t = z; // z.x = t.x/cos(t.y) + c.x; z.y = t.y/cos(t.x) + c.y; n++; } putpixel(mx + x, my + y, n); if (kbhit()) break; } getch(); closegraph(); return 0; }
Ключевые слова:
Thorn Fractal
|
|||||||