forked from UCMHSProgramming2015/FunctionsChallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
64 lines (59 loc) · 1.08 KB
/
Copy pathCode
File metadata and controls
64 lines (59 loc) · 1.08 KB
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
int diam;
PVector loc;
PVector vel;
void setup()
{
size(400,400);
diam = 15;
loc = new PVector (mouseX, mouseY);
vel = new PVector (5,5);
}
void draw()
{
println(whenXDoesYouWrong(1,9,-10));
println(springInMyStep(807.7,0.13,'w'));
println(springInMyStep(8.32,600,'x'));
println(springInMyStep(10,3.56,'k'));
followMrMouse();
}
float[] whenXDoesYouWrong(float a, float b, float c)
{
float[]x = new float[2];
x[0] = -b + (sqrt(sq(b) - 4*a*c))/2*a;
x[1] = -b - (sqrt(sq(b) - 4*a*c))/2*a;
return x;
}
float springInMyStep (float a, float b, char isolate)
{
float result = 0;
if(isolate == 'w')
{
result = 0.5*a*sq(b);
}
if(isolate == 'x')
{
result = sqrt((2*b)/a);
}
if(isolate == 'k')
{
result = (2*b)/sq(a);
}
return result;
}
void followMrMouse()
{
ellipse(loc.x,loc.y, diam, diam);
loc.add(vel);
if (loc.x > mouseX+20)
{
vel.x = -abs(vel.x);
} else if (loc.x < mouseX-20) {
vel.x = abs(vel.x);
}
if (loc.y > mouseY+20)
{
vel.y = -abs(vel.y);
} else if (loc.y < mouseY-20) {
vel.y = abs(vel.y);
}
}