-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagic_time_machine.ga
More file actions
166 lines (128 loc) · 4.08 KB
/
magic_time_machine.ga
File metadata and controls
166 lines (128 loc) · 4.08 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
"Magic Time Machine aka Neo-Suprematist Machine"
Alexis Leandro Estrella / Ji Yeon Kim / Laura Martorana
[Interactive and Electronic Media / Mª José Martínez de Pisón Ramón / http://mie.pluton.cc/]
*/
// imgs variables
images = {} // img table declaration
currentImage = 0 // current img
numImages = 30 // max num of img
// video capture
grabber = ofVideoGrabber()
cam = ofTexture()
previewOpacity = 0
// output img size
captureW = OUTPUT_W
captureH = OUTPUT_H
// switchs
preview = false // info + webcam
presencia = false // presence
grabar = false // recording
// time variables
wait = 250 // wait between shots
// font variablesfnt = ofTrueTypeFont()
fntSize = 14
fntR = 255
fntG = 0
fntOpacity = 0
// sound variables
volume = 0.0
function setup()
grabber:setDeviceID(1) // input video declaration
grabber:initGrabber(captureW, captureH) // start video capture
cam:allocate(captureW, captureH, GL_RGB) // draw video capture (only in preview)
cam:clear()
// draw saved img
setupImages(numImages)
loadImageLibrary(numImages)
end
function update()
// update audio capture
volume = gaGetVolume(0)
// update video capture
grabber:update()
if grabber:isFrameNew() then
cam = grabber:getTextureReference()
end
// loud sound starts recording
if volume > 0.9 and grabar == false then
presencia = true
grabar = true
end
// if clap or loud sound start recording and playing
if presencia then
previewOpacity = 0
if grabar and ofGetElapsedTimeMillis() > wait then
_path = gaDataPath(string.format("images/export%i.png", currentImage))
gaSaveFrame(_path, grabber:getTextureReference())
if currentImage < numImages-1 then
currentImage += 1
else
currentImage = 0
end
loadImageLibrary(numImages)
ofResetElapsedTimeCounter()
end
end
// stop playing on last img
if currentImage >= numImages-1 then
presencia = false
grabar = false
currentImage = 0
end
end
function draw()
gaBackground(0.0, 1.0)
/* captured imgs */
ofSetColor(255, 120)
images[currentImage]:draw(0, 0, captureW, captureH)
/* webcam */
ofSetColor(255, previewOpacity)
cam:draw(0, 0, OUTPUT_W, OUTPUT_H)
/* text */
if presencia == false then
previewOpacity = 0
ofSetColor(255)
fnt:loadFont(gaImportFile("DINBlackAlternate.ttf"), 50, false, false)
fnt:drawString(string.format("CLAP TO START"), 130, OUTPUT_H/2-30)
fnt:drawString(string.format("take your time"), 160, OUTPUT_H/2+100)
end
/* info */
ofSetColor(255, fntOpacity)
fnt:loadFont(gaImportFile("DINBlackAlternate.ttf"), fntSize, false, false)
fnt:drawString(string.format("PREVIEW", preview), 10, OUTPUT_H-168)
fnt:drawString(string.format("[p]", preview), fntSize*10, OUTPUT_H-168)
fnt:drawString(string.format("VOLUME", volume), 10, OUTPUT_H-146)
fnt:drawString(string.format("%f", volume), fntSize*10, OUTPUT_H-146)
fnt:drawString(string.format("PRESENCE", presencia), 10, OUTPUT_H-124)
fnt:drawString(tostring(presencia), fntSize*10, OUTPUT_H-124)
fnt:drawString(string.format("RECORDING", grabar), 10, OUTPUT_H-102)
fnt:drawString(tostring(grabar), fntSize*10, OUTPUT_H-102)
fnt:drawString(string.format("WAIT", wait), 10, OUTPUT_H-80)
fnt:drawString(string.format("%i ms", wait), fntSize*10, OUTPUT_H-80)
fnt:drawString(string.format("IMAGE", numImages), 10, OUTPUT_H-58)
fnt:drawString(string.format("%i", currentImage+1), fntSize*10, OUTPUT_H-58)
fnt:drawString(string.format("/%i", numImages), fntSize*12, OUTPUT_H-58)
end
function keyReleased()
if grabar then // play loop
setupImages(numImages)
loadImageLibrary(numImages)
currentImage = 0
elseif grabar == false then // stop loop and back to first img
currentImage = 0
end
/* preview info and webcam */
if gaKey() == string.byte('p') and preview then
previewOpacity = 0
fntOpacity = 0
preview = false
gaLog(string.format("preview off"))
elseif gaKey() == string.byte('p') and preview == false then
previewOpacity = 0
fntOpacity = 255
preview = true
gaLog(string.format("preview on"))
end
end