/
sketch.js
62 lines (45 loc) · 1.4 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Sean King
Final Project, I created a code in which a moon
decends into the night and becomes a sun that also
decends into the day.
Completed 10/5/2018
https://tocodeortogetacookie.wordpress.com/2018/10/05/final-project-i-made-it/
*/
function setup() {
createCanvas(600, 400);
//setting variables for stars location
for (var i = 0; i < 300; i++) {
var x = random(width);
var y = random(height);
var r = random(1, 1);
star[i] = new Star(x, y, r);
}
}
function draw() {
if (moon.x < width && moon.y < height) { //setting condition for moon and it's background
background(0,0,70+moon.y*.5);
for (var i = 0; i < star.length; i++) {
star[i].move();
star[i].show();
}
} else { //setting condition for sun's background
background(245-sun.y*.50,245-sun.y*.50,245-sun.y*.15);
tree(400,200,150); //declaration of the tree as a function
}
noStroke(); //structure of the sun
fill(sun.r, sun.g, sun.b);
ellipse(sun.x, sun.y, sun.diam, sun.diam);
sun.x = sun.x + .6;
sun.y = sun.y + .4;
noStroke(); //structure of the moon
fill(300);
ellipse(moon.x, moon.y, moon.diam, moon.diam);
moon.x = moon.x + .6;
moon.y = moon.y + .4;
if (moon.x > width && moon.y < height) { //condition that makes loop so moon switches to sun after it ends the canvass
sun.x = 20;
sun.y = 10;
}
house(20, 30, 200); //declaration of the house as a function
}