SlideShare a Scribd company logo
1 of 25
Processing과
Arduino
송치원
https://processing.org/
Processing is a flexible software sketchbook
and a language for learning how to code
within the context of the visual arts.
Console
Hello World
Drawing
실행결과
Draw Frames
실행결과
Draw Frames
void setup() {
size(640, 480); //W, H
}
int r_x = 0;
int add = 5;
int e_x = 20, e_y = 20;
int e_add_x = 3, e_add_y = 3;
void draw() {
background(200, 200, 200); //R, G, B
noStroke();
fill(255, 0, 0); //R, G, B
rect(r_x, 400, 100, 30); //X, Y, W, H
stroke(0, 0, 0);
fill(0, 255, 0);
ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY
e_x += e_add_x;
e_y += e_add_y;
if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x;
if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y;
if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30)
e_add_y = -e_add_y;
r_x += add;
if(r_x < 0 || r_x > 640-100) add = -add;
}
실행결과
sample int count = 200;
int snowx[]= new int[count];
int snowy[]= new int[count];
int speed[]= new int[count];
int size[]= new int[count];
void setup() {
size(320, 200);
for(int i=0; i<count; i++) {
snowx[i] = (int)random(0, 320);
snowy[i] = (int)random(0, 200);
speed[i] = (int)random(1, 4);
size[i] = (int)random(1, 5);
}
}
void draw() {
background(0);
for(int i=0; i<count; i++) {
ellipse(snowx[i], snowy[i], size[i], size[i]);
snowy[i]+=speed[i];
if(snowy[i] >= 200) {
snowy[i] = 0;
snowx[i] = (int)random(0, 320);
speed[i] = (int)random(1, 4);
size[i] = (int)random(1, 5);
}
}
}
실행결과
Drawing Functions
Mouse Event
void setup() {
}
void draw() {
if(mousePressed) {
println("mouse pressed");
}
}
void setup() {
}
void draw() {
}
void mousePressed() {
println("mouse pressed");
}
void setup() {
}
void draw() {
}
void mousePressed() {
if(mouseButton == LEFT) {
println("Left mouse button pressed");
}
else if(mouseButton == CENTER) {
println("Center mouse button pressed");
}
else if(mouseButton == RIGHT) {
println("Right mouse button pressed");
}
}
Mouse Button Pressed Pressed Mouse Button
Mouse Event
void setup() {
}
void draw() {
}
void mousePressed() {
if(mouseButton == LEFT) {
println("Left mouse button pressed");
}
else if(mouseButton == CENTER) {
println("Center mouse button pressed");
}
else if(mouseButton == RIGHT) {
println("Right mouse button pressed");
}
}
void mouseReleased() {
if(mouseButton == LEFT) {
println("Left mouse button released");
}
}
void mouseClicked() {
if(mouseButton == LEFT) {
println("Left mouse button clicked");
}
}
void mouseDragged() {
println("Drag MouseX:"+mouseX+" ,
MouseY:"+mouseY);
}
void mouseWheel(processing.event.MouseEvent
event) {
int e = event.getCount();
println("Wheel:"+e);
}
void mouseMoved() {
println("Move MouseX:"+mouseX+" ,
MouseY:"+mouseY);
}
sample
class LineElement {
int x, y, x2, y2;
}
ArrayList<LineElement> lines = new ArrayList<LineElement>();
int p_x = -1, p_y = -1;
void setup() {
size(320, 200);
stroke(255);
strokeWeight(2);
}
void draw() {
background(0);
stroke(255);
for(LineElement l : lines) {
line(l.x, l.y, l.x2, l.y2);
}
stroke(0, 0, 255);
if(p_x >= 0 && p_y >= 0) {
line(p_x, p_y, mouseX, mouseY);
}
}
void mousePressed() {
if(p_x >= 0 && p_y >= 0) {
LineElement l = new LineElement();
l.x = p_x;
l.y = p_y;
l.x2 = mouseX;
l.y2 = mouseY;
lines.add(l);
}
p_x = mouseX;
p_y = mouseY;
}
Keyboard Event
void setup() {
}
void draw() {
if (keyPressed) {
if (key == 'b' || key == 'B') {
background(0);
} else {
background(255);
}
}
}
int value = 0;
void draw() {
background(value);
}
void keyPressed() {
if (key == 'b' || key == 'B') {
value = 0;
} else {
value = 255;
}
}
void draw() {
}
void keyPressed() {
println("pressed " + key + "(" + keyCode + ")");
}
void keyReleased() {
println("released " + key + "(" + keyCode + ")");
}
void keyTyped() {
println("typed " + key + "(" + keyCode + ")");
}
Key Pressed Pressed Mouse Button
pressed a(65)
typed a(0)
released a(65)
sample
void setup() {
size(640, 480); //W, H
}
int r_x = 0;
int e_x = 20, e_y = 20;
int e_add_x = 3, e_add_y = 3;
void draw() {
background(200, 200, 200); //R, G, B
noStroke();
fill(255, 0, 0); //R, G, B
rect(r_x, 400, 100, 30); //X, Y, W, H
stroke(0, 0, 0);
fill(0, 255, 0);
ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY
e_x += e_add_x;
e_y += e_add_y;
if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x;
if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y;
if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30)
e_add_y = -e_add_y;
}
void keyPressed() {
if(keyCode == LEFT) {
r_x -= 10;
if(r_x < 0) r_x = 0;
} else if(keyCode == RIGHT) {
r_x += 10;
if(r_x > 640-100) r_x = 640-100;
}
}
Serial
통신
Arduino 와 PC를 연결하는 방법
Serial.begin(9600);
Serial.print(“command”);
Serial.read()
serial = new Serial();
serial.readChar();
serial.writeChar();
Arduino Side
void setup() {
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char ch = Serial.read();
if(ch == '1') digitalWrite(8, HIGH);
else digitalWrite(8, LOW);
}
}
Serial Monitor
Processing Side
import processing.serial.*;
Serial serial;
int pMouseX = 0;
void setup() {
size(320, 200);
serial = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
fill(0);
rect(0, 0, 160, 200);
fill(255);
rect(160, 0, 160, 200);
if(pMouseX < 160 && mouseX >= 160) {
serial.write('1');
} else if(pMouseX >= 160 && mouseX < 160) {
serial.write('0');
}
pMouseX = mouseX;
}
Arduino Side
int pButtonState = 0;
void setup() {
pinMode(8, INPUT);
Serial.begin(9600);
}
void loop() {
int buttonPressed = digitalRead(8);
if(pButtonState == LOW && buttonPressed == HIGH) {
Serial.print('1');
}
pButtonState = buttonPressed;
}
Serial Monitor
Processing Side
import processing.serial.*;
Serial serial;
void setup() {
size(320, 200);
serial = new Serial(this, Serial.list()[0], 9600);
background(0);
}
void draw() {
if(serial.available() > 0) {
int ch = serial.read();
if(ch == '1') {
int red = (int)random(255);
int green = (int)random(255);
int blue = (int)random(255);
int x = (int)random(320);
int y = (int)random(200);
int size = (int)random(30, 100);
fill(red, green, blue, 180);
ellipse(x, y, size, size);
}
}
}
sample Arduino Side
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A1);
Serial.println(value);
delay(100);
}
sample Processing Side
void draw() {
background(200, 200, 200); //R, G, B
noStroke();
fill(255, 0, 0); //R, G, B
rect(r_x, 400, 100, 30); //X, Y, W, H
stroke(0, 0, 0);
fill(0, 255, 0);
ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY
if(serial.available() > 0) {
String val = serial.readStringUntil(lf);
if(val != null) {
val = val.trim();
if(val.length() > 0) {
int val2 = Integer.parseInt(val.trim());
r_x = val2 * (640-100) / 1024;
}
}
}
e_x += e_add_x;
e_y += e_add_y;
if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x;
if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y;
if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30)
e_add_y = -e_add_y;
}
import processing.serial.*;
int lf = 10;
Serial serial;
int r_x = 0;
int e_x = 20, e_y = 20;
int e_add_x = 3, e_add_y = 3;
void setup() {
size(640, 480);
serial = new Serial(this, Serial.list()[0], 9600);
}
sample Arduino Side
int pinTrig = 7;
int pinEcho = 6;
void setup() {
Serial.begin(9600);
pinMode(pinTrig, OUTPUT);
pinMode(pinEcho, INPUT);
}
void loop() {
int value = distance();
Serial.println(value);
delay(300);
}
long distance() {
digitalWrite(pinTrig, LOW);
delayMicroseconds(2);
digitalWrite(pinTrig, HIGH);
delayMicroseconds(10);
digitalWrite(pinTrig, LOW);
long val= pulseIn(pinEcho, HIGH) * 17 / 100;
return val;
}
sample Processing Side
import processing.serial.*;
int lf = 10;
float zoom = 0.1;
Serial serial;
PImage img;
void setup() {
size(800, 600);
img = loadImage("image.jpg");
serial = new Serial(this, Serial.list()[1], 9600);
}
void draw() {
background(0);
if(serial.available() > 0) {
String val = serial.readStringUntil(lf);
if(val != null) {
val = val.trim();
if(val.length() > 0) {
float val2 = Float.parseFloat(val.trim());
zoom = max(min(val2 / 100, 1.0), 0.1);
}
}
}
float imageWidth = img.width * zoom;
float imageHeight = img.height * zoom;
image(img, (800 - imageWidth)/2, (600 - imageHeight)/2, imageWidth, imageHeight);
}
image.jpg
https://youtu.be/jjvy_jzGlAQ
아두이노 + 가속도센서 + 빛센서

