2011年9月11日 星期日

SinCosSin ( processing )

開始於非常簡單的
以sin, cos 表達圓形的座標
出發 
並僅在sin cos的內部角度進行調整
即可形成此種多變造型
Start with simple function that 
describe the circle by
sin, cos.
Making different proportion degree inside the 
sin cos to form these diversity forms.


最初的CODE:
The beginning code:
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();
 }
}

然後即加入sin於Z軸
並代入常數控制 x y z 座標的關係
形成複雜圖形

Then we try to put "sin" as a Z location.
and we put the constant to control the relation ship between x y z
to make these complex forms.

所以只要調整C1 C2 C3的數字
即可看到變化
So just changing the number of C1,C2,C3
then yo can see how it changes.

透過ControlP5加入Slider去控制參數
Add slider by controlP5 Library

the CODE:

import peasy.*;

import controlP5.*;
 int c1 = 2;
 int c2 = 4;
 int c3 = 3;
PeasyCam cam;
ControlP5 controlP5;
PMatrix3D currCameraMatrix;
PGraphics3D g3;
float circleSize = 50;
void setup() {
  size(800,800,P3D);
  g3 = (PGraphics3D)g;
  cam = new PeasyCam(this, 800);
  controlP5 = new ControlP5(this);
 
  controlP5.addSlider("c1",0,10,10,10,200,20);
  controlP5.addSlider("c2",0,10,10,40,200,20);
  controlP5.addSlider("c3",0,10,10,70,200,20); 
  //add your slider here
  controlP5.setAutoDraw(false);
}

void draw() {
   
   if (controlP5.window(this).isMouseOver()) {
       cam.setActive(false);
      } else {
       cam.setActive(true);
      }// to avoid the interruption between peasyCam and ControlP5
 
  background(255,255,0);//Add your main CODE here
  fill(255,80,255);
  stroke(0);
 
    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();
  }
  // END
   gui();
}
void gui() {
   currCameraMatrix = new PMatrix3D(g3.camera);
   camera();
   controlP5.draw();
   g3.camera = currCameraMatrix;
}












沒有留言:

張貼留言