image source1; source1.open("Dune_tarot_1.jpg"); image source2; source2.open("Dune_tarot_2.jpg"); image source3; source3.open("Dune_tarot_3.jpg"); textbuffer output; output.open("output.txt"); output.clear(); image result; result.open("Dune_tarot.png"); int f1 = 87; int f2 = 50; int f3 = 5; int f4 = 7; int scale = 2; f1 *= scale; f2 *= scale; f3 *= scale; f4 *= scale; int result_width = 2*f4 + 9*f1 + 7*f3; int result_height = 4*f4 + 10*f2; result.new(result_width, result_height); color col_white = Color(230, 230, 230); for x from 0 to result_width for y from 0 to result_height result.setColor(x, y, col_white); int vert_steps = 2 * f1; int horz_steps = 4 * f2; int sample_rate = 2; int n = 24; int vs[n]; point ps1[n]; point ps2[n]; point ps3[n]; point ps4[n]; int i = 0; vs[i]=1;ps1[i]=Point( 423.25, 200.25);ps2[i]=Point( 228.50, 201.50);ps3[i]=Point( 420.50, 96.25);ps4[i]=Point( 229.50, 97.00);i++; vs[i]=3;ps1[i]=Point( 412.25, 173.00);ps2[i]=Point( 256.25, 172.00);ps3[i]=Point( 411.50, 89.00);ps4[i]=Point( 258.00, 89.00);i++; vs[i]=2;ps1[i]=Point( 314.50, 25.50);ps2[i]=Point( 401.00, 169.50);ps3[i]=Point( 229.00, 75.75);ps4[i]=Point( 313.50, 217.75);i++; vs[i]=3;ps1[i]=Point( 330.00, 301.25);ps2[i]=Point( 411.00, 435.00);ps3[i]=Point( 251.00, 345.25);ps4[i]=Point( 328.50, 478.75);i++; vs[i]=2;ps1[i]=Point( 228.25, 167.00);ps2[i]=Point( 55.25, 168.50);ps3[i]=Point( 229.00, 71.50);ps4[i]=Point( 56.50, 73.00);i++; vs[i]=3;ps1[i]=Point( 249.75, 431.00);ps2[i]=Point( 88.75, 430.50);ps3[i]=Point( 250.50, 343.25);ps4[i]=Point( 91.00, 343.75);i++; vs[i]=2;ps1[i]=Point( 405.00, 365.25);ps2[i]=Point( 582.50, 363.50);ps3[i]=Point( 407.00, 465.50);ps4[i]=Point( 586.00, 464.75);i++; vs[i]=3;ps1[i]=Point( 413.25, 616.75);ps2[i]=Point( 577.75, 616.50);ps3[i]=Point( 413.50, 710.50);ps4[i]=Point( 580.75, 711.00);i++; vs[i]=1;ps1[i]=Point( 230.00, 195.00);ps2[i]=Point( 30.50, 197.50);ps3[i]=Point( 228.00, 92.00);ps4[i]=Point( 33.50, 94.00);i++; vs[i]=3;ps1[i]=Point( 256.25, 171.25);ps2[i]=Point( 100.00, 171.50);ps3[i]=Point( 257.25, 88.50);ps4[i]=Point( 101.75, 86.75);i++; vs[i]=1;ps1[i]=Point( 322.00, 256.50);ps2[i]=Point( 519.50, 256.00);ps3[i]=Point( 322.50, 364.00);ps4[i]=Point( 521.75, 363.75);i++; vs[i]=3;ps1[i]=Point( 334.00, 217.25);ps2[i]=Point( 491.00, 216.25);ps3[i]=Point( 333.50, 303.25);ps4[i]=Point( 491.75, 302.50);i++; vs[i]=2;ps1[i]=Point( 576.50, 168.25);ps2[i]=Point( 403.25, 171.00);ps3[i]=Point( 574.00, 72.75);ps4[i]=Point( 401.25, 76.25);i++; vs[i]=3;ps1[i]=Point( 572.50, 436.25);ps2[i]=Point( 410.50, 436.25);ps3[i]=Point( 570.25, 346.75);ps4[i]=Point( 410.00, 348.00);i++; vs[i]=2;ps1[i]=Point( 313.25, 313.75);ps2[i]=Point( 138.75, 317.50);ps3[i]=Point( 313.25, 217.00);ps4[i]=Point( 139.75, 218.25);i++; vs[i]=3;ps1[i]=Point( 327.50, 567.50);ps2[i]=Point( 164.75, 570.00);ps3[i]=Point( 327.75, 478.00);ps4[i]=Point( 166.00, 478.50);i++; vs[i]=2;ps1[i]=Point( 313.25, 219.50);ps2[i]=Point( 486.75, 217.50);ps3[i]=Point( 313.75, 318.25);ps4[i]=Point( 488.75, 315.75);i++; vs[i]=3;ps1[i]=Point( 328.25, 479.25);ps2[i]=Point( 489.00, 480.25);ps3[i]=Point( 327.00, 571.00);ps4[i]=Point( 491.00, 570.50);i++; vs[i]=1;ps1[i]=Point( 423.00, 100.25);ps2[i]=Point( 617.25, 99.25);ps3[i]=Point( 423.25, 204.00);ps4[i]=Point( 620.50, 202.75);i++; vs[i]=3;ps1[i]=Point( 412.25, 92.00);ps2[i]=Point( 568.25, 90.50);ps3[i]=Point( 414.50, 176.00);ps4[i]=Point( 570.50, 173.75);i++; vs[i]=1;ps1[i]=Point( 124.50, 255.00);ps2[i]=Point( 322.00, 252.75);ps3[i]=Point( 123.00, 361.75);ps4[i]=Point( 321.75, 358.00);i++; vs[i]=3;ps1[i]=Point( 177.00, 214.50);ps2[i]=Point( 333.25, 214.75);ps3[i]=Point( 174.25, 300.25);ps4[i]=Point( 332.50, 299.25);i++; vs[i]=2;ps1[i]=Point( 53.00, 370.00);ps2[i]=Point( 229.50, 366.75);ps3[i]=Point( 52.00, 472.00);ps4[i]=Point( 229.50, 467.25);i++; vs[i]=3;ps1[i]=Point( 84.00, 617.25);ps2[i]=Point( 248.50, 616.25);ps3[i]=Point( 80.75, 713.25);ps4[i]=Point( 248.00, 712.00);i++; //ps1[i] = source3.getPoint(1); //ps2[i] = source3.getPoint(2); //ps3[i] = source3.getPoint(3); //ps4[i] = source3.getPoint(4); int x_org = f4; int y_org = f4; int line = 0; double c_r = 200; double c_g = 155; double c_b = 80; double c_bright = (c_r + c_g + c_b)/3; double c_sat = (c_r < c_bright ? c_bright - c_r : c_r - c_bright) + (c_g < c_bright ? c_bright - c_g : c_g - c_bright) + (c_b < c_bright ? c_bright - c_b : c_b - c_bright); c_r = (c_r - c_bright) * 3 / c_sat; c_g = (c_g - c_bright) * 3 / c_sat; c_b = (c_b - c_bright) * 3 / c_sat; for i from 0 to n { int v = vs[i]; point p_1 = ps1[i]; point p_2 = ps2[i]; point p_3 = ps3[i]; point p_4 = ps4[i]; point p1 = 1.5 * p_1 + -0.5 * p_3; point p3 = -0.5 * p_1 + 1.5 * p_3; point p2 = 1.5 * p_2 + -0.5 * p_4; point p4 = 1.5 * p_4 + -0.5 * p_2; point ptop = 0.5 * p1 + 0.5 * p2; point pbot = 0.5 * p3 + 0.5 * p4; if (i + 1 == n) { output.append(format("vs[i]=3;ps1[i]=Point(%7.2lf,%7.2lf);", p_1.x, p_1.y)); output.append(format("ps2[i]=Point(%7.2lf,%7.2lf);", p_2.x, p_2.y)); output.append(format("ps3[i]=Point(%7.2lf,%7.2lf);", p_3.x, p_3.y)); output.append(format("ps4[i]=Point(%7.2lf,%7.2lf);i++;\n", p_4.x, p_4.y)); } for x from 0 to vert_steps { double d_x = 1.0 / vert_steps; double ds_x = d_x / sample_rate; double dsh_x = ds_x / 2; double v_x = dsh_x + x * d_x; for y from 0 to horz_steps { if ( (y - f2) * (f1 - 0) - (x - 0) * (0 - f2) > 0 && (y - f2) * (f1 - 2*f1) - (x - 2*f1) * (0 - f2) < 0 && (y - 3*f2) * (f1 - 2*f1) - (x - 2*f1) * (4*f2 - 3*f2) > 0 && (y - 3*f2) * (f1 - 0) - (x - 0) * (4*f2 - 3*f2) < 0) { double d_y = 1.0 / horz_steps; double ds_y = d_y / sample_rate; double dsh_y = ds_y / 2; double v_y = dsh_y + y * d_y; color col; for xi from 0 to sample_rate { double f_x = v_x + xi * ds_x; double g_x = 1.0 - f_x; for yi from 0 to sample_rate { double f_y = v_y + yi * ds_y; double g_y = 1.0 - f_y; point p = g_x*(g_y*p1 + f_y*p3) + f_x*(g_y*p2 + f_y*p4); if (v == 1) col += source1.getInterpolatedColor(p); else if (v == 2) col += source2.getInterpolatedColor(p); else col += source3.getInterpolatedColor(p); } } if (v == 3) { color col1 = Color(0,0,0); col1.r = col.r; col1.g = col.g; col1.b = col.b; col = result.getColor(x_org + x, y_org + y); color col2 = Color(0,0,0); col2.r = col.r; col2.g = col.g; col2.b = col.b; col = col1 + col2; // Average brightness times 3 double bright = (col.r + col.b + col.r)/3.0; double sat = (col.r < bright ? bright - col.r : col.r - bright) + (col.g < bright ? bright - col.g : col.g - bright) + (col.b < bright ? bright - col.b : col.b - bright); sat = sat / 2; if (bright > 200) { sat += (bright - 200) / 1.5; bright = 200; } col.r = bright + sat * c_r; col.r = col.r < 0 ? 0 : col.r > 255 ? 255 : col.r; col.g = bright + sat * c_g; col.g = col.g < 0 ? 0 : col.g > 255 ? 255 : col.g; col.b = bright + sat * c_b; col.b = col.b < 0 ? 0 : col.b > 255 ? 255 : col.b; } result.setColor(x_org + x, y_org + y, col); } } } if (v == 3) { x_org += 2 * f1 + 2*f3; if (x_org + 2 * f1 > result_width) { line = 1 - line; x_org = f4 + (line == 1 ? f1 + f3 : 0); y_org += 3 * f2 + f4; } } }