-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimaton.pde
200 lines (168 loc) · 4.26 KB
/
minimaton.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//Minimaton
//by Fabrice, Phil, tmator
//Inspired from Video2ledwallHarpSerial V1.0 by Fabrice Fourc
// http://www.tetalab.org
// import processing.video.*;
import processing.net.*;
import codeanticode.gsvideo.*;
//GSCapture video;
boolean cheatScreen;
int plage=44;//256;
int MINITEL_CHAR_WIDTH = 40;//*2;
int MINITEL_CHAR_HEIGHT = 24;//*4;
// en fait ce n'est pas vraiment un pixel par pixel char...
int PIXEL_CHAR_WIDTH = 2;
int PIXEL_CHAR_HEIGHT = 3;
// Size of each cell in the grid, ratio of window size to video size
int videoScale = 10;
int videoScalex = 1;//8;
int videoScaley = 1;//6;
int count = 0;
// Number of columns and rows in our system
int cols, rows;
// Variable to hold onto Capture object
public int s = 140;
import processing.serial.*;
// The serial port:
Serial myPort;
//luminosite globale de la colone pour le son
int colValue;
String ledCol;
String ledWallMsg;
//Client myClient;
GSCapture video;
void setup()
{
//size(MINITEL_CHAR_WIDTH*PIXEL_CHAR_WIDTH*videoScalex, MINITEL_CHAR_HEIGHT*PIXEL_CHAR_HEIGHT*videoScaley);
size(640,480);
frameRate(25);
//frame.setResizable(true);
// List all the available serial ports:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 1200);
//myClient = new Client(this, "127.0.0.1", 5204);
// Initialize columns and rows
cols = 640/videoScalex;
rows = 480/videoScaley;
video = new GSCapture(this, 640, 480, "/dev/video0");
video.start();
}
//----------------------------------------------------------
void displayPixelChar2(int x, int y)
{
x= x *2;
y = y * 3;
byte carac=0; // caractère pixel
carac+=(Math.pow(2, 0))*getG2(x+0, y+0);
carac+=(Math.pow(2, 1))*getG2(x+1, y+0);
carac+=(Math.pow(2, 2))*getG2(x+0, y+1);
carac+=(Math.pow(2, 3))*getG2(x+1, y+1);
carac+=(Math.pow(2, 4))*getG2(x+0, y+2);
carac+=(Math.pow(2, 5))*1;
carac+=(Math.pow(2, 6))*getG2(x+1, y+2);
myPort.write(carac);
// println("carac= "+carac);
}
int getG2(int x, int y)
{
//println("x + y*video.width" + (x + y*video.width));
color c = video.pixels[x + y*video.width];
int value = (int)brightness(c); // get the brightness
if (value<s)
{
return(0);
}
else
{
return(1);
}
}
void draw() {
// Read image from the camera
noStroke();
if (video.available())
{
video.read();
}
//scale(0.5);
//frame.resize(160,120);
video.loadPixels();
if (!mousePressed) //si je ne clique pas, j'affiche le preview
{
//image(video, 0, 0);
// Begin loop for columns
for (int i = 0; i < cols; i+=8)
{
// Begin loop for rows
for (int j = 0; j < rows; j+=6)
{
// Where are we, pixel-wise?
int x = i;
int y = j;
// Looking up the appropriate color in the pixel array
color c = video.pixels[i + j*video.width];
int value = (int)brightness(c); // get the brightness
if (value<s)
{
fill(0);
}
else
{
fill(255);
}
rect(x, y,8,6);// ,6);// 8,6);//,6);// videoScaley);
}
ledWallMsg += ledCol;
}
}
else //si je clique sur l'image j'envoi sur le port serie
{
//myPort.write(12);
//myPort.write(14);
/* for (int y=0;y<MINITEL_CHAR_HEIGHT;y++)
{
for (int x=0;x<MINITEL_CHAR_WIDTH;x++)
{
displayPixelChar2(x, y);
//println("x= "+x+"y= "+y);
}
}*/
}
// if (count%4 == 0) {
// s+=1;
// }
}
void keyPressed() //reglage du seuil (a-, z+)
{
if ( key == 'a')
{
s = s - 1;
println("s " + s);
}
if ( key == 'z')
{
s = s + 1;
println("s " + s);
}
if ( key == ' ')
{
//on save et on imprime
saveFrame("/tmp/img.png");
try {
String[] command = new String[1];
command[0]="/folder/print.sh";
Process p = exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}//fin while
} // fin try
catch (IOException e) { // gestion exception
e.printStackTrace();
} // fin catch
}
}