Processing=005=3d&library

Page 1

Processing

05 3D & Library 3D 以及 Library


3D


void setup(){ size(500,500,P3D); smooth(); } void draw(){ background(0); ellipse(250,250,100,100); }


Where is the Camera 鏡頭呢?不會動?


Go to File/ Example


You can open it and see what’s in the code

可以看看 他們有甚麼



There is a LIBRARY, Easy way 還好有個 Library 簡單好用


http://processing.org/reference/libraries/


Click on it


http://mrfeinberg.com/peasycam/

Find the Download


FOR

WIND OWS 微軟使用者


Unzip the file 解壓縮


There is a “peasycam” under the “PeasyCam_200 ” Copy it !!!

裡面會有個peasyCam 資料夾 複製它


If you are Windows Users, 如果你是微軟用戶

Find the “Modes” folder And find the “java” folder And find the “libraries” folder And Paste the “peasy” folder under it


Something like this 像這樣


FOR

MAC 蘋果使用者


Unzip the file 解壓縮


There is a “peasycam” under the “PeasyCam_200 ” Copy it !!!

裡面會有個peasyCam 資料夾 複製它


1.

2.

3.

4.


5.

6. If you are Mac Users, Find the “Processing.app/ Content/ Resource/ Java/ Modes/ jave/ libraries

7.

And Paste the “peasy” folder under it


Something like this


ALL the

ALL the Users

全 體 通 通 有

Close and Reopen

Your Proce ssing

重 新 啟 動


Now we can go back to the CODE


How to import the LABRARIES 如何輸入library




import peasy.*; PeasyCam gcam; // you can name any name instead of “gcam” //你可以任意取名

void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); // telling that the gcam is a new object of PeasyCam //告訴程式 我創建了一個叫gcam的PeasyCam物件 } void draw(){ background(0); ellipse(250,250,100,100); }



Primitives 3D 基本量體


box(size); box(x,y,z);


import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); }

void draw(){ background(0); box(50); }



import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); }

void draw(){ background(0); box(50); }



import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); }

void draw(){ background(255,255,0); stroke(255); fill(40,80,200); box(50,80,100);//box(x,y,z); }


IKEA


sphere(size);


import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); }

void draw(){ background(0); stroke(255); fill(40,80,200); sphere(80) }


IKEA


import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); }

void draw(){ background(0); stroke(255); fill(40,80,200); sphere(80) }


We would like to make a sin_Wave 想要做一個sin的 波浪


Translate(); 移動


translate() will move the whole coordination of the origin point translate() 會移動整個 原點的座標 位置

Translate(20,20,0) point(0,0,0);

(0,0,0) old origin

(20,20,0)


(0,0,0)

new origin (-20,-20,0) Translate(-10,-40,0) point(0,0,0);

(-10,-40,0)


(10,40,0)

(-10,20,0)

(0,0,0) new origin


import peasy.*; PeasyCam gCam; void setup(){ size(800,800,P3D); gCam = new PeasyCam(this,500); } void draw(){ background(0); box(50); translate(100,100); box(50); translate(100,100); box(50); }


Gap distance Become Longer and longer 間距 越來越長


pushMatrix(); popMatrix(); To avoid the situation 避免掉此問題


pushMatrix(); Translate(20,20,0) point(0,0,0); popMatirx(); (0,0,0) origin

(20,20,0)


pushMatrix(); Translate(20,20,0) point(0,0,0); popMatirx(); (0,0,0) new origin

(20,20,0)


import peasy.*; PeasyCam gCam; void setup(){ size(800,800,P3D); gCam = new PeasyCam(this,500); } void draw(){ background(0); box(50); pushMatrix(); translate(100,100, 0); box(50); popMatrix(); pushMatrix(); translate(100,100, 0); box(50); popMatrix();



import peasy.*; PeasyCam gCam; void setup(){ size(800,800,P3D); gCam = new PeasyCam(this,500); } void draw(){ background(0); box(50); pushMatrix(); translate(100,100, 0); box(50); popMatrix(); pushMatrix(); translate(-100,100, 0); box(50); popMatrix(); }



box(size); + For_Loop


import peasy.*; PeasyCam gCam; void setup(){ size(800,800,P3D); gCam = new PeasyCam(this,500); } void draw(){ background(0); for(int i =0; i< 500; i=i+50){ pushMatrix(); translate( i, 100, 0); box(50); popMatrix(); } }



( i, sin(i) )


PI (π) = 180° 1° = PI / 180


import peasy.*;

PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); } void draw(){ background(255,255,0); noStroke(); fill(40,80,200); for(float i=0; i<1800; i+=15){ pushMatrix(); translate( i, 50*sin(i*(PI/180)), 0); box(15); popMatrix(); } }



(r*cos(θ), r*sin(θ))

θ r


import peasy.*;

PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); } void draw(){ background(255,255,0); stroke(255); fill(40,80,200); for(float i=0; i<360; i+=6){ pushMatrix(); translate(50*cos(i*(PI/180)), 50*sin(i*(PI/180)), 0); box(10); popMatrix(); } }



Make a Spiral 做個神鬼奇航


import peasy.*;

PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); } void draw(){ background(255,255,0); stroke(255); fill(40,80,200); for(float i=0; i<1440; i+=6){ pushMatrix(); translate( (i/2)*cos(i*(PI/180)), (i/2)* sin(i*(PI/180)), i/3); box(25); popMatrix(); } }



import peasy.*;

PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 500); } void draw(){ background(255,255,0); stroke(255); fill(40,80,200); for(float i=0; i<1440; i+=6){ pushMatrix(); translate( (i/2)*cos(i*(PI/180)), (i/2)*sin(i*(PI/180)), i ); box(i/10); popMatrix(); } }



import peasy.*; PeasyCam gcam; void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 1000); } void draw(){ background(255,255,0); stroke(255); fill(40,80,200); for(float i=0; i<360; i+=1){ pushMatrix(); translate(200*cos(i*PI/180), 200*sin(i*PI/180), 200*sin(i*PI/180)); box(i/10); popMatrix(); } }



import peasy.*; PeasyCam gcam;

void setup(){ size(500,500,P3D); smooth(); gcam = new PeasyCam(this, 1000); } void draw(){ background(255,255,0); fill(40,80,200); int c1 = 1; int c2 = 1; int c3 = 2; for(float i=0; i<360; i+=1){ pushMatrix(); translate(200*cos(c1*i*PI/180), 200*sin(c2*i*PI/180), 200*sin(c3*i*PI/180)); box(i/10); popMatrix(); } }



int c1 = 1; int c2 = 1; int c3 = 3;

int c1 = 2; int c2 = 4; int c3 = 3;

int c1 = 1; int c2 = 1; int c3 = 6;

int c1 = 2; int c2 = 5; int c3 = 2;

int c1 = 2; int c2 = 1; int c3 = 3;

int c1 = 3; int c2 = 4; int c3 = 1;


If (you are interested more into 3D Mesh){ another library “Hemesh�; }


If (you are interested more into 3D Mesh){ another library “toxiclibs�; }


http://www.wblut.com/2010/05/04/hemesh-a-3d-mesh-library-for-processing/



Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.