Alexandra Kaplan -Project 3

/* Alexandra Kaplan
Section C
aekaplan@andrew.cmu.edu
Project 03 */


var bigCircleR = 150; //gold part of pocket watch radius
var smallCircleR = 140; // face part of pocket watch radius
var centerCircleR = 7; //center of hands radius
var topEllipseW = 20; //width of top ellipse
var topEllipseH = 15; //height of top ellipse
var minuteHand = smallCircleR / 4; // starting location of minute hand


function setup(){
	createCanvas(640, 480);
}

function draw(){
	background(30, 20, 80);
	
	//text
    var boundedTextSize = min(mouseX / 5, width);
    fill(mouseX / 3, mouseX / 2, mouseX + 150);
    textSize(boundedTextSize);
    textAlign(CENTER);
    text('you are getting sleepy', width / 2, height / 2 + 100);


	var circleX = 0; //x starting position of pocket watch
    var circleY = height / 1.3; // y starting position of pocket watch
    var swing = mouseX; // when mouse x is positive, swings left, when mouseX is negative, swings right

    if (mouseX > 90){
        swing = -swing - 180; //watch changes direction so it doesn't go off the canvas
    }
    if (mouseX > 270){
        swing = mouseX + 360; //watch changes direction so it doesn't go off the canvas
    }
    if (mouseX > 450){
        swing = -mouseX - 540; //watch changes direction so it doesn't go off the canvas
    }
    if (mouseX > 630){
        swing = mouseX + 720; //watch changes direction so it doesn't go off the canvas
    }
    
    print(mouseX); //to help me debug
    
	push();

    translate(width / 2, 0); //translates origin to center of width

	rotate(radians(-swing)); //rotates everything around translated origin (0,0)

	strokeWeight(5);
    stroke(200, 150, 30);
	line(0, 0, circleX, circleY);//line connecting watch to origin

	strokeWeight(0);

	fill(200, 150, 30);
	ellipse(circleX, circleY, bigCircleR, bigCircleR); //draws outside of watch
    
  
	fill(200, 150, 30);
	ellipse(circleX , circleY - bigCircleR / 2, topEllipseW, topEllipseH);//draws top nubbin of watch
	
	
	fill(255);
	ellipse(circleX, circleY, smallCircleR, smallCircleR); //draws face of watch
	
	fill(0);
	ellipse(circleX, circleY, centerCircleR, centerCircleR); // draws center of watch

    strokeWeight(4);
    stroke(0);
	line(circleX, circleY, 30, circleY - 30); //hour hand

	push();
	translate(circleX, circleY); //translates origin to center of watch
	line(0, 0, minuteHand, minuteHand); //draws minute hand
	pop();

  
    pop();


}






This project has definitely been the most challenging for me so far. I enjoyed the premise of it, things just got really difficult when I ran into the problem of how to make the pendulum stop spinning and change directions to swing the other way. Thank you so much to the TA’s who helped me on how I could think through the problem!

Leave a Reply