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
|
import processing.opengl.*;
import javax.media.opengl.*;
PGraphicsOpenGL pgl;
GL gl;
ArrayList balls; int yPos; int xPos;
int vec;
void setup() {
size(400,400,OPENGL);
background(0);
yPos = height;
xPos = width;
vec = 1;
balls = new ArrayList();
}
void draw() {
background(0); lights(); noStroke();
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);
pgl.endGL();
if(frameCount % 5 == 0)
balls.add(new Ball());
for (int i=0; i<balls.size(); i++) {
Ball ba = (Ball)balls.get(i);
if (ba.y < yPos+50) {
pushMatrix();
translate(ba.x, ba.y, ba.z);
fill(ba.c);
sphere(20);
popMatrix();
}
}
yPos -= 10;
xPos += vec;
if (xPos >= width+25 || xPos <= width-25) vec *= -1;
camera(xPos-width/2.0, yPos-height/2, (height/2.0) / tan(PI*60.0 / 360.0), xPos-width/2.0, yPos-height/2, 0, 0, 1, 0);
}
class Ball {
float x;
float y;
float z;
color c;
Ball() {
x = random(width);
y = random(yPos-height*2, yPos-height*3);
z = random(-300,300);
c = color((int)random(255), (int)random(255), (int)random(255), (int)random(100,200));
}
}
|