作者 主题: [ Processing 作品开源 ] sketch_sep16b_2011  (阅读 3978 次)

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
[ Processing 作品开源 ] sketch_sep16b_2011
« 于: 九月 17, 2011, 10:17:40 下午 »
sketch_sep16b_2010  是我个人已经在openProcessing 社区里开源的Processing 生成作品。

via http://openprocessing.org/visuals/?visualID=37680

在这里也贴下代码,欢迎各种提问,交流,拍砖。 :)



程序代码
//Raven Kwok | 郭锐文
//Email: raystain@gmail.com
//Blog: the-moor.blogbus.com
//Vimeo: vimeo.com/ravenkwok
//Weibo: weibo.com/ravenkwok
 
Particle [] particles;
 
void setup() {
  background(255);
  size(600, 600);
  frameRate(30);
  smooth();
  particles = new Particle [3];
  for(int i=0;i<particles.length;i++){
    particles[i] = new Particle();
  }
}

void draw() {
  for(int i=0;i<particles.length;i++){
    particles[i].run();
    particles[i].display();
    particles[i].update();
  }
}

class Particle {
  float radiusIncre, xPosIncre, yPosIncre, colorIncre, xTargetIncre, yTargetIncre;
  float radiusTime, xPosTime, yPosTime, redTime, greenTime, blueTime, xTargetTime, yTargetTime;
  float radiusRange, xPosRange, yPosRange, colorRange, xTargetRange, yTargetRange;
  float radiusV, xPosV, yPosV, redV, greenV, blueV, xTargetV, yTargetV, xOffsetV, yOffsetV;
  float accelerateV;
  float lineWeight;
  Particle() {
    radiusTime = random(100);
    xTargetTime = random(100);
    xPosTime = random(100);
    yTargetTime = random(100);
    yPosTime = random(100);
    redTime = random(100);
    greenTime = random(100);
    blueTime = random(100);
    xPosRange = width;
    xTargetRange = width;
    yPosRange = height;
    yTargetRange = height;
    radiusRange = width/3;
    colorRange = 255;
    xPosIncre = yPosIncre = radiusIncre = colorIncre = 0.01;
    xTargetIncre = yTargetIncre = 0.005;
    xPosV = width/2;
    yPosV = height/2;
    accelerateV = 100;
    lineWeight = random(10);
  }
  void run() {
    xTargetV = noise(xTargetTime)*xTargetRange;
    yTargetV = noise(yTargetTime)*yTargetRange;
    xPosV += (xTargetV-xPosV)/accelerateV;
    yPosV += (yTargetV-yPosV)/accelerateV;
    redV = noise(redTime)*1.8*colorRange;
    greenV = noise(greenTime)*1.8*colorRange;
    blueV = noise(blueTime)*1.8*colorRange;
    xOffsetV = (noise(xPosTime)-0.5)*xPosRange;
    yOffsetV = (noise(yPosTime)-0.5)*yPosRange;
    radiusV = noise(radiusTime)*noise(radiusTime)*noise(radiusTime)*radiusRange;
  }
  void display() {
    stroke(random(100,255), random(200,255), random(0,100));
    strokeWeight(lineWeight);
    beginShape();
    vertex(xTargetV,yTargetV);
    vertex((xTargetV+xPosV)/2, (yTargetV+yPosV)/2);
    endShape();
    strokeWeight(0.5);
    fill(redV, greenV, blueV);
    ellipse(xPosV+xOffsetV, yPosV+yOffsetV, radiusV*0.8, radiusV*0.8);
     
  }
  void update() {
    xTargetTime += xTargetIncre;
    yTargetTime += yTargetIncre;
    xPosTime += xPosIncre;
    yPosTime += yPosIncre;
    radiusTime += radiusIncre;
    redTime += colorIncre;
    greenTime += colorIncre;
    blueTime += colorIncre;
  }
}
 
void mousePressed(){
  background(255);
}
« 最后编辑时间: 九月 17, 2011, 10:21:11 下午 作者 RavenKwok »