forked from codenamejab/congressional
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animate.txt
179 lines (120 loc) · 4.14 KB
/
animate.txt
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function animate() {
// set the animation position (0-100)
percent += direction;
if (percent < 0) {
percent = 0;
direction = 1;
};
draw(percent);
if (percent < 100){
// request another frame
setTimeout(function () {
requestAnimationFrame(animate);
}, 1000 / fps);
}
}
// draw the current frame based on sliderValue
function draw(sliderValue) {
// redraw path
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth = 5;
ctx.strokeStyle = 'black';
drawGrid();
drawNotches();
add_hoop();
add_line();
//show start point
ctx.strokeStyle = 'rgb(0,255,0)'
ctx.fillStyle = 'blue'
ctx.beginPath();
ctx.arc(660,480,5,0,6.28);
ctx.fill();
ctx.strokeStyle= "black";
ctx.lineWidth = 2;
ctx.font = "bold 30px Arial"
ctx.fillText("Start your shot here", 540,445)
ctx.strokeText("Start your shot here", 540,445)
if(swish == 1){
ctx.fillStyle = 'rgb(0,255,255)'
ctx.font = "bold 120px Times New Roman"
ctx.fillText("Swish!", 300,250)
}
else if(swish == 2){
ctx.fillStyle = 'rgb(255,0,0)'
ctx.font = "bold 40px Times New Roman"
ctx.fillText("You stepped past the line!", 230, 350)
}
else if(swish == 3){
ctx.fillStyle = 'rgb(0,255,255)'
ctx.font = "bold 120px Times New Roman"
ctx.fillText("Swiiiish!", 230,250)
}
else if(swish == 4){
ctx.fillStyle = 'rgb(255,0,0)'
ctx.font = "bold 40px Times New Roman"
ctx.fillText("You missed!", 350, 350)
}
graphCurve(inputSign,inputA,inputB,inputC);
if(percent == 100 || percent == 0){
swish = 0
}
// draw the tracking rectangle
var xy;
// this has to be 25
var percent = (sliderValue) / 25
xy = getQuadraticBezierXYatPercent({
x: point1X,
y: point1Y
}, {
x: parabOriginX,
y: IntersectY
}, {
x: point2X,
y: point2Y
}, percent/4);
//this is to see where ball lands and not have it go on past hoop
//if((xy.x<= 165 - ball.width * .6 / 2 ) && (xy.x >= 60 - ball.width * .6 / 2) && (xy.y >=60 - ball.height * .6 / 2) && (xy.y <= 150 - ball.height * .6 / 2)){
//drawRect(xy, "red")
// alert("yu in")
drawRect(xy, "red");
//check if they made it or not; swish
if(point1X >= 600 && point1X <= 720 && xy.x <= 197 && xy.x >= 187 && xy.y >= 30 && xy.y <= 150 ){
console.log("Swish")
swish = 1;
}
else if(point1X <= 600 || point1X >= 720){
swish = 2;
console.log("travelled while shooting")
}
else if(slope >= 15 && xy.x <= 180 && xy.x >= 60){
swish = 3;
console.log("Swiiiiish")
}
else if(slope <15 && xy.x <= 197 && xy.x >= 187 && (xy.y <= 30 || xy.y >= 150)){
swish = 4
console.log("BRICK")
}
}
// draw tracking rect at xy
function drawRect(point, color) {
ctx.fillStyle = "cyan";
ctx.strokeStyle = "gray";
ctx.lineWidth = 3;
ctx.save();
ctx.beginPath();
ctx.arc(point.x, point.y, 55, 0, 6.28, false); //draw the circle
ctx.clip(); //call the clip method so the next render is clipped in last path
ctx.closePath();
ctx.drawImage(ball, point.x - ball.width * .6 / 2, point.y - ball.height * .6 / 2, ball.width * 0.6, ball.height * 0.6);
ctx.restore();
//ctx.rect(point.x - 13, point.y - 8, 25, 15);
}
// quadratic bezier: percent is 0-1
function getQuadraticBezierXYatPercent(startPt, controlPt, endPt, percent) {
var x = Math.pow(1 - percent, 2) * startPt.x + 2 * (1 - percent) * percent * controlPt.x + Math.pow(percent, 2) * endPt.x;
var y = Math.pow(1 - percent, 2) * startPt.y + 2 * (1 - percent) * percent * controlPt.y + Math.pow(percent, 2) * endPt.y;
return ({
x: x,
y: y
});
}