-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawingBackground.pde
102 lines (86 loc) · 2.35 KB
/
DrawingBackground.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
class DrawingBackground {
PImage[] images; // array of images
PImage whole;
// star array
ArrayList<Star> stars;
// the position of each drawings
ArrayList<Integer>posX;
ArrayList<Integer>posY;
// the variable for mouse interation
int preX, preY;
float alpha=0;
int count=0;
boolean finishFlag=false;
DrawingBackground() {
// load images
images=new PImage[7];
for (int i=0; i<images.length; i++)
images[i]=loadImage("img/"+i+".png");
// load star images
stars=new ArrayList<Star>(6);
for (int i=0; i<6; i++)
stars.add(new Star(i+1));
whole=loadImage("img/complete.png");
// generate position array
posX=new ArrayList<Integer>();
posY=new ArrayList<Integer>();
}
// the user can place each drawing where they want
boolean placeDrawing(int target, boolean mouseClick) {
preX=mouseX;
preY=mouseY;
imageMode(CENTER);
image(images[target+1], mouseX, mouseY);
if (mouseClick) {
posX.add(preX);
posY.add(preY);
return true;
}
return false;
}
// drawing whole images
void drawBackground(int complete) {
// very basic background
imageMode(CORNER);
image(images[0], 0, 0);
imageMode(CENTER);
for (int i=1; i<complete+1; i++) {
image(images[i], posX.get(i-1), posY.get(i-1));
}
/////////////test code here////////////////////
//for(int i=0;i<stars.size();i++)
// stars.get(i).starDraw();
//////////////////////////////////////////
if (complete==6) { // after the user complete his/her drawing
if (!finishFlag && screenChangeEffect()) {
finishFlag=true;
}
if (finishFlag) {
bgm.play();
imageMode(CORNER);
image(whole, 0, 0);
fill(255, 150);
text("Starry Night", 100, height-30);
// draw blinking stars
for (int i=0; i<stars.size(); i++)
stars.get(i).starDraw();
}
}
}
boolean screenChangeEffect() {
count++;
if (count<150) {
alpha+=2;
} else if (count<320) {
imageMode(CORNER);
image(whole, 0, 0);
//tint(255,alpha*-1);
alpha-=2;
}
fill(255, alpha);
noStroke();
rect(0, 0, width, height);
if (count==320) return true;
return false;
}
}