Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Grapic.h>
- #include <math.h>
- #include <iostream>
- #include <windows.h>
- // si vous vous demandez pourquoi y a tout ça là :
- const float pi = 3.141592653;
- struct complex { float x, y; };
- complex C (float x, float y) { struct complex ret; ret.x = x; ret.y = y; return ret; }
- complex C_exp (float rho, float theta) { complex ret; ret.x = rho*cos(theta); ret.y = rho*sin(theta); return ret; }
- complex operator+ (complex a, complex b) { complex ret; ret.x = a.x + b.x; ret.y = a.y + b.y; return ret; }
- complex operator- (complex a, complex b) { complex ret; ret.x = a.x - b.x; ret.y = a.y - b.y; return ret; }
- complex operator* (float a, complex b) { complex ret; ret.x = a * b.x; ret.y = a * b.y; return ret; }
- complex operator* (complex a, complex b) { complex ret; ret.x = a.x * b.x - a.y * b.y; ret.y = a.x * b.y + a.y * b.x; return ret; }
- complex scale (complex p, float x, float y, float lambda) { return lambda*(p-C(x,y)); }
- complex translate (complex P, float dx, float dy) { complex ret; ret = P+C(dx,dy); return ret; }
- complex rotate (complex p, float x, float y, float theta) { return (p-C(x,y))*C_exp(1,theta)+C(x,y); }
- void show (complex z) { std::cout << z.x << " + " << z.y << " i"; }
- float abs (complex z) { return sqrt(z.x*z.x + z.y*z.y); }
- float arg (complex z) { if (z.x > 0 or z.y != 0) return 2*atan(z.y/(z.x+abs(z))); else -pi; }
- // c'est du bout d'code que j'ai mis dans un .h et qu'j'ai include après, du coup j'ai juste copié-collé l'contenu du header ^^'
- using namespace grapic;
- const int DIMW = 500;
- const int MAX = 500;
- int f (float x) {
- return DIMW*(x+1)/2;
- }
- float f_inv (float x) {
- return 2*(x-DIMW/2)/DIMW;
- }
- int julia (complex z, complex c) {
- complex julia = z*z+c;
- complex Max_J = julia;
- int Max = 1;
- for (int i = 2; i < 256; i++) {
- julia = julia*julia + c;
- if (abs(julia) > abs(Max_J)) {
- Max_J = julia;
- Max = i;
- }
- }
- return Max;
- }
- void bruh (int a, char b) {
- if (a > 0) for (int i = 0; i < a; i++) printf("%c",b);
- }
- void percentage (float x) {
- bruh((x/DIMW*10+1),'\xDB');
- bruh(((1-x/DIMW)*10-1),'\xB0');
- printf("\r");
- }
- float r (int n) { return std::max(255/3-(255-n),0)*3; }
- float g (int n) { return std::max(255/3-abs((255-n)-255/3),0)*3; }
- float b (int n) { return std::max(255/3-abs((255-n)-2*255/3),0)*3; }
- int main (int, char**) {
- bool stop = false;
- winInit("julia",DIMW,DIMW);
- backgroundColor(0,0,0);
- int i,j;
- int x,y;
- complex z = C(0.32,0.043);
- float z1,z2=0;
- while (!stop) {
- system("cls");
- winClear();
- z2 = 0;
- for (i = 0; i < DIMW; i++) {
- for (j = 0; j < DIMW; j++) {
- if (julia(C(f_inv(i),f_inv(j)),z) > z2) { z2 = julia(C(f_inv(i),f_inv(j)),z); }
- }
- percentage(i);
- }
- printf("\n");
- for (i = 0; i < DIMW; i++) {
- for (j = 0; j < DIMW; j++) {
- z1 = julia(C(f_inv(i),f_inv(j)),z);
- put_pixel(i,j,r(z1*255/z2),g(z1*255/z2),b(z1*255/z2));
- }
- percentage(i);
- }
- system("cls");
- pressSpace();
- printf("Re(z) = "); std::cin >> z.x;
- printf("Im(z) = "); std::cin >> z.y;
- stop = winDisplay();
- }
- winQuit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement