-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor_lines_serial.pde
More file actions
47 lines (42 loc) · 1.28 KB
/
Color_lines_serial.pde
File metadata and controls
47 lines (42 loc) · 1.28 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
/*
Continuous line creations
first created by RedFrik
With Serial communication
Michel Platnic - 2007
*/
import processing.serial.*; //import the Serial library
Serial myPort; // The serial port, this is a new instance of the Serial class (an Object)
float serialInput = 0.0;
int i= 0;
void setup() {
frameRate(60); //faster frame updaterate
size(1040, 880, P2D); //using P2D renderer for nicer lines
// smooth(4); //some antialiasing
background(0);
// List all the available serial ports
printArray(Serial.list());
// change the number below to match your port:
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
//version 1 gray
//version 2 colorful
//stroke(50,(70+i)%255,(200+i*0.5)%255);
//version 3 colorful sine wave
stroke(sin(i*0.03)*127.5+127.5,cos(i*0.02)*127.5+127.5,60);
rotate(serialInput/100);
line( //arguments can be written on separate lines - easier to read
sin(i*0.029)*width*0.5+(width*0.5), //start x
sin(i*0.04)*height*0.5+(height*0.5), //start y
sin(i*0.03)*width*0.5+(width*0.5), //stop x
sin(i*0.012+0.3)*height*0.5+(height*0.5) //stop y
);
i++;
}
void serialEvent (Serial myPort) {
// get the byte:
serialInput = myPort.read();
// print it:
println(serialInput/50);
}