3D box repeating, how do I get it to not repeat?

edited January 2016 in How To...
PImage myImage;
float x,y,z;
int rotatex, ry, rz = 0;
float newt;

void setup() {  // this is run once.   

  // set the background color
  background(255, 255, 255);

  // canvas size (Integers only, please.)
  size(800, 600, P3D); 

  // smooth edges
  smooth();

  // limit the number of frames per second
  frameRate(50);

  // set the width of the line. 
  strokeWeight(1);
  x = width/2;
  y = height/2;
  z = 0;
} 

void draw() {  // this is run repeatedly. 

translate(x, y, z);
rotateZ(rz);
rotateY(ry);
rotateX(newt);
fill(0, 0, 255);
box(50, 100, 50);
}

This code right here makes a 3D box that I can edit but it keep making the same box over and over again, how can i make one box and keep it there without it making another box? I tried putting it on setup but it didnt work.

Tagged:

Answers

  • I dont know how to post code

  • i have fixed the formatting.

    i can't see the problem with that code. i see one box which doesn't move.

  • Answer ✓

    set the background color at beginning of draw() to delete

    also angles need to be float (it's radians with rotate, not degrees)

    PImage myImage;
    float x, y, z;
    float  rotatex, ry, rz = 0;
    float newt;
    
    void setup() {  // this is run once.   
      // canvas size (Integers only, please.)
      size(800, 600, OPENGL); 
    
      // set the background color
      background(255, 255, 255);
    
      // smooth edges
      smooth();
    
      // limit the number of frames per second
      frameRate(250);
    
      // set the width of the line. 
      strokeWeight(1);
      x = width/2;
      y = height/2;
      z = 0;
    } 
    
    void draw() {  // this is run repeatedly. 
      // set the background color
      background(255, 255, 255);
    
      translate(x, y, z);
      rotateZ(rz);
      rotateY(ry);
      rotateX(newt);
      fill(0, 0, 255);
      box(50, 100, 50);
      //rz+=.022;
      ry+=.021;
    }
    
  • when you want to use an angle from 0 to 360 (in degrees) that's fine

    but then you need to say rotate(radians(angle));

    so you convert the value in degrees to a value in radians (0 to 2 times PI)

Sign In or Register to comment.