SlideShare a Scribd company logo
ProcessingWorkshop
Processing
電子アートとビジュアルデザインのための
プログラミング言語であり、統合開発環境
である。視覚的なフィードバックが即座に
得られるため、初心者がプログラミングを
学習するのに適しており、電子スケッチ
ブックの基盤としても利用できる。Java
を単純化し、グラフィック機能に特化した
言語といえる。(Wikipedia より抜粋)
ProcessingWorkshop
Run
プログラムを実行
Stop
実行中のプログラムを停止
Editor
プログラムを記述するところ
Console
エラーがあるとここに表示される
Setup
Run
初期化設定を書くところ。Run を押した瞬間に一度だけ呼ばれる。
Draw
描画処理を書くところ。デフォルトだと一秒間に 60 回同じ処理が
繰り返される。
ProcessingWorkshop
void setup()
{
}
void draw()
{
}
Stop
ProcessingWorkshop
Coordinate - Axis
x( 0, 0 )
y
Math
x( 0, 0 )
y
Program
数学とプログラムでは y 軸の向きが逆なので注意!
ProcessingWorkshop
Coordinate - Example
x
10030
y
100
50
70
80
line( 30, 50, 70, 80 );
( x 30, y 50 ) から ( x 70, y 80 ) に線を引く
ProcessingWorkshop
Primitives - Line
line( x1, y1, x2, y2 );
Point1 Point2
Point1( x,1 y1 ) と Point2( x,2 y2 ) を結ぶ直線を引く
ProcessingWorkshop
Primitives - Line
//---------------------------------------- setup
void setup()
{
// set window size
size( 100, 100 );
}
//---------------------------------------- draw
void draw()
{
// draw line
line( 30, 50, 70, 80 );
}
ProcessingWorkshop
Primitives - Rect
rect( x, y, width, height );
Point
Point( x, y ) を左上とした、幅 width、高さ height の矩形を描く
rectMode( CENTER ) で Point( x, y ) を中心として描画する
ProcessingWorkshop
Primitives - Rect
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// draw rect
rect( 100, 100, 50, 50 );
// set rect mode CENTER
rectMode( CENTER );
// draw rect
rect( 100, 100, 50, 50 );
}
ProcessingWorkshop
Primitives - Ellipse
ellipse( x, y, width, height );
Point
Point( x, y ) を中心とした、幅 width、高さ height の楕円を描く
正円を描く場合は、width と height に同じ数値を入れる
ProcessingWorkshop
Primitives - Ellipse
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// draw circle
ellipse( 100, 100, 50, 50 );
// draw ellipse
ellipse( 100, 100, 100, 10 );
}
ProcessingWorkshop
Primitives - Triangle
Point1( x1, y1 ), Point2( x2, y2 ), Point3( x3, y3 ) を結ぶ三角形を描く
triangle( x1, y1, x2, y2, x3, y3 );
Point1 Point2 Point3
ProcessingWorkshop
Primitives - Triangle
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// draw top triangle
triangle( 0, 0, 200, 0, 100, 100 );
// draw bottom triangle
triangle( 0, 200, 200, 200, 100, 100 );
}
ProcessingWorkshop
Color - Background
background( red, green, blue );
background( gray );
( red, green, blue ) または ( gray )、それぞれ 0 から 255 までの数値で背景色を指定
ProcessingWorkshop
Color - Background
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 128, 0, 0 );
}
ProcessingWorkshop
Color - Stroke
stroke( red, green, blue );
stroke( gray );
noStroke();
( red, green, blue ) または ( gray )、それぞれ 0 から 255 までの数値で線色を指定
noStroke() で線なし
指定しない場合は黒になる
ProcessingWorkshop
Color - Stroke
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 128, 0, 0 );
// set stroke color
stroke( 255, 255, 0 );
// draw bottom circle
ellipse( 100, 130, 100, 100 );
// disable stroke
noStroke();
// draw top circle
ellipse( 100, 70, 70, 70 );
}
ProcessingWorkshop
Color - Fill
fill( red, green, blue );
fill( gray );
noFill();
( red, green, blue ) または ( gray )、それぞれ 0 から 255 までの数値で塗りつぶし色を指定
noFill() で塗りつぶしなし
指定しない場合は白になる
ProcessingWorkshop
Color - Fill
//---------------------------------------- setup
void setup()
{
// set window size
size( 200, 200 );
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 255, 200, 200 );
// set fill color
fill( 255, 255, 128 );
// draw bottom circle
ellipse( 100, 130, 100, 100 );
// disable fill
noFill();
// draw top circle
ellipse( 100, 70, 70, 70 );
}
ProcessingWorkshop
Drawing
//---------------------------------------- setup
void setup()
{
// set window size
size( 640, 440 );
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 192, 128, 64 );
// no stroke
noStroke();
// set fill color
fill( 0 );
// left eye
ellipse( ( 320 - 150 ), 170, 80, 80 );
// right eye
ellipse( ( 320 + 150 ), 170, 80, 80 );
// mouth
triangle( 320, 280, ( 320 - 80 ), ( 280 + 70 ), ( 320 + 80 ), ( 280 + 70 ) );
}
ProcessingWorkshop
Variables
変数
数値を入れておく箱のようなもの。
変数にはそれぞれ種類があり、それを「型」
という。
値を保存しておきたい場合や、同じ値を何
度も使用する場合、計算をする場合に使う。
変数を使う前には、使いたい変数の型と名
前を宣言する必要がある。
int 型: 整数
float 型: 小数(浮動小数点数) int 型 float 型
5 255
1024
127
68 94
16
5.99
255.1 127.0
68.34
94.21
16.08
//---------------------------------------- global
// declare variables
int x;
int y;
int diameter;
//---------------------------------------- setup
void setup()
{
// set window size
size( 640, 480 );
// assign values to variables
x = 320;
y = 240;
diameter = 200;
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 255 );
// disable stroke
noStroke();
// set fill color
fill( 255, 0, 0 );
// draw ellipse with variables
ellipse( x, y, diameter, diameter );
}
ProcessingWorkshop
Variables - Declaration
//---------------------------------------- global
// declare variables
int x;
int y;
int diameter;
//---------------------------------------- setup
void setup()
{
// set window size
size( 640, 480 );
// assign values to variables
x = 320;
y = 240;
diameter = 200;
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 255 );
// disable stroke
noStroke();
// set fill color
fill( 255, 0, 0 );
// draw ellipse with variables
ellipse( x, y, diameter, diameter );
// update x
x = x + 1;
}
ProcessingWorkshop
Variables - Animation
ProcessingWorkshop
Conditional
i f 文
特定の条件下だけ通常とは違う処理をさせ
たいときに使う。
if( 条件 )
{
// ここに処理を描く
}
関係演算子
// a が b と等しいとき
if( a == b )
{
// ここに処理
}
// a が b と等しくないとき
if( a != b )
{
// ここに処理
}
// a が b より小さいとき
if( a < b )
{
// ここに処理
}
// a が b 以下のとき
if( a <= b )
{
// ここに処理
}
// a が b より大きいとき
if( a > b )
{
// ここに処理
}
// a が b 以上のとき
if( a >= b )
{
// ここに処理
}
//---------------------------------------- global
// declare variables
int x;
int y;
int diameter;
//---------------------------------------- setup
void setup()
{
// set window size
size( 640, 480 );
// assign values to variables
x = 0;
y = 240;
diameter = 200;
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 255 );
// disable stroke
noStroke();
// set fill color
fill( 255, 0, 0 );
// draw ellipse with variables
ellipse( x, y, diameter, diameter );
// update x
x = x + 1;
// reset x when x is over window width
if( x > width )
{
x = 0;
}
}
ProcessingWorkshop
Conditional - Animation
//---------------------------------------- global
// declare variables
int x;
int y;
int diameter;
//---------------------------------------- setup
void setup()
{
// set window size
size( 640, 480 );
// assign values to variables
diameter = 200;
x = -( diameter / 2 );
y = 240;
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 255 );
// disable stroke
noStroke();
// set fill color
fill( 255, 0, 0 );
// draw ellipse with variables
ellipse( x, y, diameter, diameter );
// update x
x = x + 1;
// reset x when x is over window width
if( ( x - ( diameter / 2 ) ) > width )
{
x = -( diameter / 2 );
}
}
ProcessingWorkshop
Conditional - NaturalAnimation
ProcessingWorkshop
SerialCommunication
ProcessingWorkshop
SerialCommunication //---------------------------------------- import
// import serial library
import processing.serial.*;
//---------------------------------------- global
// serial object
Serial serial;
int val = 0;
//---------------------------------------- setup
void setup()
{
// set window size
size( 480, 480 );
// listup serial devices to console
println( Serial.list() );
// setup serial
serial = new Serial( this, serial.list()[ 5 ], 9600 );
// clear serial
serial.clear();
// buffer serial until 'n'
serial.bufferUntil( 'n' );
}
//---------------------------------------- draw
void draw()
{
// fill background
background( 0 );
}
//------------------------------------------------------------ serialEvent
void serialEvent( Serial _serial )
{
// read string until 'n' from serial buffer
String str = _serial.readStringUntil( 'n' );
// if str is not null
if( str != null )
{
// trim str
str = trim( str );
// convert string to int
val = int( str );
// print value to console
println( val );
}
}
ProcessingWorkshop
SerialCommunication
//---------------------------------------- import
// import serial library
import processing.serial.*;
//---------------------------------------- global
// serial object
Serial serial;
int val = 0;
float angle = 0.0;
float centerX, centerY;
//---------------------------------------- setup
void setup()
{
// set window size
size( 480, 480 );
// fill background
background( 0 );
centerX = width / 2;
centerY = height / 2;
// listup serial devices to console
println( Serial.list() );
// setup serial
serial = new Serial( this, serial.list()[ 5 ], 9600 );
// clear serial
serial.clear();
// buffer serial until 'n'
serial.bufferUntil( 'n' );
}
//---------------------------------------- draw
void draw()
{
// disable stroke
noStroke();
// fill background slowly
fill( 0, 2 );
rect( 0, 0, width, height );
// set stroke color
stroke( 0, 255, 0 );
// update angle
++angle;
float radius = val / 4;
float x = centerX + ( cos( radians( angle ) ) * radius );
float y = centerY + ( sin( radians( angle ) ) * radius );
// draw line
line( centerX, centerY, x, y );
}
// serialEvent は変更しないので割愛

