Project 3: Dynamic Drawing

For this project I wanted to mess around with 3D geometries. I used the mouse position to change the size, and color of various objects as well as the color and the position of a point light source.

sketch 3

//Tim Nelson-Pyne
//Section C

var diameterA = 5;
var diameterB = 0;

function setup() {
    createCanvas(450, 600, WEBGL);
}

function draw() {
    noStroke();

    //sets the background color and changes it based on mouse position
    background((mouseY/width)*255, 0, 255-(mouseX/width)*255);

    //sets the material for all 3d objects and allows the color to be changed based on mouse position
    specularMaterial(255-(mouseX/width)*255, (mouseY/width)*255, (mouseX/width)*255); 
    ambientLight(255);
    //creates a point light and moves it and changes its color based on mouse position
    pointLight((mouseY/width)*255, 0, 255-(mouseX/width)*255, mouseX, mouseY, mouseY);
    shininess(0);



    //changes the size of the spheres based on mouseX position
    diameterA = 100 * sin(PI *mouseX/450);

    //changes the size of the boxes based on mouseX position
    //also changes the diameter of the torus
    diameterB = 100 * cos(PI *mouseY/600);



    

    



    
    //draws top right sphere and box
    push();
    translate(width/4, height/4);
    sphere(diameterA);
    box(diameterB);
    pop();


    //draws bottom right sphere and box
    push();
    translate(width/4, -height/4);
    sphere(diameterA);
    box(diameterB);
    pop();

    //draws top left sphere and box
    push();
    translate(-width/4, height/4);
    sphere(diameterA);
    box(diameterB);
    pop();

    //draws bottom left sphere and box
    push();
    translate(-width/4, -height/4);
    sphere(diameterA);
    box(diameterB);    
    pop();

    //draws middle sphere and torus
    sphere(diameterA);
    specularMaterial(0,0,(mouseX/width)*255);
    torus(2*diameterB, mouseY/4);


    






    
    

}


function mousePressed() {
    

}

Leave a Reply