Audrey Zheng – Final Project

sketch

//Audrey Zheng
//Section A
//audreyz@andrew.cmu.edu




var cubex = 10;
var cubey = 20;
var cubeWidth = 20;

var cube;
var cube2;


var cx;
var cy;

var systems;


function setup() {
    createCanvas(300, 300);
    background(220);
   


    // osc = new p5.TriOsc();
    // osc.freq(880.0);
    // osc.amp(0.1);
    // osc.start();


    cx = width/2;
    cy = width/2;

    cube1 = new cube(200,30);
    cube2 = new cube(20,20);
    cube3 = new cube(150,150);

    
    systems = [];
    

}

function draw() {
    if (millis() > 2000) {
        //osc.stop();
        //noLoop();
    }

    //rect(cubex, cubey, cubeWidth, cubeWidth);

    cube1.display();
    cube2.display();
    cube3.display();

    for (i = 0; i <systems.length; i ++) {
        systems[i].display();
    }
    
    if (systems.length==0) {
        textAlign(CENTER);
        text("Click to add cubes", width/2, height/2);
    }

}

function cube(x,y) { //the cube
    this.x = x;
    this.y = y;

    this.width = 20;


    this.NW =[this.x, this.y];    
    this.NE = [x+this.width, this.y];

    this.SE = [this.x+this.width, y+this.width];

    this.SW = [this.x, y+this.width];

    this.larger = new square(x,y,this.width, this.width);
    this.smaller = new square(x + (cx -x) * 0.25, y + (cy - y) *0.25, this.width * 0.75, this.width * 0.75);


    this.NWs =[(this.x + (cx - this.x) * 0.20), this.y + (cy - this.y) * 0.20];
     
    this.NEs = [(this.x + (cx - this.x) * 0.20) + (this.width * 0.8), this.y + (cy - this.y) * 0.20];

    this.SEs = [(this.x + (cx - this.x) * 0.20) + (this.width * 0.8), this.y + (cy - this.y) * 0.20 + (this.width * 0.8)];

    this.SWs = [(this.x + (cx - this.x) * 0.20), this.y + (cy - this.y) * 0.20 +(this.width * 0.8)];




   
    this.display = function() {
        rect(this.x, this.y, this.width, this.width);
        rect(this.x + (cx - this.x) * 0.20, this.y + (cy - this.y) * 0.20, this.width * 0.8, this.width * 0.8);
        line(this.NW[0], this.NW[1], this.NWs[0], this.NWs[1]);
        line(this.NE[0], this.NE[1], this.NEs[0], this.NEs[1]);
        line(this.SE[0], this.SE[1], this.SEs[0], this.SEs[1]);

        line(this.SW[0], this.SW[1], this.SWs[0], this.SWs[1]);



    };

}

function square(x,y,w,h) {
    this.x = x;
    this.y = y;
    this.width = w;
    this.height = h;

    this.getCorners = function() {
        var NW =[x-w/2,y-h/2];
        //print(NW);
        var NE = [x+w/2, y-h/2];
        var SE = [x+w/2, y-h/2];
        var SW = [x-w/2, y+h/2];

        return [NW,NE,SE,SW];
    };
}


function mousePressed() {
    this.p = new cube(mouseX,mouseY);
    systems.push(p);
    print(systems);
}




function fillFront() {

}

function fillBottom() {

}

function fillTop() {

}

function fillLeft() {

}

function fillRight() {

}


Leave a Reply