-
Notifications
You must be signed in to change notification settings - Fork 1
/
Warp.pde
93 lines (77 loc) · 2.1 KB
/
Warp.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
class Warp extends Pattern {
float r;
float rofs;
float warpSpeed;
Pattern subroutine;
boolean warpHorizontal;
boolean warpVertical;
float warpFactor;
public Warp() {
this.subroutine = null;
warpHorizontal = false;
warpVertical = true;
warpSpeed = 2;
warpFactor = 1;
}
public Warp(Pattern subroutine, boolean warpHorizontal, boolean warpVertical, float warpSpeed, float warpFactor) {
this.subroutine = subroutine;
this.warpHorizontal = warpHorizontal;
this.warpVertical = warpVertical;
this.warpSpeed = warpSpeed;
this.warpFactor = warpFactor;
}
void setup(PApplet parent) {
super.setup(parent);
if (this.subroutine != null) {
this.subroutine.setup(parent);
}
}
void hshift(int y, int xofs) {
if (xofs < 0)
xofs = displayWidth + xofs;
PImage tmp = get(displayWidth-xofs, y, xofs, 1);
copy(0, y, displayWidth-xofs, 1, xofs, y, displayWidth-xofs, 1);
image(tmp, 0, y);
}
void vshift(int x, int yofs) {
if (yofs < 0)
yofs = displayHeight + yofs;
PImage tmp = get(x, displayHeight-yofs, 1, yofs);
copy(x, 0, 1, displayHeight-yofs, x, yofs, 1, displayHeight-yofs);
image(tmp, x, 0);
}
void drawBackground() {
if (subroutine != null) {
subroutine.draw();
// if (subroutine.isDone) {
// newMode();
// }
}
else {
background(0);
noFill();
ellipseMode(RADIUS);
for (int i=0; i<10; i++) {
stroke(i%2==0 ? color(255,64,64) : color(255,128,0));
ellipse(displayWidth/2,displayHeight/2,i*(displayWidth/10),i*(displayHeight/10));
}
}
}
void draw() {
drawBackground();
if (warpVertical) {
for (int x=0; x<displayWidth; x++) {
r = x*1.0/displayHeight*PI + rofs;
vshift(x, int(sin(r)*(displayHeight*warpFactor)));
}
rofs += 0.0314 * warpSpeed;
}
if (warpHorizontal) {
for (int y=0; y<displayHeight; y++) {
r = y*1.0/displayWidth*PI + rofs;
hshift(y, int(sin(r)*(displayWidth*warpFactor)));
}
rofs += 0.0314 * warpSpeed;
}
}
}