More Related Content

What's hot

Processing資料(8) 文字
Processing資料(8) 文字Processing資料(8) 文字
Processing資料(8) 文字reona396
 
Processing iii
Processing iiiProcessing iii
Processing iiicitylore
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 
Processing資料(5) 正弦波と極座標
Processing資料(5) 正弦波と極座標Processing資料(5) 正弦波と極座標
Processing資料(5) 正弦波と極座標reona396
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligenceAditya Sharma
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvassuitzero
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
Cuarto Punto Parte B
Cuarto Punto Parte BCuarto Punto Parte B
Cuarto Punto Parte Bgustavo206
 
Simulate bouncing ball in pygame
Simulate bouncing ball in pygameSimulate bouncing ball in pygame
Simulate bouncing ball in pygameDr Anurekha R
 
Simulate elliptical orbit in pygame
Simulate elliptical orbit in pygameSimulate elliptical orbit in pygame
Simulate elliptical orbit in pygameDr Anurekha R
 
Introduction to Processing and creative coding
Introduction to Processing and creative codingIntroduction to Processing and creative coding
Introduction to Processing and creative codingJerome Herr
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysGilbert Guerrero
 

What's hot (18)

Processing資料(8) 文字
Processing資料(8) 文字Processing資料(8) 文字
Processing資料(8) 文字
 
