Code for Processing: Difference between revisions

From Medien Wiki
(Created page with "import processing.serial.*; Serial myPort; int r; void setup() { println("Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); size(600, 600);...")
 
No edit summary
Line 1: Line 1:
/*
import processing.serial.*;
import processing.serial.*;


Serial myPort;
Serial myPort;
int r;
int r;
                   
                   
 
void setup() {
void setup() {
 
 
   println("Start15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)15:54, 23 November 2021 (UTC)~~");
   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
   randomSeed(second());  // initialize random number
   randomSeed(second());  // initialize random number
   r = width;
   r = width;


  println(Serial.list());


  println(Serial.list());
   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 21: Line 24:
}
}


void draw()
{
  background(255);


  fill(random(0,255), random(0,255), random(0,255));  // fill with random color


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
   ellipse(width/2, height/2, r, r);                      // draw a circle
(스케치 실행창에 원을 그림)
 
   line(width/2, 0, width/2, height);                  // draw a line
   line(width/2, 0, width/2, height);                  // draw a line
   line(0, height/2, width, height/2);                // draw a line
   line(0, height/2, width, height/2);                // draw a line




   fill(0, 120);                                                  // black, transparency 120
   fill(0, 120);                                                  // black, transparency 120
   textAlign(CENTER, CENTER);
   textAlign(CENTER, CENTER);
   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 44: Line 53:
    
    
   String response = p.readStringUntil('\n').trim();  // Read Stored Data
   String response = p.readStringUntil('\n').trim();  // Read Stored Data
   r = int(response);
   r = int(response);
   r = constrain(r, 5, width) ;                        // r is MIN: 5 ~ MAX: width
   r = constrain(r, 5, width) ;                        // r is MIN: 5 ~ MAX: width


}
}
*/

Revision as of 15:59, 23 November 2021

/*

import processing.serial.*;

Serial myPort;

int r;

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
 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

}


  • /