More Related Content

PDF
Processing workshop v3.0
PDF
enchant.jsでゲーム制作をはじめてみよう
PDF
enchant.jsでゲーム制作をはじめてみよう 「パンダの会」バージョン
PPT
C++でHello worldを書いてみた
PDF
SystemC Tutorial
PDF
Halide による画像処理プログラミング入門
PDF
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Processing workshop v3.0
enchant.jsでゲーム制作をはじめてみよう
enchant.jsでゲーム制作をはじめてみよう 「パンダの会」バージョン
C++でHello worldを書いてみた
SystemC Tutorial
Halide による画像処理プログラミング入門
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目

What's hot (9)

PDF
Glfw3,OpenGL,GUI
PDF
Siv3Dで楽しむゲームとメディアアート開発
PPTX
Play2 scalaを2年やって学んだこと
PDF
C++0x in programming competition
KEY
Stroustrup11章雑感
PDF
VerilatorとSystemC
PPTX
そうだ 検証、しよう。
PDF
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
PDF
Continuation with Boost.Context
Glfw3,OpenGL,GUI
Siv3Dで楽しむゲームとメディアアート開発
Play2 scalaを2年やって学んだこと
C++0x in programming competition
Stroustrup11章雑感
VerilatorとSystemC
そうだ 検証、しよう。
Intel AVX-512/富岳SVE用SIMDコード生成ライブラリsimdgen
Continuation with Boost.Context
Ad

Similar to Processing workshop (20)

PDF
PWAnight_20221019_クリエイティブコーディングとは?
PDF
Openstack+Ceph設定ガイド
PDF
社内勉強会資料(Varnish Module)
PDF
riscv instruction sets lets-impl-rv32i.pdf
PDF
Hbstudy41 auto scaling
PDF
about DakotagUI
PDF
C base design methodology with s dx and xilinx ml
PDF
x86とコンテキストスイッチ
PDF
coma Study Room vol.2 Arduino Workshop
PDF
about dakota6.7 gui
PDF
Zynq VIPを利用したテストベンチ
PDF
Synthesijer and Synthesijer.Scala in HLS-friends 201512
PPTX
ぱっと見でわかるC++11
KEY
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
PDF
Arduino入門
PDF
ネコでもわかるインタラクティブサウンド20130706
PDF
これからのJavaScriptの話
PDF
【学習メモ#1st】12ステップで作る組込みOS自作入門
PDF
PF部2011年12月勉強会.androidsola
PDF
CMSI計算科学技術特論B(14) OpenACC・CUDAによるGPUコンピューティング
PWAnight_20221019_クリエイティブコーディングとは?
Openstack+Ceph設定ガイド
社内勉強会資料(Varnish Module)
riscv instruction sets lets-impl-rv32i.pdf
Hbstudy41 auto scaling
about DakotagUI
C base design methodology with s dx and xilinx ml
x86とコンテキストスイッチ
coma Study Room vol.2 Arduino Workshop
about dakota6.7 gui
Zynq VIPを利用したテストベンチ
Synthesijer and Synthesijer.Scala in HLS-friends 201512
ぱっと見でわかるC++11
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
Arduino入門
ネコでもわかるインタラクティブサウンド20130706
これからのJavaScriptの話
【学習メモ#1st】12ステップで作る組込みOS自作入門
PF部2011年12月勉強会.androidsola
CMSI計算科学技術特論B(14) OpenACC・CUDAによるGPUコンピューティング
Ad

Recently uploaded (10)

PDF
5_「AIと仲良くなるには?」日本大学東北高等学校南梨夢乃さんinspirehigh.pdf
PDF
7_「なぜ人は他人と違うところがあってもそれをなかなか誇れないのか?」明治大学付属中野八王子中学校宮本ゆりかさん.pdf
PDF
3_「本当の『悪者』って何?」鷗友学園女子中学校_福島 雪乃さんinspirehigh.pdf
PDF
外国人が日本のテーブルマナーに驚く理由は?_公文国際学園高等部 角田 恵梨佳さん
PDF
9_前田音葉さん:「Yakushima Islandってなんか変じゃない?」.pdf
PPT
日本語test日本語test日本語test日本語test日本語test日本語test.ppt
PDF
8_「世の中の流行はどのようにして生まれるのか」学校法人聖ドミニコ学園竹野はるいpptx.pdf
PDF
My Inspire High Award 2024(岡田秀幸).pptx.pdf
PDF
「なぜ、好きなことにいつかは飽きるの?」大塚莉子 - My Inspire High Award 2024.pdf
PDF
6_「老いることは不幸なこと?」植草学園大学附属高等学校森 珠貴さんinspirehigh.pdf
5_「AIと仲良くなるには?」日本大学東北高等学校南梨夢乃さんinspirehigh.pdf
7_「なぜ人は他人と違うところがあってもそれをなかなか誇れないのか?」明治大学付属中野八王子中学校宮本ゆりかさん.pdf
3_「本当の『悪者』って何?」鷗友学園女子中学校_福島 雪乃さんinspirehigh.pdf
外国人が日本のテーブルマナーに驚く理由は?_公文国際学園高等部 角田 恵梨佳さん
9_前田音葉さん:「Yakushima Islandってなんか変じゃない?」.pdf
日本語test日本語test日本語test日本語test日本語test日本語test.ppt
8_「世の中の流行はどのようにして生まれるのか」学校法人聖ドミニコ学園竹野はるいpptx.pdf
My Inspire High Award 2024(岡田秀幸).pptx.pdf
「なぜ、好きなことにいつかは飽きるの?」大塚莉子 - My Inspire High Award 2024.pdf
6_「老いることは不幸なこと?」植草学園大学附属高等学校森 珠貴さんinspirehigh.pdf

Processing workshop