Proga 0601
Proga 0601Proga 0601
Proga 0601
 
Processing iii
Processing iiiProcessing iii
Processing iii
 
Vcs9
Vcs9Vcs9
Vcs9
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 
Processing資料(5) 正弦波と極座標
Processing資料(5) 正弦波と極座標Processing資料(5) 正弦波と極座標
Processing資料(5) 正弦波と極座標
 
Kwp2 100107
Kwp2 100107Kwp2 100107
Kwp2 100107
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvas
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Oprerator overloading
Oprerator overloadingOprerator overloading
Oprerator overloading
 
Cuarto Punto Parte B
Cuarto Punto Parte BCuarto Punto Parte B
Cuarto Punto Parte B
 
Simulate bouncing ball in pygame
Simulate bouncing ball in pygameSimulate bouncing ball in pygame
Simulate bouncing ball in pygame
 
Simulate elliptical orbit in pygame
Simulate elliptical orbit in pygameSimulate elliptical orbit in pygame
Simulate elliptical orbit in pygame
 
Introduction to Processing and creative coding
Introduction to Processing and creative codingIntroduction to Processing and creative coding
Introduction to Processing and creative coding
 
pptuni1
pptuni1pptuni1
pptuni1
 
Tabla derivadas
Tabla derivadasTabla derivadas
Tabla derivadas
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + Arrays
 

Viewers also liked

Arduino+Matlab Project - Talking Window Blind
Arduino+Matlab Project - Talking Window BlindArduino+Matlab Project - Talking Window Blind
Arduino+Matlab Project - Talking Window BlindByoungjo Choi
 
Arduino+Matlab Project - Automatic Rotating Door
Arduino+Matlab Project - Automatic Rotating DoorArduino+Matlab Project - Automatic Rotating Door
Arduino+Matlab Project - Automatic Rotating DoorByoungjo Choi
 
[2] 아두이노 활용 실습
[2] 아두이노 활용 실습[2] 아두이노 활용 실습
[2] 아두이노 활용 실습Chiwon Song
 
Arduino by Todd Holoubeck
Arduino by Todd HoloubeckArduino by Todd Holoubeck
Arduino by Todd Holoubecksookmyungvisual
 
Arduino+Matlab Project - Smart Fan
Arduino+Matlab Project - Smart FanArduino+Matlab Project - Smart Fan
Arduino+Matlab Project - Smart FanByoungjo Choi
 
Arduino+Matlab Project - Automatic Coin Sorter
Arduino+Matlab Project - Automatic Coin SorterArduino+Matlab Project - Automatic Coin Sorter
Arduino+Matlab Project - Automatic Coin SorterByoungjo Choi
 
