Processingってすごくないか?@92日目

reacTIVisionの関係でProcessingを再び触ってみたが,白沼に,もとい,知らぬ間に正式版がリリースされているではないか!

久しぶりに触ってみたが,Processingの凄さを改めて感じた.

ActionScriptに比べると貧相な印象しか持っていなかったが,非常に洗練されたパワフルな言語であると感じた.ここからはテクニカルな話になります.

例えば,モジュールについてのサンプルだが,

[java]
/**
* Array Objects.
*
* Demonstrates the syntax for creating an array of custom objects.
*/

int unit = 40;
int num;
Module[] mods;

void setup()
{
size(200, 200);
background(176);
noStroke();

num = width/unit * width/unit;
mods = new Module[num];

for (int i=0; i<height/unit; i++) {
for(int j=0; j<height/unit; j++) {
int index = i*height/unit + j;
mods[index] = new Module(j*unit, i*unit, unit/2, unit/2, random(0.05, 0.8));
}
}
}

void draw()
{
for(int i=0; i<num; i++) {
mods[i].update();
mods[i].draw();
}
}

class Module {
float mx, my;
int size = unit;
float x, y = 0;
int xdir = 1;
int ydir = 1;
float speed;

// Contructor (required)
Module(float imx, float imy, float ix, float iy, float ispeed) {
mx = imy;
my = imx;
x = int(ix);
y = int(iy);
speed = ispeed;
}

// Custom method for updating the variables
void update() {
x = x + (speed * xdir);
if (x >= size || x <= 0) {
xdir *= -1;
x = x + (1 * xdir);
y = y + (1 * ydir);
}
if (y >= size || y <= 0) {
ydir *= -1;
y = y + (1 * ydir);
}
}

// Custom method for drawing the object
void draw() {
stroke(second()*4);
point(mx+x-1, my+y-1);
}
}

[/java]
と書くだけである.一つのファイルで全部書かれているがもちろんライブラリファイルのように分割することもできる.

そして何よりも,ちょっと書くだけで,何らかの画像を描画できるという敷居の低さが素晴らしい.

もしもActionScriptで何か描画しようと思ったら,かなりの事を学習して,それから初めて画像を描画することができる.しかしProcessingはその「何かが出来る」というところまでの敷居が低い.これは授業などで導入するプログラミング言語として最適なのではないだろうか.

参考リンクを紹介するので,興味のある方はDLして試してみるとよいだろう.

Follow me!

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA