-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlitchFX.java
106 lines (93 loc) · 2.47 KB
/
GlitchFX.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
99
100
101
102
103
104
105
106
//package glitchP5;
import processing.core.PApplet;
public class GlitchFX
{
PApplet parent;
int[] area = new int[0];
int[] area_ = new int[0];
int lastxPos;
int lastyPos;
int lastw;
int lasth;
int lastsX;
int lastsY;
int[]lastPixels;
GlitchFX(PApplet p)
{
this.parent = p;
lastPixels = new int[parent.width*parent.height];
}
void open()
{
parent.loadPixels();
}
void close()
{
parent.updatePixels();
PApplet.arrayCopy(parent.pixels, lastPixels);
}
void glitch(int xPos, int yPos, int w, int h, int sX, int sY)
{
computeArea(xPos, yPos, w, h, sX, sY);
int shiftr = 6;
if (area.length<area_.length)
{
for (int j = 0; j < area.length; j++)
{
parent.pixels[area[j]] = lastPixels[area_[j]] ;
// parent.pixels[area[j]] += parent.pixels[area_[j]] << shiftr;
}
} else
{
for (int j = 0; j < area_.length; j++)
{
parent.pixels[area[j]] += lastPixels[area_[j]] << shiftr;
// parent.pixels[area[j]] += parent.pixels[area_[j]] << shiftr;
}
}
}
void computeArea(int xPos, int yPos, int w, int h, int sX, int sY)
{
if (xPos != lastxPos || yPos != lastyPos || w != lastw || h != lasth || sX != lastsX || sY != lastsY)
{
int startX = PApplet.constrain(xPos-w/2, 0, parent.width-1);
int startY = PApplet.constrain(yPos-h/2, 0, parent.height-1);
int endX = PApplet.constrain(xPos+w/2, 0, parent.width-1);
int endY = PApplet.constrain(yPos+h/2, 0, parent.height-1);
int startX_ = PApplet.constrain(xPos-w/2+sX, 0, parent.width-1);
int startY_ = PApplet.constrain(yPos-h/2+sY, 0, parent.height-1);
int endX_ = PApplet.constrain(xPos+w/2+sX, 0, parent.width-1);
int endY_ = PApplet.constrain(yPos+h/2+sY, 0, parent.height-1);
w = Math.abs(startX-endX);
h = Math.abs(startY-endY);
area = new int[w*h];
int i=0;
for (int y=startY; y<endY; y++)
{
for (int x=startX; x<endX; x++)
{
area[i]=parent.width*y+x;
i++;
}
}
w = Math.abs(startX_-endX_);
h = Math.abs(startY_-endY_);
area_ = new int[w*h];
i=0;
for (int y=startY_; y<endY_; y++)
{
for (int x=startX_; x<endX_; x++)
{
area_[i]=parent.width*y+x;
i++;
}
}
}
lastxPos = xPos;
lastyPos = yPos;
lastw = w ;
lasth = h ;
lastsX = sX;
lastsY = sY ;
}
}