Arduino 소개, RC카 만들기
Arduino 소개, RC카 만들기Arduino 소개, RC카 만들기
Arduino 소개, RC카 만들기Ji Hun Kim
 
Arduino Basic Programming
Arduino Basic ProgrammingArduino Basic Programming
Arduino Basic ProgrammingSangGyu Kim
 
모바일 스마트 홈 구축
모바일 스마트 홈 구축모바일 스마트 홈 구축
모바일 스마트 홈 구축Devgear
 
Arduino UNO로 키보드 만들기
Arduino UNO로 키보드 만들기Arduino UNO로 키보드 만들기
Arduino UNO로 키보드 만들기Chae Yeon Cho
 

Viewers also liked (10)

Arduino+Matlab Project - Talking Window Blind
Arduino+Matlab Project - Talking Window BlindArduino+Matlab Project - Talking Window Blind
Arduino+Matlab Project - Talking Window Blind
 
Arduino+Matlab Project - Automatic Rotating Door
Arduino+Matlab Project - Automatic Rotating DoorArduino+Matlab Project - Automatic Rotating Door
Arduino+Matlab Project - Automatic Rotating Door
 
[2] 아두이노 활용 실습
[2] 아두이노 활용 실습[2] 아두이노 활용 실습
[2] 아두이노 활용 실습
 
Arduino by Todd Holoubeck
Arduino by Todd HoloubeckArduino by Todd Holoubeck
Arduino by Todd Holoubeck
 
Arduino+Matlab Project - Smart Fan
Arduino+Matlab Project - Smart FanArduino+Matlab Project - Smart Fan
Arduino+Matlab Project - Smart Fan
 
Arduino+Matlab Project - Automatic Coin Sorter
Arduino+Matlab Project - Automatic Coin SorterArduino+Matlab Project - Automatic Coin Sorter
Arduino+Matlab Project - Automatic Coin Sorter
 
Arduino 소개, RC카 만들기
Arduino 소개, RC카 만들기Arduino 소개, RC카 만들기
Arduino 소개, RC카 만들기
 
Arduino Basic Programming
Arduino Basic ProgrammingArduino Basic Programming
Arduino Basic Programming
 
모바일 스마트 홈 구축
모바일 스마트 홈 구축모바일 스마트 홈 구축
모바일 스마트 홈 구축
 
Arduino UNO로 키보드 만들기
Arduino UNO로 키보드 만들기Arduino UNO로 키보드 만들기
Arduino UNO로 키보드 만들기
 

Similar to [3] 프로세싱과 아두이노

Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regularesAnel Sosa
 
Creative Coding 1 - 2 Variables
Creative Coding 1 - 2 VariablesCreative Coding 1 - 2 Variables
Creative Coding 1 - 2 VariablesTill Nagel
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2fraytuck
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
第一回 冬のスイッチ大勉強会 - XBee編 -
第一回 冬のスイッチ大勉強会 - XBee編 -第一回 冬のスイッチ大勉強会 - XBee編 -
第一回 冬のスイッチ大勉強会 - XBee編 -Wataru Kani
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docxPiersRCoThomsonw
 

Similar to [3] 프로세싱과 아두이노 (20)

Proga 090525
Proga 090525Proga 090525
Proga 090525
 
Proga 0608
Proga 0608Proga 0608
Proga 0608
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
 
Kwp2 100121
Kwp2 100121Kwp2 100121
Kwp2 100121
 
Kwp2 100121
Kwp2 100121Kwp2 100121
Kwp2 100121
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Proga 0518
Proga 0518Proga 0518
Proga 0518
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Proga 0622
Proga 0622Proga 0622
Proga 0622
 
Programa expresiones regulares
Programa expresiones regularesPrograma expresiones regulares
Programa expresiones regulares
 
Sbaw090623
Sbaw090623Sbaw090623
Sbaw090623
 
Creative Coding 1 - 2 Variables
Creative Coding 1 - 2 VariablesCreative Coding 1 - 2 Variables
Creative Coding 1 - 2 Variables
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
Documento de acrobat2
Documento de acrobat2Documento de acrobat2
Documento de acrobat2
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
graphics Assidnment
graphics Assidnmentgraphics Assidnment
graphics Assidnment
 
第一回 冬のスイッチ大勉強会 - XBee編 -
第一回 冬のスイッチ大勉強会 - XBee編 -第一回 冬のスイッチ大勉強会 - XBee編 -
第一回 冬のスイッチ大勉強会 - XBee編 -
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 

More from Chiwon Song

