Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int iteration_max = 100;
- float escape = 16;
- int hypersampling_factor = 5; //only relevant for high quality, warning, quadratic growth in computation time
- float xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag;
- void setup() {
- size(1500, 1000); //aspect ratio 3:2 for symmetry
- background(0);
- xup = 2;
- xlow = -2;
- yup = 2;
- ylow = -2;
- /*c1_real = -1;
- c1_imag = 0.2;
- c2_real = -0.5;
- c2_imag = 0.5;*/
- c1_real = -0.102;
- c1_imag = +0.828;
- c2_real = 0.810;
- c2_imag = 0.582;
- /*c1_real = -0.25155795;
- c1_imag = 0.004885681;
- c2_real = -0.8748981;
- c2_imag = 0.03848663;*/
- /*c1_real = -0.5126952;
- c1_imag = -0.11730869;
- c2_real = 0.20672332;
- c2_imag = -0.58003414;*/
- draw_all_sets_std(true, iteration_max, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- draw_all_sets_description();
- draw_all_coords(false, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- String s = "";
- s += "it" + str(iteration_max);
- if (c1_imag >= 0) {
- s += "c1_" + str(c1_real) + "+" + str(c1_imag) + "i";
- } else {
- s += "c1_" + str(c1_real) + str(c1_imag) + "i";
- }
- if (c2_imag >= 0) {
- s += "c2_" + str(c2_real) + "+" + str(c2_imag) + "i";
- } else {
- s += "c2_" + str(c2_real) + str(c2_imag) + "i";
- }
- // comment in to save image
- //save("6view_5x5antial_" + s + ".png");
- }
- void draw() {
- }
- void color_if_point_in_set(int num, int iteration_max, float z_real, float z_imag, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- if (iteration_max == iterate_switch(num, iteration_max, z_real, z_imag, c1_real, c1_imag, c2_real, c2_imag)) {
- fill(0, 255, 0);
- stroke(0, 255, 0);
- } else {
- fill(255, 0, 128);
- stroke(255, 0, 128);
- }
- }
- void draw_all_coords(boolean lines, float xup, float xlow, float yup, float ylow, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- float x1, y1, x2, y2;
- x1 = map(c1_real, xlow, xup, 0, width/3);
- y1 = map(c1_imag, ylow, yup, 0, height/2);
- x2 = map(c2_real, xlow, xup, 0, width/3);
- y2 = map(c2_imag, ylow, yup, 0, height/2);
- textSize(12);
- if ((x1 < width/3) && (0 < x1) && (y1 < height/2) && (0 < y1)) {
- color_if_point_in_set(0, iteration_max, c1_real, c1_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x1 - 2, y1 - 2, 4, 4);
- text("c1", x1 + 2, y1 + 12);
- if (lines) {line(x1, 0, x1, height/2); line(0, y1, width/3, y1);}
- color_if_point_in_set(1, iteration_max, c1_real, c1_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x1 - 2, y1 + height/2 - 2, 4, 4);
- text("c1", x1 + 2, y1 + height/2 + 12);
- if (lines) {line(x1, height/2, x1, height); line(0, y1 + height/2, width/3, y1 + height/2);}
- color_if_point_in_set(2, iteration_max, c1_real, c1_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x1 + width/3 - 2, y1 - 2, 4, 4);
- text("c1", x1 + width/3 + 2, y1 + 12);
- if (lines) {line(x1 + width/3, 0, x1 + width/3, height/2); line(width/3, y1, 2*width/3, y1);}
- color_if_point_in_set(3, iteration_max, c1_real, c1_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x1 + width/3 - 2, y1 + height/2 - 2, 4, 4);
- text("c1", x1 + width/3 + 2, y1 + height/2 + 12);
- if (lines) {line(x1 + width/3, height/2, x1 + width/3, height); line(width/3, y1 + height/2, 2*width/3, y1 + height/2);}
- }
- if ((x2 < width/3) && (0 < x2) && (y2 < height/2) && (0 < y2)) {
- color_if_point_in_set(0, iteration_max, c2_real, c2_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x2 - 2, y2 - 2, 4, 4);
- text("c2", x2 + 2, y2 + 12);
- if (lines) {line(x2, 0, x2, height/2); line(0, y2, width/3, y2);}
- color_if_point_in_set(1, iteration_max, c2_real, c2_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x2 - 2, y2 + height/2 - 2, 4, 4);
- text("c2", x2 + 2, y2 + height/2 + 12);
- if (lines) {line(x2, height/2, x2, height); line(0, y2 + height/2, width/3, y2 + height/2);}
- color_if_point_in_set(2, iteration_max, c2_real, c2_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x2 + width/3 - 2, y2 - 2, 4, 4);
- text("c2", x2 + width/3 + 2, y2 + 12);
- if (lines) {line(x2 + width/3, 0, x2 + width/3, height/2); line(width/3, y2, 2*width/3, y2);}
- color_if_point_in_set(3, iteration_max, c2_real, c2_imag, c1_real, c1_imag, c2_real, c2_imag);
- rect(x2 + width/3 - 2, y2 + height/2 - 2, 4, 4);
- text("c2", x2 + width/3 + 2, y2 + height/2 + 12);
- if (lines) {line(x2 + width/3, height/2, x2 + width/3, height); line(width/3, y2 + height/2, 2*width/3, y2 + height/2);}
- }
- }
- void draw_all_sets_std(boolean high_quality, int iteration_max, float xup, float xlow, float yup, float ylow, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- if (high_quality) {
- println("0/6");
- draw_set_hq(0, iteration_max, 0, int(width/3), 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("1/6");
- draw_set_hq(1, iteration_max, 0, int(width/3), int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("2/6");
- draw_set_hq(2, iteration_max, int(width/3), int(2*width/3), 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("3/6");
- draw_set_hq(3, iteration_max, int(width/3), int(2*width/3), int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("4/6");
- draw_set_hq(4, iteration_max, int(2*width/3), width, 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("5/6");
- draw_set_hq(5, iteration_max, int(2*width/3), width, int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("6/6");
- } else {
- println("0/6");
- draw_set(0, iteration_max, 0, int(width/3), 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("1/6");
- draw_set(1, iteration_max, 0, int(width/3), int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("2/6");
- draw_set(2, iteration_max, int(width/3), int(2*width/3), 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("3/6");
- draw_set(3, iteration_max, int(width/3), int(2*width/3), int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("4/6");
- draw_set(4, iteration_max, int(2*width/3), width, 0, int(height/2), xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("5/6");
- draw_set(5, iteration_max, int(2*width/3), width, int(height/2), height, xup, xlow, yup, ylow, c1_real, c1_imag, c2_real, c2_imag);
- println("6/6");
- }
- draw_all_sets_description();
- }
- void draw_all_sets_description() {
- stroke(255, 0, 0);
- line(width/3, 0, width/3, height);
- line(2*width/3, 0, 2*width/3, height);
- line(0, height/2, width, height/2);
- textSize(12);
- fill(255, 0, 0);
- text("M(c1)", 2, 12);
- text("M'(c1)", 2, height/2 + 12);
- text("M(c2)", width/3 + 2, 12);
- text("M'(c2)", width/3 + 2, height/2 + 12);
- text("J(c1, c2)", 2*width/3 + 4, 12);
- text("J(c2, c1)", 2*width/3 + 4, height/2 + 12);
- }
- void draw_set(int num, int iteration_max, int xleft, int xright, int ytop, int ybottom, float xup, float xlow, float yup, float ylow, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- float z_real, z_imag;
- int i = 0;
- for(int x = xleft; x < xright; x++) {
- for(int y = ytop; y < ybottom; y++) {
- z_real = map(x, xleft, xright, xlow, xup);
- z_imag = map(y, ytop, ybottom, ylow, yup);
- i = iterate_switch(num, iteration_max, z_real, z_imag, c1_real, c1_imag, c2_real, c2_imag);
- if (i == iteration_max) {
- set(x, y, color(255));
- } else {
- //set(x, y, color(int(map(i, 0, iteration_max, 0, 255))));
- set(x, y, color(int(map(log(float(i)/20+1), 0, log(float(iteration_max)/10+1), 0, 255))));
- }
- }
- }
- }
- void draw_set_hq(int num, int iteration_max, int xleft, int xright, int ytop, int ybottom, float xup, float xlow, float yup, float ylow, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- float z_real, z_imag;
- int i = 0;
- for(int x = xleft; x < xright; x++) {
- for(int y = ytop; y < ybottom; y++) {
- i = 0;
- for (int dx = 0; dx < hypersampling_factor; dx++) {
- for (int dy = 0; dy < hypersampling_factor; dy++) {
- z_real = map(x + float(dx)/hypersampling_factor - float(hypersampling_factor)/2, xleft, xright, xlow, xup);
- z_imag = map(y + float(dy)/hypersampling_factor - float(hypersampling_factor)/2, ytop, ybottom, ylow, yup);
- i += iterate_switch(num, iteration_max, z_real, z_imag, c1_real, c1_imag, c2_real, c2_imag);
- }
- }
- if (i == iteration_max * sq(hypersampling_factor)) {
- set(x, y, color(255));
- } else {
- //set(x, y, color(int(map(i, 0, iteration_max * sq(hypersampling_factor), 0, 255))));
- set(x, y, color(int(map(log(float(i)/(20 * sq(hypersampling_factor))+1), 0, log(float(iteration_max)/10+1), 0, 255))));
- }
- }
- }
- }
- int iterate_switch(int num, int iteration_max, float z_real, float z_imag, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- switch (num) {
- case -1:
- // M
- return iterate(iteration_max, 0, 0, z_real, z_imag, z_real, z_imag);
- case 0:
- // M(c1)
- return iterate(iteration_max, 0, 0, z_real, z_imag, c1_real, c1_imag);
- case 1:
- // M'(c1)
- return iterate(iteration_max, 0, 0, c1_real, c1_imag, z_real, z_imag);
- case 2:
- // M(c2)
- return iterate(iteration_max, 0, 0, z_real, z_imag, c2_real, c2_imag);
- case 3:
- // M'(c2)
- return iterate(iteration_max, 0, 0, c2_real, c2_imag, z_real, z_imag);
- case 4:
- // J(c1, c2)
- return iterate(iteration_max, z_real, z_imag, c1_real, c1_imag, c2_real, c2_imag);
- case 5:
- // J(c2, c1)
- return iterate(iteration_max, z_real, z_imag, c2_real, c2_imag, c1_real, c1_imag);
- default:
- // should never happen
- return -1;
- }
- }
- int iterate(int iteration_max, float z_real, float z_imag, float c1_real, float c1_imag, float c2_real, float c2_imag) {
- int i = 0;
- float zt_real, zt_imag;
- while((i < iteration_max) && (sq(z_real)+sq(z_real) < escape)) {
- zt_real = sq(z_real) - sq(z_imag) + c1_real;
- zt_imag = 2 * z_real * z_imag + c1_imag;
- z_real = sq(zt_real) - sq(zt_imag) + c2_real;
- z_imag = 2 * zt_real * zt_imag + c2_imag;
- i++;
- }
- return i;
- }
Add Comment
Please, Sign In to add comment