points on the surface of cube
in
Programming Questions
•
1 year ago
I'm trying to create a cube made of points on the surface. This is my code:
-
import processing.opengl.*;
int winsize=600;int nums = 50;int[] q = new int[nums];PVector qube = new PVector();int c, s;void setup() {size(winsize, winsize, OPENGL);background(0);for (int i=0; i<nums; i++) {q[i]=(int)(Math.random() * (5 + 1));}}
void draw() {translate(200, 200);rotateX(45);rotateY(45);for (int i=0; i<nums; i++) {int side = 200;s = (int)(Math.random() * (5 + 1));println(s);c = s%3;pick(c, (s>2?1:0));pick((c+1)%3, random(0, 1));pick((c+2)%3, random(0, 1));pushMatrix();translate(qube.x*side, qube.y*side, qube.z*side);ellipse(0, 0, 3, 3);popMatrix();}}
void pick(int index, float value) {if (index==0) {qube.x = value;//println("0"+" >> x");fill(0, 0, 255);}else if (index==1) {qube.y = value;//println("1"+" >> y");fill(255, 0, 0);}else if (index==2) {qube.z = value;//println("2"+" >> z");fill(0, 255, 0);}}
I'm only getting 3 (and a half maybe) faces, maybe I'm not able to make a distributed generation with the random method? Thanks in advance.
1