-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook_Shelf.pde
55 lines (54 loc) · 1.26 KB
/
Book_Shelf.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
var book = [
{title: "The Giver",
stars: 4,
author: "Lois Lowry",
color: color(0, 150, 33),
haveRead: false
},
{title: "Harry Potter",
stars: 5,
author: "J.K.Rowling",
color: color(222, 163, 0),
haveRead: true
},
{title: "Da Vinci-koden",
stars: 3,
author:"Dan Brown",
color: color(115, 0, 191),
haveRead: true},
{title: "Narnia",
stars: 4,
author: "C.S Lewis",
color: color(38, 224, 181),
haveRead: true
},
{title: "Thokyo Ghoul",
author: "Unknown",
stars: 4,
color: color(255, 0, 128),
haveRead: true}
];
// draw shelf
fill(194, 74, 0);
rect(0, 120, width, 10);
var y = 20;
var x=0;
for(var j = 0; j < book.length; j++){
x = j;
if (j>2){
y=150;
fill(194, 74, 0);
rect(0, 250, width, 10);
x=j-3;
}
// draw one book
fill(book[j].color);
rect(10+120*x, y, 90, 100);
fill(0, 0, 0);
text(book[j].title, 15+120*x, y+9, 70, 100);
text(book[j].author, 15+120*x, y+30, 70, 100);
if(book[j].haveRead===true){
text("read", 15+120*x, y+50,70,100);}else{text("not read", 15+120*j, 70,70,100);}
for (var i = 0; i < book[j].stars; i++) {
image(getImage("cute/Star"), 13 + i * 20+x*120, y+70, 20, 30);}
}