-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathWarp.pde
90 lines (74 loc) · 1.85 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
class Warp extends Routine {
float r;
float rofs;
float warpSpeed;
Routine subroutine;
boolean warpHorizontal;
boolean warpVertical;
float warpFactor;
public Warp() {
this.subroutine = null;
warpHorizontal = false;
warpVertical = true;
warpSpeed = 1;
warpFactor = 1;
}
public Warp(Routine 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 = width + xofs;
PImage tmp = get(width-xofs,y,xofs,1);
copy(0,y,width-xofs,1, xofs,y,width-xofs,1);
image(tmp,0,y);
}
void vshift(int x, int yofs) {
if (yofs < 0)
yofs = height + yofs;
PImage tmp = get(x,height-yofs,1,yofs);
copy(x,0,1,height-yofs, x,yofs,1,height-yofs);
image(tmp,x,0);
}
void drawBackground() {
if (subroutine != null) {
subroutine.draw();
if (subroutine.isDone) {
newMode();
}
}
else {
background(0);
fill(255);
ellipseMode(CORNER);
ellipse(0,0,width-1,height-1);
}
}
void draw() {
drawBackground();
if (warpVertical) {
for (int x=0; x<width; x++) {
r = x*1.0/height*PI + rofs;
vshift(x,int(sin(r)*(height*warpFactor)));
}
rofs += 0.0314 * warpSpeed;
}
if (warpHorizontal) {
for (int y=0; y<height; y++) {
r = y*1.0/width*PI + rofs;
hshift(y,int(sin(r)*(width*warpFactor)));
}
rofs += 0.0314 * warpSpeed;
}
}
}