-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYoulia.pde
125 lines (116 loc) · 3.48 KB
/
Youlia.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import processing.video.*;
Capture webcam;
PShader fractalShader;
boolean isCalibrating = true;
boolean isRecording = false;
PGraphics camGraphics;
ArrayList<Preset> presets;
float rotation = 0.0;
AnimationRunner animationRunner;
void setup() {
size(1200, 800, P2D);
String[] devices = Capture.list();
println(devices);
readPresets();
animationRunner = new AnimationRunner(new AnimationPlayList(presets, 600, 60));
reloadShader();
camGraphics = createGraphics(1200, 800, P2D);
webcam = new Capture(this, 1200, 800, "FaceTime HD Camera", 30);
webcam.start();
}
void readPresets(){
presets = new ArrayList<Preset>();
JSONArray json = loadJSONArray("data/presets.json");
for (int i = 0; i < json.size(); i++){
JSONObject presetJSON = json.getJSONObject(i);
JSONObject startPointJSON = presetJSON.getJSONObject("start");
JSONObject endPointJSON = presetJSON.getJSONObject("end");
PresetPoint start = new PresetPoint(startPointJSON.getFloat("c1"),
startPointJSON.getFloat("c2"),
startPointJSON.getFloat("rotation"));
PresetPoint end = new PresetPoint(endPointJSON.getFloat("c1"),
endPointJSON.getFloat("c2"),
endPointJSON.getFloat("rotation"));
presets.add(new Preset(start, end));
}
}
void draw() {
webcam.read();
camGraphics.beginDraw();
camGraphics.shader(fractalShader);
camGraphics.image(webcam, 0, 0);
camGraphics.endDraw();
textSize(20);
fill(255);
image(camGraphics, 0,0);
textAlign(RIGHT, BOTTOM);
text("@rykarn", width, height);
if (isRecording){
PVector fractalParameters = getFractalParameters();
fractalShader.set("c1", fractalParameters.x);
fractalShader.set("c2", fractalParameters.y);
fractalShader.set("rotation", rotation);
}
else {
animationRunner.animate();
PresetPoint presetPoint = animationRunner.getCurrentAnimationState();
fractalShader.set("c1", presetPoint.c1);
fractalShader.set("c2", presetPoint.c2);
fractalShader.set("rotation", presetPoint.rotation);
}
if (isCalibrating){
fractalShader.set("calibrate", 1);
}
else
{
fractalShader.set("calibrate", 0);
}
}
public PVector getFractalParameters(){
float c1 = (mouseX/float(width) -0.5f)*1f;
float c2 = (mouseY/float(height) -0.5f)*1f;
return new PVector(c1, c2);
}
PresetPoint firstPoint = null;
public void mousePressed() {
if (firstPoint == null){
PVector fractalParameters = getFractalParameters();
firstPoint = new PresetPoint(fractalParameters.x, fractalParameters.y, rotation);
}
else{
PVector fractalParameters = getFractalParameters();
PresetPoint endPoint = new PresetPoint(fractalParameters.x, fractalParameters.y, rotation);
Preset preset = new Preset(firstPoint, endPoint);
presets.add(preset);
firstPoint = null;
}
}
public void keyPressed() {
if (keyCode == UP){
rotation += 0.1;
}
else if (keyCode == DOWN){
rotation -= 0.1;
}
else if (key == 's' && isRecording){
JSONArray json = new JSONArray();
for (int i = 0; i < presets.size(); i++){
json.setJSONObject(i, presets.get(i).toJSON());
}
saveJSONArray(json, "data/presets.json");
}
else if (key == 'r'){
isRecording = !isRecording;
}
else{
isCalibrating = !isCalibrating;
}
}
public void reloadShader() {
try {
fractalShader = loadShader("traptex.glsl");
}
catch (RuntimeException e) {
e.printStackTrace();
}
}