another Look at some Objects, Functions, and now – rotation.

var moon = {
x: 500,
y: 650,
display: function() {
stroke(0);
strokeWeight(13);
ellipse(this.x, this.y, 300, 300);
},
move: function(){
this.x = this.x + random(-.2, .2);
this.y = this.y + random(-.2, .2);
}
}

function setup() {
createCanvas(1000, 600);
}

function draw() {
background(255, 174, 185);
text(mouseX, 10, 20);
text(mouseY, 20, 30);
stroke(255, 204, 0);
strokeWeight(5);
fill(238, 229, 222);
quad(-5, 945, 490, 255, 510, 255, 1005, 945); //road

stroke(255, 204, 0);
strokeWeight(7);
drawMoon(500, 110, 300, 0, 0, 255); //centermoon

moon.move();
moon.display();

push(); //centerstar
translate(500, 110);
rotate(frameCount / 90.0); //frame
star(0, 0, 80, 100, 40);
pop();
stroke(255, 204, 0);
strokeWeight(7);

drawMoon(100, 110, 300, 255, 0, 0);

push(); //leftstar
translate(100, 110);
rotate(frameCount / 90.0);
star(0, 0, 80, 100, 40);
pop();

drawMoon(900, 110, 300);

push(); //rightstar
translate(900, 110);
rotate(frameCount / 90.0);
star(0, 0, 80, 100, 40);
pop();

drawMoon(300, 90, 100);
drawMoon(700, 90, 100);
drawMoon(100, 110, 100);
drawMoon(900, 110, 100);

drawLamp(50, 400, 255);
drawLamp(200, 400, 0);
drawLamp(700, 400, 0);
drawLamp(850, 400, 255); //bottom 4
drawLamp(50, 250, 0);
drawLamp(200, 250, 255);
drawLamp(700, 250, 255);
drawLamp(850, 250, 0); //middle 4
drawLamp(50, 100, 255);
drawLamp(200, 100, 0);
drawLamp(700, 100, 0);
drawLamp(850, 100, 255); //top 4

}

function drawMoon(x, y, diameter, r, g, b) {
fill(r, g, b);
ellipse(x, y, diameter, diameter); //moon
}
function drawLamp(x, y, clr) {
fill(clr);
rect(x + 40, y + 50, 20, 400); //tube
rect(x, y, 100, 100); //shade
rect(x + 25, 550, 50, 50); //base
}

function star(x, y, radius1, radius2, npoints) {
var angle = TWO_PI / npoints;
var halfAngle = angle / 2.0;
beginShape();
for (var a = 0; a < TWO_PI; a += angle) {
var sx = x + cos(a) * radius2;
var sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s