-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
random_house.pde
63 lines (53 loc) · 1.92 KB
/
random_house.pde
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
63
// The random() function (Random House Exercise)
// The Coding Train / Daniel Shiffman
// Processing Intro Series
void setup() {
size(640, 460);
pixelDensity(2);
frameRate(5); //sketch will refresh 5 times per second
}
void draw() {
// Sky
background(50, 50, 250);
rectMode(CORNER);
// Grass
fill(25, 200, 25);
rect(0, height / 2, width, height / 2); //Draw grass
float x = width / 2;
float y = height / 2;
float w = random(150, 400);
float r = random(0.2, 1); //scale ratio
float h = w * r;
float sw = random(2, 4); //thickness of line
strokeWeight(sw);
stroke(0);
// House
rectMode(CENTER);
fill(random(100, 255), 0, random(100, 255));
rect(x, y, w, w * r);
// Roof
float randomHeight = random(h / 2 + 50, 200);
fill(random(50, 255), random(0, 50), random(0, 50));
triangle(x - w / 2, y - (w * r) / 2, x + w / 2, y - (w * r) / 2, x, y - randomHeight);
// Windows
float windowWidth = random(10, h / 3);
float windowPosX = random(windowWidth, w / 2 - windowWidth);
strokeWeight(2);
stroke(0);
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x - windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
rect(x + windowPosX, y - (w * r) / 4, windowWidth, windowWidth);
line(x - windowPosX, y - (w * r) / 4 - windowWidth / 2, x - windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x - windowPosX - windowWidth / 2, y - (w * r) / 4, x - windowPosX + windowWidth / 2, y - (w * r) / 4);
line(x + windowPosX, y - (w * r) / 4 - windowWidth / 2, x + windowPosX, y - (w * r) / 4 + windowWidth / 2);
line(x + windowPosX - windowWidth / 2, y - (w * r) / 4, x + windowPosX + windowWidth / 2, y - (w * r) / 4);
//Door
noStroke();
fill(random(100, 255), random(100, 255), random(100, 255));
rect(x, y + h / 4, h / 4, h / 2 - sw * 2);
fill(random(0, 50), random(0, 50), random(0, 50));
circle(x - h / 24, y + h / 4, h / 12);
}
void mousePressed() {
background(0);
}