// Demo nesting for csc220 assn4 NestingCSC220Fall2023PShapeWithRotation // NestingCSC220Fall2023PShape adds rotated framed images in 3 dimensions // From Assignment 4 STUDENT B: // STUDENT B 50%: Each student creates their own shape according to handout spec. // You must use 2D shapes only, with copies rotated in X, Y, and Z directions, and // nested to the degree given by global recursionDepth+1. PImage STUDENTIMAGE = null ; PShape STUDENTSHAPE ; int imgwidth, imgheight ; float aspectRatio ; int imageSize = 400, frameSize = 410 ; void setup() { size(1100, 900, P3D); frameRate(60); STUDENTIMAGE = loadImage("HikerApr2023.jpg"); imgwidth = STUDENTIMAGE.width ; imgheight = STUDENTIMAGE.height ; aspectRatio = float(imgheight) / imgwidth ; STUDENTSHAPE = createShape(RECT, 0, 0, imageSize, aspectRatio * imageSize); STUDENTSHAPE.setTexture(STUDENTIMAGE); // OPTIONAL STUDENTIMAGE.resize(300, round(aspectRatio * 300)); // aspectRatio = 1.0 ; background(255); imageMode(CENTER); shapeMode(CENTER); } void draw() { //camera(width/2.0, height/10.0, (height/2.0) / tan(PI*30.0 / 180.0), // width/2.0, height/2.0, 0, 0, 1, 0); //camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), // width/2.0, height/2.0, 0, 0, 1, 0); camera(width/6.0, height/4.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0); //camera(width/10.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), // width/2.0, height/2.0, 0, 0, 1, 0); int recursionDepth = 2 ; ortho(); push(); translate(width/2, height/2); float scaledown = 1.0 ; // NOTE: If you plot 2 2D shapes of different colors in the same Z plane, their pixels will // munge together. The later one plotted will NOT cover the earlier ones. // Therefore, as you nest deeper to plot smaller shapes, you could plot 2 of each offset at // increased z and -z distances from the outermost one. I just stuck with the same color instead // of plotting multiple copies. However, I plotted 2 copies of the STUDENTSHAPE, for (int depth = 0 ; depth <= recursionDepth ; depth = depth + 1) { push(); scale(scaledown); fill(0); stroke(0); rectMode(CENTER); push(); translate(0, 0, depth+2); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); translate(0, 0, depth-4); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); pop(); push(); rotateY(radians(90)); // plot another rotated around Y axis translate(0, 0, depth+2); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); translate(0, 0, depth-4); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); pop(); push(); rotateX(radians(90)); // plot another rotated around X axis translate(0, 0, depth+2); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); translate(0, 0, depth-4); shape(STUDENTSHAPE, 0, 0, imageSize, aspectRatio * imageSize); pop(); scaledown *= 0.9 ; pop(); } pop(); }