(Created page with "import processing.serial.*; Serial myPort; int r; void setup() { println("Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); size(600, 600);...") |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
Serial myPort; | Serial myPort; | ||
int r; | int r; | ||
void setup() { | void setup() { | ||
size(600, 600); // window size | |||
randomSeed(second()); // initialize random number | |||
r = width; | |||
println(Serial.list()); | |||
myPort = new Serial(this, Serial.list()[2], 9600); | |||
myPort.bufferUntil('\n'); // store data in buffer | |||
} | } | ||
void draw() | |||
{ | |||
background(255); | |||
fill(random(0,255), random(0,255), random(0,255)); // fill with random color | |||
ellipse(width/2, height/2, r, r); // draw a circle | |||
line(width/2, 0, width/2, height); // draw a line | |||
line(0, height/2, width, height/2); // draw a line | |||
fill(0, 120); // black, transparency 120 | |||
textAlign(CENTER, CENTER); | |||
textSize(r/2); | |||
text(r, width/2, height/2); // express distance in the window (스케치 실행창에 거리측정값 표현) | |||
} | } | ||
void serialEvent(Serial p) { // Read Serial port value | void serialEvent(Serial p) { // Read Serial port value | ||
String response = p.readStringUntil('\n').trim(); // Read Stored Data | |||
r = int(response); | |||
r = constrain(r, 5, width) ; // r is MIN: 5 ~ MAX: width | |||
} | } |
Latest revision as of 16:29, 23 November 2021
import processing.serial.*;
Serial myPort;
int r;
void setup() {
size(600, 600); // window size
randomSeed(second()); // initialize random number
r = width;
println(Serial.list());
myPort = new Serial(this, Serial.list()[2], 9600);
myPort.bufferUntil('\n'); // store data in buffer
}
void draw()
{
background(255);
fill(random(0,255), random(0,255), random(0,255)); // fill with random color
ellipse(width/2, height/2, r, r); // draw a circle
line(width/2, 0, width/2, height); // draw a line
line(0, height/2, width, height/2); // draw a line
fill(0, 120); // black, transparency 120
textAlign(CENTER, CENTER);
textSize(r/2);
text(r, width/2, height/2); // express distance in the window (스케치 실행창에 거리측정값 표현)
}
void serialEvent(Serial p) { // Read Serial port value
String response = p.readStringUntil('\n').trim(); // Read Stored Data
r = int(response);
r = constrain(r, 5, width) ; // r is MIN: 5 ~ MAX: width
}