Click anywhere to regenerate. Press “C” to change colors and keep shapes. Press “S” to change the shape and keep the colors. Press “P” to toggle camera from perspective to orthographic. Press “B” to change background color. Press “L” to change line color. Press “X” to change both the background and the line color.
|
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 |
Pylon allPylons[]; int numPylons = 10; boolean cameraOrtho = true; boolean whiteLines = true; boolean lightBackground = true; void setup() { size(940, 540, P3D); colorMode(HSB); allPylons = new PVector[numPylons]; createPylons(); } void draw() { if (lightBackground) background(220); else background(50); if (cameraOrtho) ortho(-width, width, -height, height, -10000, 10000); else perspective(); float camX = map(mouseX, 0, width, 1000, -1000); float camY = map(mouseY, 0, height, 1000, -1000); camera(camX, camY, 1000, 0, 0, 0, 0.0, 1.0, 0.0); for (int i=0; i<numPylons; i++) { Pylon pylon = allPylons[i]; pylon.draw(); } } void createPylons() { for (int i=0; i<numPylons; i++) { Pylon pylon = new Pylon(); allPylons[i] = pylon; } } void mousePressed() { createPylons(); } void keyPressed() { if (key == 'p') cameraOrtho = !cameraOrtho; if (key == 'l') whiteLines = !whiteLines; if (key == 'b') lightBackground = !lightBackground; if (key == 'c') { for (int i=0; i<numPylons; i++) { allPylons[i].randomizeColor(); } } if (key == 's') { for (int i=0; i<numPylons; i++) { allPylons[i].randomizeSize(); } } if (key == 'x') { lightBackground = !lightBackground; whiteLines = !whiteLines; } } class Pylon { float w, h, d; float x, y, z; float hue, sat, bright; float size = 0.0; float targetSize = 1.0; float scaleSpeed = 0.05; float maxSize = 700; Pylon() { x = random(-50, 50); y = random(-50, 50); z = random(-50, 50); randomizeSize(); randomizeColor(); scaleSpeed = (w/maxSize) * 0.1 + 0.1; } void draw() { pushMatrix(); size += (targetSize - size) * scaleSpeed; if (whiteLines) stroke(255); else stroke(0); fill(hue, sat, bright); box(w*size, h, d); popMatrix(); } void randomizeColor() { hue = random(0, 255); sat = random(0, 255); bright = random(0, 255); } void randomizeSize() { w = random(10, maxSize); h = random(10, maxSize); d = random(10, maxSize); size = 0; } } |





