Hey my friends (translate)

edited March 2016 in Questions about Code

I have the following question ! I want to make a figure out of cubes . My problem is if I use this code I just get one box. The other box is missing. What is wrong with 14589841968241913993459

Tagged:

Answers

  • edited March 2016 Answer ✓

    translate() is cumulative. your second box is at 30+45, 90+75, 0 which is out of the screen.

    size(200, 200, P3D);
    

    and you'll see it.

    to stop this, use pushMatrix(), popMatrix()

    void setup() {
      size(100, 100, P3D);
      frameRate(20);
    }
    
    void draw() {
      background(200);
    
      fill(255, 0, 0);
      pushMatrix();
      translate(30, 90, 0);
      box(20);
      popMatrix();
    
      fill(0, 0, 255); // not 300, range is 0-255
      pushMatrix();
      translate(45, 75, 0);
      box(20);
      popMatrix();
    }
    

    ALSO please don't post screenshots of code, paste it as text.

  • Make size bigger

    size(900, 800);

  • Ahh thanks a million..oke i am new here and will Do so !! :)

  • Answer ✓
    fill(255, 0, 0);
    pushMatrix();
    translate(30, 90, 0);
    box(20);
    popMatrix();
    ...
    

    and whilst copy and pasting this is ok for 2 or 3 blocks, it'll get cumbersome really quickly. so make a function that takes colour and position (possibly size) and that instead.

Sign In or Register to comment.