-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlitchP5.java
98 lines (82 loc) · 1.97 KB
/
GlitchP5.java
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
//package glitchP5;
import processing.core.PApplet;
import java.util.ArrayList;
public class GlitchP5
{
PApplet parent;
GlitchFX glfx;
ArrayList<TimedGlitcher> timedGlitchers = new ArrayList<TimedGlitcher>();
public GlitchP5(PApplet parent)
{
this.parent = parent;
glfx = new GlitchFX(parent);
}
public void run()
{
glfx.open();
for (int i=timedGlitchers.size()-1; i>=0; i--)
{
TimedGlitcher tg = timedGlitchers.get(i);
tg.run();
if (tg.done())
timedGlitchers.remove(tg);
}
glfx.close();
}
public boolean done() {
return timedGlitchers.size()==0 ? true : false;
}
public void glitch(int x, int y, int spreadX, int spreadY, int diaX, int diaY, int amount, float randomness, int attack, int sustain)
{
for (int i = 0; i < amount; i++)
{
int att = (int)parent.random(attack);
timedGlitchers.add(new TimedGlitcher( (int)(x+(parent.random(-spreadX/2, spreadX/2))),
(int)(y+(parent.random(-spreadY/2, spreadY/2))),
(int)(diaX*randomness), (int)(diaY*randomness),
randomness, att, (int)parent.random(sustain))
);
}
}
private class TimedGlitcher
{
int x, y, diaX, diaY, on;
int timer, delay;
float randomness;
int sX, sY;
int onset = 0;
TimedGlitcher(int x, int y, int diaX, int diaY, float randomness, int on, int time)
{
this.x = x;
this.y = y;
this.diaX = diaX;
this.diaY = diaY;
this.randomness = randomness;
this.on = on;
this.timer = time;
sX = (int)(parent.random(-10, 10));
sY = (int)(parent.random(-10, 10));
delay = 10;
}
void run()
{
delay--;
if (delay <= 0) {
if (onset >= on)
{
glfx.glitch(x, y, diaX, diaY, sX, sY);
timer--;
}
onset++;
delay = 0;
}
}
boolean done()
{
if (timer <= 0)
return true;
else
return false;
}
}
}