Loading...
Logo
Processing Forum
I'm trying to create a cube made of points on the surface. This is my code:

Copy code

  1. 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.

Replies(2)

Hi, i think your points are ok, you just don't see all of them, because of light/camera settings.
If you pick more points(about 2000) and replace
Copy code
  1. rotateX(45);
    rotateY(45);
with
Copy code
  1.   background(0);
      rotateX((float)frameCount/20);
      rotateY((float)frameCount/20);
you should see what i mean.

Maybe it's a good idea to create the random-locations once in setup, then you could easily access them later.