forked from paulobarcelos/ColorsOfMovement_Processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorsOfMovement.pde
68 lines (58 loc) · 1.65 KB
/
ColorsOfMovement.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
/*
* ColorsOfMovement
*
* Created by Paulo Barcelos on 09/22/2011.
* Copyright 2011 Paulo Barcelos. All rights reserved.
*
*/
class ColorsOfMovement
{
private int numStoredFrames;
private int w, h;
Vector<PImage> imgs;
private boolean ready;
ColorsOfMovement (){
imgs = new Vector<PImage>();
ready = false;
}
void setup (int w, int h, int numStoredFrames){
this.numStoredFrames = numStoredFrames;
imgs.clear();
ready = false;
}
void update (PImage img){
imgs.add(img);
if(imgs.size() > numStoredFrames){
imgs.remove(0);
ready = true;
}
else ready = false;
}
void draw(float x, float y, float w, float h, boolean flipHorizontal){
w = w*2;
h = h*2;
if(ready){
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
gl.glPushMatrix();
gl.glEnable(GL.GL_BLEND);
gl.glTranslatef(x, y, 0);
if(flipHorizontal)gl.glTranslatef(w/2,0,0);
if(flipHorizontal)gl.glScalef(-1.f, 1.f, 1.f);
gl.glBlendFunc(GL.GL_CONSTANT_COLOR, GL.GL_ONE);
gl.glBlendColor(255,0,0,255);
image(imgs.firstElement(),0 ,0, w, h);
gl.glBlendColor(0,255,0,255);
image(imgs.elementAt(numStoredFrames / 2),0 ,0, w, h);
gl.glBlendColor(0,0,255,255);
image(imgs.elementAt(numStoredFrames-5),0 ,0, w, h); // Accessing the 4 last elements is giving a memory leak! WTF!
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GL.GL_BLEND);
gl.glPopMatrix();
pgl.endGL();
}
}
boolean isReady(){
return ready;
}
}