Code for Processing: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 1: Line 1:
/*
import processing.serial.*;
import processing.serial.*;


Line 8: Line 6:
                      
                      
void setup() {
void setup() {
  println("Start15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)15:59, 23 November 2021 (UTC)~~");
   size(600, 600);        // window size
   size(600, 600);        // window size


Line 20: Line 15:


   myPort = new Serial(this, Serial.list()[2], 9600);
   myPort = new Serial(this, Serial.list()[2], 9600);
   myPort.bufferUntil('\n');                          // store data in buffer
   myPort.bufferUntil('\n');                          // store data in buffer
    
    
Line 43: Line 39:
   textSize(r/2);
   textSize(r/2);


   text(r, width/2, height/2);                         // express distance in the window
   text(r, width/2, height/2);           // express distance in the window (스케치 실행창에 거리측정값 표현)
 
(스케치 실행창에 거리측정값 표현)


}
}
Line 59: Line 53:


}
}
*/

Revision as of 16:02, 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

}