Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- color[] carnival = {#824C96,#433466,#FFAF4F,#ED733F,#FFFFFF};
- color[] wine = {#35013F,#561050,#951556,#E9B5D2, #FFFFFF};
- color[] forestdew= {#7dd0ae,#66bf9b,#53a584,#479071, #387e62};
- color[] random1 = {#ca054d,#3b1c32,#a4d4b4,#ffcf9c, #387e62};
- color[] test = {#f94e01,#2873bd,#bc99fe,#f7db6f, #b96d40};
- color[] lpalette = random1;
- color[] rpalette = forestdew;
- float side, theta, t0, limit;
- PVector a;
- PShape s0;
- Square[] squares, arr2;
- int count,ps;
- float attr;
- String [] mode = {"lr","lr","ll","ll"};
- //String [] mode = {"ll","ll","ll","ll"};
- //String [] mode = {"lr","ll","lr","ll"};
- //String [] mode = {"lr","ll","lr","ll"};
- //String [] mode = {"ll","lr","lr","ll"};
- void setup()
- {
- size(1600, 1000);
- background(0);
- smooth();
- noStroke();
- frameRate(999);
- side = 200;
- limit = 2;
- theta = radians (30f);
- t0 = radians(180f);
- attr = 1.15;
- ps=2;
- squares = new Square[200000];
- count=0;
- color initcol = lpalette[0];
- a = new PVector(800,900);
- fill(initcol);
- s0=createShape(RECT, 0, 0, side, side);
- s0.rotate(t0);
- squares[0] = new Square(s0,a,1);
- iterate(a, side, t0, 1, true, true, initcol);
- arr2 = Arrays.copyOf(squares, count-2);
- Arrays.sort(arr2);
- render();
- }
- void draw()
- {
- int i = min(count-2, 25000) - frameCount;
- //if (i>=0) {arr2[i].draw();}
- //render();
- noLoop();
- }
- void keyPressed() {
- if (key==' ') {save("cabbage"+"-"+hour()+"-"+minute()+"-"+second()+".png");}
- }
- void iterate(PVector v, float m, float t, int gen, boolean lef, boolean larg, color cc) {
- PVector v1, v2;
- PShape s1, s2;
- float l1, l2, l, r, ngl, ngr;
- boolean rle, rla, lle, lla;
- color cl, cr;
- int cas = (int(larg) + (int(lef)+1)*2 -2);
- String opt = mode[cas];
- // Big square side
- l1 = m * cos(theta);
- // Small square side
- l2 = m * sin(theta);
- // Si je suis en mode Large Left ...
- if (opt=="ll") {
- // If it's a left square, we span a large left and a small right (auto-clone)
- l = l1;
- r = l2;
- ngl = t+theta;
- ngr = t-(PI/2-theta);
- if (!lef) {
- cl = color (red(lpalette[gen%5])/pow(attr,gen-ps), green(lpalette[gen%5])/pow(attr,gen-ps), blue(lpalette[gen%5])/pow(attr,gen-ps));
- cr = color (red(cc)/attr, green(cc)/attr, blue(cc)/attr);
- } else {
- cl = color (red(cc)/attr, green(cc)/attr, blue(cc)/attr);
- cr = color (red(rpalette[gen%5])/pow(attr,gen-ps), green(rpalette[gen%5])/pow(attr,gen-ps), blue(rpalette[gen%5])/pow(attr,gen-ps));
- }
- }
- //Si je suis en mode Large Right
- else {
- // If it's a right square, we span a small left and a large right (counter-phase)
- // We also switch to a new color for left line
- l = l2;
- r = l1;
- ngl = t+(PI/2-theta);
- ngr = t-theta;
- if (!lef) {
- cl = color (red(lpalette[gen%5])/pow(attr,gen-ps), green(lpalette[gen%5])/pow(attr,gen-ps), blue(lpalette[gen%5])/pow(attr,gen-ps));
- cr = color (red(cc)/attr, green(cc)/attr, blue(cc)/attr);
- } else {
- cl = color (red(cc)/attr, green(cc)/attr, blue(cc)/attr);
- cr = color (red(rpalette[gen%5])/pow(attr,gen-ps), green(rpalette[gen%5])/pow(attr,gen-ps), blue(rpalette[gen%5])/pow(attr,gen-ps));
- }
- }
- // Update vectors
- v1 = new PVector (m*cos(t+PI/2),m*sin(t+PI/2));
- v1.add(v);
- v2 = new PVector (l*cos(ngr+PI/2), l*sin(ngr+PI/2));
- v2.add(v1);
- // Create Squares
- s1=createShape();
- s1.beginShape();
- s1.fill(cl);
- s1.vertex(0,0);
- s1.vertex(0,l);
- s1.vertex(l,l);
- s1.vertex(l,0);
- s1.endShape();
- s2=createShape();
- s2.beginShape();
- s2.fill(cr);
- s2.vertex(0,0);
- s2.vertex(0,r);
- s2.vertex(r,r);
- s2.vertex(r,0);
- s2.endShape();
- // rotate squares
- s1.rotate(ngl);
- s2.rotate(ngr);
- // Push into squares array
- squares[count+1] = new Square(s1, v1, gen);
- squares[count+2] = new Square(s2, v2, gen);
- count+=2;
- // Iterate
- if (m>limit) {
- // Iterate s1
- //iterate(v1, l, ngl, gen+1, ((opt.substring(1,2)=="l")), ((opt.substring(0,1)=="l")), cl);
- iterate(v1, l, ngl, gen+1, true, ((opt.substring(0,1)=="l")), cl);
- // Iterate s2
- //iterate(v2, r, ngr, gen+1, ((opt.substring(1,2)=="l")), ((opt.substring(0,1)=="l")), cr);
- iterate(v2, r, ngr, gen+1, false, ((opt.substring(0,1)=="l")), cr);
- }
- }
- void render() {
- // Render backwards for better visual effect: That was the main quest!
- for (int i=count-3; i>=0; i--) {
- arr2[i].draw();
- }
- }
- class Square implements Comparable {
- PVector pos;
- PShape s;
- int n;
- Square (PShape sh, PVector v, int depth) {
- pos = v;
- s = sh;
- n = depth;
- }
- int compareTo(Object o)
- {
- Square other=(Square)o;
- if (other.n > n) return -1;
- if (other.n == n) return 0;
- return 1;
- }
- void draw() {
- shape(s, pos.x, pos.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment