forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jumper_Walker_Program.pde
99 lines (85 loc) · 1.62 KB
/
Jumper_Walker_Program.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
//nopointerexception - access smth that doesnt exist
class Jumper
{
int myX, myY;
Jumper()
{
myX = 250;
myY = 250;
}
void jump(){
myX = (int)(Math.random()*500);
myY = (int)(Math.random()*500);
}
void show()
{
ellipse(myX, myY, 50, 50);
}
}
class Walker
{
int myX, myY;
Walker()
{
myX = 175;
myY = 250;
}
void walk(){
myX = myX + (int)(Math.random()*10)-4;
myY = myY + (int)(Math.random()*10)-4;
}
void show()
{
ellipse(myX, myY, 50, 50);
}
}
Jumper bob;
Walker fred;
Walker [] betterOldPplHome = new Walker [10]; //array
void setup()
{
size(500,500);
frameRate(20);
background(0);
bob = new Jumper();
fred = new Walker();
for(int i = 0; i < betterOldPplHome.length; i++){
betterOldPplHome[i] = new Walker(); //elements of array
}
}
Walker [] oldpplhome = {
new Walker(),
new Walker(),
new Walker(),
new Walker(),
new Walker(),
};
/*
Walker [] betterOldPplHome = new Walker [10]; //array
for(int i = 0; i < betterOldPplHome.length; i++)[
betterOldPplHome[i] = new Walker(); //elements of array
}
*/
void draw()
{
background(0);
//fill(150);
bob.jump();
bob.show();
for(int i = 0; i < betterOldPplHome.length; i++){
betterOldPplHome[i].walk();
betterOldPplHome[i].show();
}
fred.walk();
fred.show();
oldpplhome[0].walk();
oldpplhome[0].show();
oldpplhome[1].walk();
oldpplhome[1].show();
oldpplhome[2].walk();
oldpplhome[2].show();
oldpplhome[3].walk();
oldpplhome[3].show();
oldpplhome[4].walk();
oldpplhome[4].show();
}