Click anywhere to redraw. Press “L” to toggle line drawing. Press “C” to cycle line color between black, white, and colored. Press “+” and “-” to change the line size.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
ArrayList<Rect> allRects; float prob = 0; float hueRange = 0.05; float satRange = 0.05; float brightRange = 0.1; float time = 0; float drawSpacing = 1.0; float axisSwitch = 0.5; boolean doesDrawLines = true; float lineSize = 0.5; int lineType = 1; static final int LineTypeWhite = 0; static final int LineTypeBlack = 1; static final int LineTypeColor = 2; void setup() { size(940, 540, P3D); colorMode(HSB, 1.0, 1.0, 1.0, 1.0); background(0.0); drawFractal(); } void draw() { translate(0.5, 0.5); time += 0.1; if (doesDrawLines) { switch (lineType) { case LineTypeWhite: stroke(1.0, 1.0); break; case LineTypeBlack: stroke(0.0, 1.0); break; case LineTypeColor: stroke(allRects.get(0).hue, allRects.get(0).sat, allRects.get(0).bright, 1.0); break; default: break; } strokeWeight(lineSize); } else { noStroke(); } for (int i=0; i<allRects.size (); i++) { Rect rect = allRects.get(i); if (rect.isAlive) { if (time > rect.drawTrigger) { rect.draw(); rect.lifeCounter += 1; if (rect.lifeCounter > 10) rect.isAlive = false; } } } } void drawRect(Rect rect) { if (rect.w > 20 && rect.h > 20) { float ratio1 = random(1); float ratio2 = 1 - ratio1; float offset = 1; if (random(1) > axisSwitch) { Rect r1 = new Rect(rect.x, rect.y, rect.w*ratio1, rect.h, rect.hue, rect.sat, rect.bright, rect.drawTrigger+drawSpacing); allRects.add(r1); if (random(1) > prob) drawRect(r1); Rect r2 = new Rect(rect.x+rect.w*ratio1, rect.y, rect.w*ratio2, rect.h, rect.hue, rect.sat, rect.bright, rect.drawTrigger+drawSpacing*1.5); allRects.add(r2); if (random(1) > prob) drawRect(r2); } else { Rect r1 = new Rect(rect.x, rect.y, rect.w, rect.h*ratio1, rect.hue, rect.sat, rect.bright, rect.drawTrigger+drawSpacing); allRects.add(r1); if (random(1) > prob) drawRect(r1); Rect r2 = new Rect(rect.x, rect.y+rect.h*ratio1, rect.w, rect.h*ratio2, rect.hue, rect.sat, rect.bright, rect.drawTrigger+drawSpacing*1.5); allRects.add(r2); if (random(1) > prob) drawRect(r2); } } } void drawFractal() { allRects = new ArrayList<Rect>(); Rect rect = new Rect(0, 0, width, height, 1.0, 1.0, 1.0, 0); rect.hue = random(1); rect.sat = random(1); rect.bright = random(0.2, 1.0); drawRect(rect); } void mousePressed() { background(0.0); axisSwitch = random(0.1, 0.9); time = 0; prob = random(0, 0.1); hueRange = random(0, 0.2); satRange = random(0, 0.2); brightRange = random(0, 0.3); drawFractal(); } void keyPressed() { if (key == 'l') { doesDrawLines = !doesDrawLines; } if (key == '=') { lineSize++; if (lineSize > 20) lineSize = 20; } if (key == '-') { lineSize--; if (lineSize < 1) lineSize = 1; } if (key == 'c') { lineType++; if (lineType> 2) lineType = 0; } } class Rect { float x; float y; float w; float h; float hue; float sat; float bright; float drawTrigger; boolean isAlive = true; int lifeCounter = 0; Rect(float _x, float _y, float _w, float _h, float _hue, float _sat, float _bright, float _drawTrigger) { x = _x; y = _y; w = _w; h = _h; float tempHue = _hue + random(-hueRange, hueRange); if (tempHue > 1.0) tempHue = 0.0; if (tempHue < 0.0) tempHue = 1.0; hue = tempHue; float tempSat = _sat + random(-satRange, satRange); sat = constrain(tempSat, 0, 1); float tempBright = _bright + random(-brightRange, brightRange); bright = constrain(tempBright, 0, 1); drawTrigger = _drawTrigger; } void draw() { fill(hue, sat, bright); rect(x, y, w, h); } } |








