import processing.opengl.*; /** lots of dots 2 by Christian Vengels * effect that WAS EXPECTED to happen ;) * if you click a mouse button you can zoom into the cube */ // import processing.opengl.*; int dimension=30; int offset=10; float distance=-200, targetDistance; float easing=0.05; int[][] vals; int[] rads; int maxitems; void setup() { int md = dimension * offset; size (400, 400, OPENGL); colorMode(RGB, md); maxitems = int(random(30)); vals = new int[maxitems][3]; rads = new int[maxitems]; for (int i = 0; i < maxitems; i++) { int x = int(random(0, md)); int y = int(random(0, md)); int z = int(random(0, md)); vals[i][0] = x; vals[i][1] = y; vals[i][2] = z; rads[i] = int(random(0, offset)); } } void draw() { background(0); strokeWeight(1); translate(width/2, height/2, distance); // rotateX(millis()*0.0004); rotateY(millis()*0.0007); ease(); translate(-dimension/2*offset, -dimension/2*offset, -dimension/2*offset); drawColorCube(); drawPoints(); } void ease() { if (mousePressed == true) { targetDistance=200; } else { targetDistance=-200; } float diffDistance = targetDistance - distance; if(abs(diffDistance) > 1) { distance += diffDistance * easing; } } void strokeAndVert(int x, int y, int z) { stroke(x, y, z); vertex(x, y, z); } void drawColorCube() { noFill(); int md = dimension * offset; beginShape(QUAD_STRIP); strokeAndVert(0, md, 0); strokeAndVert(0, 0, 0); strokeAndVert(md, md, 0); strokeAndVert(md, 0, 0); strokeAndVert(md, md, md); strokeAndVert(md, 0, md); strokeAndVert(0, md, md); strokeAndVert(0, 0, md); strokeAndVert(0, md, 0); strokeAndVert(0, 0, 0); endShape(); } void drawPoints() { for (int i = 0; i < maxitems; i++) { int x = vals[i][0]; int y = vals[i][1]; int z = vals[i][2]; stroke(x, y, z); noFill(); pushMatrix(); translate(x, y, z); sphere(rads[i]); popMatrix(); } }