20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기Chiwon Song
 
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)Chiwon Song
 
20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POPChiwon Song
 
20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?Chiwon Song
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계Chiwon Song
 
20200815 inversions
20200815 inversions20200815 inversions
20200815 inversionsChiwon Song
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swiftChiwon Song
 
[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안Chiwon Song
 
[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행Chiwon Song
 
20190330 immutable data
20190330 immutable data20190330 immutable data
20190330 immutable dataChiwon Song
 
20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해Chiwon Song
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order functionChiwon Song
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragmentChiwon Song
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programmingChiwon Song
 
20171104 FRP 패러다임
20171104 FRP 패러다임20171104 FRP 패러다임
20171104 FRP 패러다임Chiwon Song
 
스크래치로 시작하는 코딩
스크래치로 시작하는 코딩스크래치로 시작하는 코딩
스크래치로 시작하는 코딩Chiwon Song
 
메이커운동과 아두이노
메이커운동과 아두이노메이커운동과 아두이노
메이커운동과 아두이노Chiwon Song
 
아두이노 RC카 만들기
아두이노 RC카 만들기아두이노 RC카 만들기
아두이노 RC카 만들기Chiwon Song
 
[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoTChiwon Song
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷Chiwon Song
 

More from Chiwon Song (20)

20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
 
20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP
 
20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계
 
20200815 inversions
20200815 inversions20200815 inversions
20200815 inversions
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안
 
[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행
 
20190330 immutable data
20190330 immutable data20190330 immutable data
20190330 immutable data
 
20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
 
20171104 FRP 패러다임
20171104 FRP 패러다임20171104 FRP 패러다임
20171104 FRP 패러다임
 
스크래치로 시작하는 코딩
스크래치로 시작하는 코딩스크래치로 시작하는 코딩
스크래치로 시작하는 코딩
 
메이커운동과 아두이노
메이커운동과 아두이노메이커운동과 아두이노
메이커운동과 아두이노
 
아두이노 RC카 만들기
아두이노 RC카 만들기아두이노 RC카 만들기
아두이노 RC카 만들기
 
[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 

Recently uploaded

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

[3] 프로세싱과 아두이노

  • 2. https://processing.org/ Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts.
  • 3.
  • 4.
  • 8. Draw Frames void setup() { size(640, 480); //W, H } int r_x = 0; int add = 5; int e_x = 20, e_y = 20; int e_add_x = 3, e_add_y = 3; void draw() { background(200, 200, 200); //R, G, B noStroke(); fill(255, 0, 0); //R, G, B rect(r_x, 400, 100, 30); //X, Y, W, H stroke(0, 0, 0); fill(0, 255, 0); ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY e_x += e_add_x; e_y += e_add_y; if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x; if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y; if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30) e_add_y = -e_add_y; r_x += add; if(r_x < 0 || r_x > 640-100) add = -add; } 실행결과
  • 9. sample int count = 200; int snowx[]= new int[count]; int snowy[]= new int[count]; int speed[]= new int[count]; int size[]= new int[count]; void setup() { size(320, 200); for(int i=0; i<count; i++) { snowx[i] = (int)random(0, 320); snowy[i] = (int)random(0, 200); speed[i] = (int)random(1, 4); size[i] = (int)random(1, 5); } } void draw() { background(0); for(int i=0; i<count; i++) { ellipse(snowx[i], snowy[i], size[i], size[i]); snowy[i]+=speed[i]; if(snowy[i] >= 200) { snowy[i] = 0; snowx[i] = (int)random(0, 320); speed[i] = (int)random(1, 4); size[i] = (int)random(1, 5); } } } 실행결과
  • 11. Mouse Event void setup() { } void draw() { if(mousePressed) { println("mouse pressed"); } } void setup() { } void draw() { } void mousePressed() { println("mouse pressed"); } void setup() { } void draw() { } void mousePressed() { if(mouseButton == LEFT) { println("Left mouse button pressed"); } else if(mouseButton == CENTER) { println("Center mouse button pressed"); } else if(mouseButton == RIGHT) { println("Right mouse button pressed"); } } Mouse Button Pressed Pressed Mouse Button
  • 12. Mouse Event void setup() { } void draw() { } void mousePressed() { if(mouseButton == LEFT) { println("Left mouse button pressed"); } else if(mouseButton == CENTER) { println("Center mouse button pressed"); } else if(mouseButton == RIGHT) { println("Right mouse button pressed"); } } void mouseReleased() { if(mouseButton == LEFT) { println("Left mouse button released"); } } void mouseClicked() { if(mouseButton == LEFT) { println("Left mouse button clicked"); } } void mouseDragged() { println("Drag MouseX:"+mouseX+" , MouseY:"+mouseY); } void mouseWheel(processing.event.MouseEvent event) { int e = event.getCount(); println("Wheel:"+e); } void mouseMoved() { println("Move MouseX:"+mouseX+" , MouseY:"+mouseY); }
  • 13. sample class LineElement { int x, y, x2, y2; } ArrayList<LineElement> lines = new ArrayList<LineElement>(); int p_x = -1, p_y = -1; void setup() { size(320, 200); stroke(255); strokeWeight(2); } void draw() { background(0); stroke(255); for(LineElement l : lines) { line(l.x, l.y, l.x2, l.y2); } stroke(0, 0, 255); if(p_x >= 0 && p_y >= 0) { line(p_x, p_y, mouseX, mouseY); } } void mousePressed() { if(p_x >= 0 && p_y >= 0) { LineElement l = new LineElement(); l.x = p_x; l.y = p_y; l.x2 = mouseX; l.y2 = mouseY; lines.add(l); } p_x = mouseX; p_y = mouseY; }
  • 14. Keyboard Event void setup() { } void draw() { if (keyPressed) { if (key == 'b' || key == 'B') { background(0); } else { background(255); } } } int value = 0; void draw() { background(value); } void keyPressed() { if (key == 'b' || key == 'B') { value = 0; } else { value = 255; } } void draw() { } void keyPressed() { println("pressed " + key + "(" + keyCode + ")"); } void keyReleased() { println("released " + key + "(" + keyCode + ")"); } void keyTyped() { println("typed " + key + "(" + keyCode + ")"); } Key Pressed Pressed Mouse Button pressed a(65) typed a(0) released a(65)
  • 15. sample void setup() { size(640, 480); //W, H } int r_x = 0; int e_x = 20, e_y = 20; int e_add_x = 3, e_add_y = 3; void draw() { background(200, 200, 200); //R, G, B noStroke(); fill(255, 0, 0); //R, G, B rect(r_x, 400, 100, 30); //X, Y, W, H stroke(0, 0, 0); fill(0, 255, 0); ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY e_x += e_add_x; e_y += e_add_y; if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x; if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y; if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30) e_add_y = -e_add_y; } void keyPressed() { if(keyCode == LEFT) { r_x -= 10; if(r_x < 0) r_x = 0; } else if(keyCode == RIGHT) { r_x += 10; if(r_x > 640-100) r_x = 640-100; } }
  • 16. Serial 통신 Arduino 와 PC를 연결하는 방법 Serial.begin(9600); Serial.print(“command”); Serial.read() serial = new Serial(); serial.readChar(); serial.writeChar();
  • 17. Arduino Side void setup() { pinMode(8, OUTPUT); Serial.begin(9600); } void loop() { if (Serial.available() > 0) { char ch = Serial.read(); if(ch == '1') digitalWrite(8, HIGH); else digitalWrite(8, LOW); } } Serial Monitor
  • 18. Processing Side import processing.serial.*; Serial serial; int pMouseX = 0; void setup() { size(320, 200); serial = new Serial(this, Serial.list()[0], 9600); } void draw() { fill(0); rect(0, 0, 160, 200); fill(255); rect(160, 0, 160, 200); if(pMouseX < 160 && mouseX >= 160) { serial.write('1'); } else if(pMouseX >= 160 && mouseX < 160) { serial.write('0'); } pMouseX = mouseX; }
  • 19. Arduino Side int pButtonState = 0; void setup() { pinMode(8, INPUT); Serial.begin(9600); } void loop() { int buttonPressed = digitalRead(8); if(pButtonState == LOW && buttonPressed == HIGH) { Serial.print('1'); } pButtonState = buttonPressed; } Serial Monitor
  • 20. Processing Side import processing.serial.*; Serial serial; void setup() { size(320, 200); serial = new Serial(this, Serial.list()[0], 9600); background(0); } void draw() { if(serial.available() > 0) { int ch = serial.read(); if(ch == '1') { int red = (int)random(255); int green = (int)random(255); int blue = (int)random(255); int x = (int)random(320); int y = (int)random(200); int size = (int)random(30, 100); fill(red, green, blue, 180); ellipse(x, y, size, size); } } }
  • 21. sample Arduino Side void setup() { Serial.begin(9600); } void loop() { int value = analogRead(A1); Serial.println(value); delay(100); }
  • 22. sample Processing Side void draw() { background(200, 200, 200); //R, G, B noStroke(); fill(255, 0, 0); //R, G, B rect(r_x, 400, 100, 30); //X, Y, W, H stroke(0, 0, 0); fill(0, 255, 0); ellipse(e_x, e_y, 20, 20); // X, Y, RX, RY if(serial.available() > 0) { String val = serial.readStringUntil(lf); if(val != null) { val = val.trim(); if(val.length() > 0) { int val2 = Integer.parseInt(val.trim()); r_x = val2 * (640-100) / 1024; } } } e_x += e_add_x; e_y += e_add_y; if(e_x < 10 || e_x > 640-10) e_add_x = -e_add_x; if(e_y < 10 || e_y > 480-10) e_add_y = -e_add_y; if(e_x > r_x && e_x < r_x+100 && e_y > 400 && e_y < 400+30) e_add_y = -e_add_y; } import processing.serial.*; int lf = 10; Serial serial; int r_x = 0; int e_x = 20, e_y = 20; int e_add_x = 3, e_add_y = 3; void setup() { size(640, 480); serial = new Serial(this, Serial.list()[0], 9600); }
  • 23. sample Arduino Side int pinTrig = 7; int pinEcho = 6; void setup() { Serial.begin(9600); pinMode(pinTrig, OUTPUT); pinMode(pinEcho, INPUT); } void loop() { int value = distance(); Serial.println(value); delay(300); } long distance() { digitalWrite(pinTrig, LOW); delayMicroseconds(2); digitalWrite(pinTrig, HIGH); delayMicroseconds(10); digitalWrite(pinTrig, LOW); long val= pulseIn(pinEcho, HIGH) * 17 / 100; return val; }
  • 24. sample Processing Side import processing.serial.*; int lf = 10; float zoom = 0.1; Serial serial; PImage img; void setup() { size(800, 600); img = loadImage("image.jpg"); serial = new Serial(this, Serial.list()[1], 9600); } void draw() { background(0); if(serial.available() > 0) { String val = serial.readStringUntil(lf); if(val != null) { val = val.trim(); if(val.length() > 0) { float val2 = Float.parseFloat(val.trim()); zoom = max(min(val2 / 100, 1.0), 0.1); } } } float imageWidth = img.width * zoom; float imageHeight = img.height * zoom; image(img, (800 - imageWidth)/2, (600 - imageHeight)/2, imageWidth, imageHeight); } image.jpg

Editor's Notes

  1. Processing 2001년부터 당시 MIT 미디어 랩에서 개발 비개발자들을 위한 프로그래밍 교육용 쉽고 간결한 문법 JVM 위에서 동작 시각적이고 인터렉션 작업에 특화
  2. Processing IDE 간결하고 쉬운 사용법 Setup() , draw() 로 구성된 구조 Arduino IDE 개발에 영향을 미침 Java 문법을 차용하고 있음
  3. Processing 설치 공식 사이트 : https://processing.org 왼쪽 메뉴에서 Download 선택 플랫폼에 맞는 인스톨러 선택
  4. 프로그램 구조 setup() 첫 실행 시 한 번 호출 됨 draw() 매 프레임마다 호출됨 print() 콘솔 로그 출력 println() 콘솔 로그 출력(new line)
  5. Size 실행창의 크기를 지정 fullScreen 전체화면으로 실행 size와 함께 호출하면 안됨 background 배경색상을 지정(화면이 지워짐) fill 내부 칠하는 색상을 지정 rect 사각형을 그림
  6. 변수 값 사용 rect(x, 100, 200, 200); // 변수값을 사용해서 위치 지정 draw() 매 프레임마다 호출됨 x += add; //  프레임마다 변수값이 계산 상자가 창의 양 끝에 닿을 때 방향 전환 : add = -add;
  7. eclipse(x, y, rx, ry) 원 그리기, 중심(x,y), 가로크기(rx), 세로크기(ry) 공그리기 위치 이동 : e_x, e_y 이동 방향 : e_add_x, e_add_y 바 그리기 위치 이동 : r_x 이동 방향 : add
  8. Class 를 사용한 방법 class Snow { int x, y, speed, size; Snow() { x = (int)random(0, 320); y = 0; speed = (int)random(1, 4); size = (int)random(1, 5); } } Snow[] snow = new Snow[200]; void setup() { size(320, 200); for(int i=0; i<snow.length; i++) { snow[i] = new Snow(); snow[i].y = (int)random(0, 200); } } void draw() { background(0); for(int i=0; i<snow.length; i++) { Snow s = snow[i]; ellipse(s.x, s.y, s.size, s.speed); s.y += s.speed; if(s.y >= 200) { snow[i] = new Snow(); } } }
  9. Reference https://processing.org/reference/
  10. 마우스 이벤트를 처리하는 방법 mousePressed 값 확인 mousePressed() 함수 콜백 mouseButton 값 확인 (버튼 상태)
  11. API Reference http://processing.github.io/processing-javadocs/core/ 마우스 이벤트 패키지 processing.event.MouseEvent 마우스 이벤트 종류 mousePressed() mouseReleased() mouseDragged() mouseWheel() mouseMoved()
  12. Mouse move 감지 Mouse Press 시 이전 점부터 현재 점 까지 라인(LineElement) 생성 생성된 LineElement 를 배열(ArrayList) 에 추가 매 프레임 마다 (1) 화면 지우기 : background(0) (2) 라인 히스토리 그리기 : for(LineElement l : lines)
  13. 키보드 이벤트 처리하는 방법 keyPressed 값 사용 keyPressed() 함수 콜백 keyCode 값 사용 키보드 이벤트 종류 keyPressed() keyReleased() keyTypes()
  14. 공그리기 위치 이동 : e_x, e_y 이동 방향 : e_add_x, e_add_y 바 그리기 위치 이동 : r_x 이동 방향 : 키이벤트에 의해서 처리
  15. Aruino 는 Serial 통신을 수행 Serial 을 통해서 Arduino 와 통신함 Serial 통신이 가능한 모든 언어에서 사용 가능 C/C++ Java Python Javascript (Node.js) … Processing 에서는 쉽게 Serial 통신을 수행할 수 있는 기능 제공
  16. 아두이노 제어하기 예제 Arduino 측 Serial 통신 Serial 연결 Serial.println : 시리얼 출력 Serial.read : 시리얼 입력 Serial.available : 입력이 있는지 확인 시리얼 모니터 창에서 “전송” 시 Serial 로 전달 됨 시리얼을 통해 ‘1’ 입력 시 LED 켜기, 그 외 LED 끄기
  17. 아두이노 제어하기 예제 Processing 측 Serial 통신 Serial 클래스 사용 Serial.list() 로 시리얼 포트에 연결된 목록 확인 Serial 목록 중에서 Arduino 가 연결된 항목을 선택해서 연결 Serial.write 로 시리얼로 데이터 전달
  18. 아두이노로 제어하기 예제 Arduino 측 Serial 통신 Serial 연결 Serial.println : 시리얼 출력 시리얼 모니터 창에서 전송되는 내용 확인 가능 버튼이 눌리면 시리얼을 통해 ‘1’ 전달
  19. 아두이노로 제어하기 예제 Processing 측 Serial 통신 Serial.read : 시리얼로 데이터 읽기 Serial.available : 시리얼 데이터가 있는지 확인 ‘1’이 전달되면 (아두이노에서 버튼이 눌리면) 랜덤하게 원 출력
  20. 아두이노와 PC 연동 예제 (아두이노 측) 가변저항을 아두이노에 연결 analogRead 로 저항값 읽기 (0 ~ 1023 사이의 값) 저항값을 시리얼로 전달함
  21. 아두이노와 PC 연동 예제 (PC 측) Serial.read 로 전달 값 읽기 Serial 값으로 Bar 의 위치를 지정
  22. 아두이노와 PC 연동 예제 (아두이노 측) 초음파 센서를 아두이노에 연결 초음파 센서로 물체 거리 연산 거리값을 시리얼을 통해 PC 로 전달
  23. 아두이노와 PC 연동 예제 (PC 측) Pimage 클래스를 통해 이미지 읽기 image.jpg 파일은 프로세싱 소스 파일과 같은 경로에 있어야 함 Image 함수로 이미지 그리기 image(이미지 객체, x좌표, y좌표, 이미지 가로 크기, 이미지 세로 크기) 시리얼을 통해서 얻은 거리값으로 그려낼 이미지 크기 계산 (zoom) min(A, B) : A, B 값 중 작은 값을 반환함 max(A, B) : A, B 값 중 큰 값을 반환함 max( min( ZOOM , 1.0 ) , 0.1 ) : ZOOM 값이 최소 0.1 ~ 최대 1.0 값으로 필터링 함
  24. 아두이노와 PC 연결 활용 사례 가속도센서로 핸들 신호 감지 빛 센서로 발바닥 움직임 감지 센서 정보를 PC 로 전달 PC 에서 신호에 따라 정해진 효과음 재생 Processing 에서 소리 재생 import processing.sound.*; SoundFile file; file = new SoundFile(this, "sample.mp3"); file.play();