// CSC220F19Demo3DSphereBox, D. Parson, 9/24-26/2019 // This sketch shows how to elongate spheres using scale(...), and // to position 3D boxes and spheres using translate(). void setup() { size(800, 500, P3D); frameRate(60); // Must be explicit in newer Macs after setting size. stroke(0); fill(0, 255, 255); background(255); } void draw() { pushMatrix(); // at top of display() rotateY(radians(22.5)); // so we can see edges of boxes // For each body part, do a pushMatrix(), translate for its center, scale if you want to elongate a sphere, add spheres // and boxes, add some 2D parts (optional), then popMatrix() for each body part. // Put a sphere in center of screen. Note - only radius parameter, use scale(X,Y,Z) to elongate a sphere. pushMatrix(); stroke(0); fill(0, 255, 255); // cyan translate(width/2, height/2, 0); sphere(75); popMatrix(); // Put a box in center of screen. Box allows arguments for width, height, & depth.. pushMatrix(); stroke(100); fill(255, 255, 0); // yellow translate(width/2, height/2, 0); box(150, 75, 150); // width, height, depth popMatrix(); // Put a sphere elongated in X direction. pushMatrix(); stroke(0); fill(0, 255, 255); // cyan translate(width/4, height/4, 0); scale(2, 1, 1); // this elongates in X sphere(75); popMatrix(); // Put a sphere elongated in Y direction. pushMatrix(); stroke(0); fill(255, 0, 255); // magenta translate(3*width/4, height/4, 0); scale(1, 2, 1); // this elongates in Y sphere(75); popMatrix(); // Put a sphere elongated in Z direction. pushMatrix(); stroke(0); fill(128); // gray translate(width/4, 3*height/4, 0); scale(1, 1, 3); // this elongates in Z sphere(75); popMatrix(); popMatrix(); // at bottom of display }