프로세싱 광운대학교로봇학부박광현
프로세싱실행 2 C:\processing-3.2.1 폴더
창나타내기 실행 정지 3 폭 높이 600 400
도형그리기
배경칠하기 5 background(255, 255, 255); R G B background(255, 0, 0); background(255, 122, 0);
선그리기 6 background(255, 122, 0); stroke(0, 0, 255); line(10, 20, 300, 200); 선색깔 ( 그리기전에설정한다 ) (0, 0) (10, 20) (300, 200)
선두께 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); line(10, 20, 300, 200); 선두께 ( 픽셀 ) ( 그리기전에설정한다 ) 7
직사각형그리기 8 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); rect(10, 20, 300, 200); (0, 0) (10, 20) 폭 높이 200 300
색깔채우기 9 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); rect(10, 20, 300, 200); 채우기색깔 ( 그리기전에설정한다 )
선 / 채움없애기 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); nostroke(); rect(10, 20, 300, 200); 10 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); nofill(); rect(10, 20, 300, 200);
타원그리기 11 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); rect(10, 20, 300, 200); ellipse(160, 120, 300, 200); (0, 0) 폭 높이 (160, 120) 200 300
점그리기 12 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); rect(10, 20, 300, 200); ellipse(160, 120, 300, 200); point(160, 120); (0, 0) (160, 120)
삼각형그리기 13 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); triangle(10, 20, 300, 200, 200, 300); (0, 0) (10, 20) (300, 200) (200, 300)
사각형그리기 14 background(255, 122, 0); stroke(0, 0, 255); strokeweight(4); fill(0, 255, 0); quad(10, 20, 300, 200, 200, 300, 100, 250); (0, 0) (10, 20) (300, 200) (100, 250) (200, 300)
애니메이션
기본형태 16 void setup() { void draw() {
색깔애니메이션 17 void setup() { background(255, 122, 0); stroke(0, 0, 255); void draw() { int c = framecount % 256; fill(c, 0, 0); rect(10, 20, 300, 200); 1 부터시작 draw() 호출하고 1 씩증가
직선예술 18 void setup() { background(255, 255, 255); void draw() { stroke(random(256), random(256), random(256)); line(random(width), random(height), random(width), random(height)); random(end); random(start, end); end 는포함안됨
마우스 void setup() { background(255); stroke(0, 0, 255); 19 background(255, 255, 255) 와같음 void draw() { line(200, 200, mousex, mousey); void setup() { stroke(0, 0, 255); void draw() { background(255); line(200, 200, mousex, mousey);
마우스 20 void setup() { stroke(0, 0, 255); void draw() { line(200, 200, mousex, mousey); void mousepressed() { background(255);
마우스 21 void setup() { stroke(0, 0, 255); void draw() { line(200, 200, mousex, mousey); void mousepressed() { if(mousebutton == LEFT) background(255); else background(255, 122, 0);
마우스 22 mousebutton mouseclicked() mousedragged() mousemoved() mousepressed() mousereleased() mousewheel() mousex mousey pmousex pmousey
마우스 23 void setup() { background(255); stroke(0, 0, 255); void draw() { void mousedragged() { line(pmousex, pmousey, mousex, mousey);
마우스 24 void setup() { background(255); stroke(0, 0, 255); fill(0, 255, 0); void draw() { background(255); rect(mousex, mousey, 30, 30);
키보드 25 void setup() { background(255); stroke(0, 0, 255); void draw() { line(200, 200, mousex, mousey); void keypressed() { if(key == 'a') background(255); else background(255, 122, 0);
키보드 26 key keycode keypressed() keypressed keyreleased() keytyped()
햄스터
라이브러리사용 28 스케치 > 내부라이브러리... > Roboid
1 초앞으로이동하기 29 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { hamster.wheels(30, 30); delay(1000); hamster.stop(); 왼쪽바퀴속도 (-100 ~ 100) % 오른쪽바퀴속도 (-100 ~ 100) % msec (1000 분의 1 초단위 )
1 초뒤로이동하기 30 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { hamster.wheels(-30, -30); delay(1000); hamster.stop();
제자리돌기 ( 스핀 ) 31 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { hamster.wheels(-30, 30); delay(1000); hamster.stop();
한쪽바퀴를축으로회전하기 ( 피봇턴 ) 32 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { hamster.wheels(0, 30); delay(1000); hamster.stop();
둥글게회전하기 ( 라운드턴 ) 33 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { hamster.wheels(20, 40); delay(1000); hamster.stop();
근접센서값관찰하기 34 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { while(true) { println(hamster.leftproximity()); delay(20);
손을가져가면뒤로도망가기 35 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { void run() { while(hamster.leftproximity() < 50) { delay(20); hamster.wheels(-30, -30);
밀당로봇 36... void run() { while(true) { if(hamster.leftproximity() > 40) { hamster.wheels(-30, -30); else { hamster.wheels(30, 30); delay(20);
LED 켜고끄기 37... void run() { while(true) { if(hamster.leftproximity() > 40) { hamster.leds(hamster.led_red, Hamster.LED_RED); hamster.wheels(-30, -30); else { hamster.leds(0, 0); hamster.wheels(30, 30); delay(20); 왼쪽 LED 색깔 오른쪽 LED 색깔
버저소리내기 38... void run() { while(true) { if(hamster.leftproximity() > 40) { hamster.leds(hamster.led_red, Hamster.LED_RED); hamster.buzzer(1000); hamster.wheels(-30, -30); else { hamster.leds(0, 0); hamster.buzzer(0); hamster.wheels(30, 30); delay(20); Hz
햄스터 + 그래픽
키보드조종기 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void setup() { hamster = Hamster.create(this); void draw() { 40 void keypressed() { if(key == ' ') hamster.stop(); else if(key == CODED) { if(keycode == UP) hamster.wheels(30, 30); else if(keycode == DOWN) hamster.wheels(-30, -30); else if(keycode == LEFT) hamster.wheels(-30, 30); else if(keycode == RIGHT) hamster.wheels(30, -30);
마우스조종기 41 import org.roboid.core.*; import processing.hamster.*; import org.roboid.robot.*; Hamster hamster; void run() { while(true) { if(mousepressed) { int dx = (100 - mousex) / 2; int dy = (100 - mousey) / 2; void setup() { size(200,200); hamster = Hamster.create(this); void draw() { background(255); fill(0); ellipse(100,100, 30, 30); line(100,100, mousex, mousey); if(dy < 0) hamster.wheels(dy + dx, dy - dx); else hamster.wheels(dy - dx, dy + dx); else { hamster.stop(); delay(20);
수고하셨습니다. http://hamster.school akaii@kw.ac.kr