作者 主题: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)  (阅读 16717 次)

big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #15 于: 六月 25, 2012, 09:29:18 下午 »
好不容易做出一个

float xStart, yStart;
float spacing;
float diam;
int rows;
int cols;
float degree,angleStart,angleStop;


void setup() {
  size(600, 450);
  smooth();
  xStart = 15;
  yStart = 15;
  spacing = 30;
  rows = 20;//一行有多少个
  cols = 15;
  diam = 30;
}
void draw() {
  background(#6D6D76);
  noStroke();
  fill(150);
  for (int i=0;i<cols;i++) {  //这个循环只是把圆画上
      for (int j=0;j<rows;j++) {
      fill(random(255),random(255),random(255));
      float xPos = xStart+j*spacing;
      float yPos = yStart+i*spacing;
      ellipse(xPos, yPos,diam,diam);
    }
  }

  for (int i=0;i<cols;i++) {  //这个循环是画扇形样子
      for (int j=0;j<rows;j++) {
      degree =random(360);
      angleStart=radians(degree);//扇形的起始角度
      angleStop=radians(degree+random(360)); //终止角度       
      float xPos = xStart+j*spacing;
      float yPos = yStart+i*spacing;
      fill(random(255),random(255),random(255));
      arc(xPos,yPos,diam,diam,angleStart,angleStop);
    }
  } 
  noLoop();
}




RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #16 于: 六月 26, 2012, 10:43:19 上午 »
@big_fat_meal

 :) 其实可以直接把两个循环合并在一块儿的。此外还可以让一些变量(矩阵起始位置,圆之间的间隔等)去绑定圆的直径,如下:

程序代码
float xStart, yStart;
float spacing;
float diam;
int cols, rows;

void setup() {
  size(600, 450);
  smooth();
  rows = 20;
  cols = 15;
  diam = 30;
  xStart = diam/2;
  yStart = diam/2;
  spacing = diam;
  noStroke();
}
void draw() {
  background(100);

  for (int i=0;i<cols;i++) {
    for (int j=0;j<rows;j++) {
      fill(random(255), random(255), random(255));
      float xPos = xStart+j*spacing;
      float yPos = yStart+i*spacing;
      ellipse(xPos, yPos, diam, diam);
     
      float degreeStart = random(360);
      float degreeEnd = degreeStart + random(360);

      fill(random(255), random(255), random(255));
      arc(xPos, yPos, diam, diam, radians(degreeStart), radians(degreeEnd));
    }
  }
  noLoop();
}


big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #17 于: 六月 26, 2012, 10:14:31 下午 »
原来如此哦,没合并成功

big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #18 于: 六月 26, 2012, 10:32:55 下午 »
这个原来这么简单,发现嵌套的循环无法解决出现直的竖线和横线的情况,。居然这么就好了

float[] xPos= new float [200];
float[] yPos= new float [200];

void setup(){
  size(400,400);
  smooth();
  noStroke();
  frameRate(30);
}
void draw(){
  background(255);
  noStroke();
  for(int i=0;i<200;i++){
    for(int j=0;j<200;j++){
      xPos=2*i+random(2);
      yPos[j]=2*j+random(2);
      stroke(33);
      strokeWeight(2);
      point(xPos,yPos[j]);
    }
  }
}
 



RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #19 于: 六月 27, 2012, 11:09:41 上午 »
@big_fat_meal

代码有些问题,应该是
程序代码
xPos[i]=2*i+random(2),以及point(xPos[i],yPos[j])
吧。

另外思路稍微复杂了些,其实杂点直接使点的颜色在灰度范围内随机就可以了,没有必要在位置上操作。当然这个效果也还不错拉 :)

big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #20 于: 六月 28, 2012, 02:02:27 下午 »
这个挺麻烦的,一直在循环里打转,拼来凑去成这个效果,感觉差不多OK了



import processing.opengl.*;

float [] xPos = new float[100];
float [] yPos = new float[100];
float [] xPosSeed = new float[100];
float [] yPosSeed = new float[100];
float seedIncre;
float thres;
float bright=0;
float sw=0;
float distance;

void setup() {
  size(500, 500,OPENGL);
  background(255);
  frameRate(20);
  smooth();
  for(int i=0;i<xPosSeed.length;i++){
    xPosSeed = random(100);
    yPosSeed = random(100);
  }
  seedIncre = 0.005;
  thres = 50;
}
void draw() { 
 
  for (int i=0;i<xPos.length;i++) {
    xPos = noise(xPosSeed)*width;
    yPos = noise(yPosSeed)*height;
    xPosSeed += seedIncre;
    yPosSeed += seedIncre;
  }

  for (int i=0;i<xPos.length;i++) {
    for (int j=i+1;j<xPos.length;j++) {
          float distance = dist(xPos, yPos, xPos[j], yPos[j]);
      if (distance<=thres) {
          float s=distance/thres;       
          sw=8*(1-s);
          strokeWeight(sw);
          stroke(bright,32);
          line(xPos, yPos, xPos[j], yPos[j]);
          bright+=0.005; 
       }
      }
    }
}



big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #21 于: 六月 28, 2012, 04:10:00 下午 »
在for循环里面,这两个有什么区别

       strokeWeight(sw);
          stroke(bright,32);
          line(xPos, yPos, xPos[j], yPos[j]);
          bright+=0.005; 

第二种
       strokeWeight(sw);
          stroke(0,8);        //这一行的stroke(0,8)是不是不起作用?
          line(xPos, yPos, xPos[j], yPos[j]);  //这个line有作用吗?       
          stroke(bright,42);
          line(xPos, yPos, xPos[j], yPos[j]);
          bright+=0.005;

big_fat_meal

  • Newbie
  • *
  • 帖子: 33
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #22 于: 六月 28, 2012, 04:13:42 下午 »
在draw的连线部分使用4个for循环和使用2个for循环有什么区别,是不是效果可以调的更好一些

import processing.opengl.*;
float [] xPos = new float[100];
float [] yPos = new float[100];
float [] xPosSeed = new float[100];
float [] yPosSeed = new float[100];
float seedIncre;
float thres;
float bright=0;
float sw=0;
float distance;


void setup() {
  size(500, 500,OPENGL);
  background(255);
  frameRate(20);
  smooth();
  for(int i=0;i<xPosSeed.length;i++){
    xPosSeed = random(100);
    yPosSeed = random(100);
  }
  seedIncre = 0.005;
  thres = 50;
}
void draw() { 
 
  for (int i=0;i<xPos.length;i++) {
    xPos = noise(xPosSeed)*width;
    yPos = noise(yPosSeed)*height;
    xPosSeed += seedIncre;
    yPosSeed += seedIncre;
  }




  for (int i=0;i<xPos.length;i++) {
    for (int j=i+1;j<xPos.length;j++) {
          distance = dist(xPos, yPos, xPos[j], yPos[j]);
      if (distance<=thres) {
          float s=distance/thres;       
          sw=8*(1-s);
          strokeWeight(sw);
          stroke(0,8);
          line(xPos, yPos, xPos[j], yPos[j]);

       }
      }
    }


 
  for (int i=0;i<xPos.length;i++) {
    for (int j=i+1;j<xPos.length;j++) {
      float distance = dist(xPos, yPos, xPos[j], yPos[j]);
      if (distance<thres) {
          float s=distance/thres;       
          sw=8*(1-s);
          strokeWeight(sw);         
           stroke(bright,48);
           line(xPos, yPos, xPos[j], yPos[j]);
           bright+=0.005;           
       }
      }
    }   
}

« 最后编辑时间: 六月 28, 2012, 04:16:35 下午 作者 big_fat_meal »

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #23 于: 六月 29, 2012, 02:10:44 下午 »
@big_fat_meal

关于你提交的作业你可以尝试一下使用noLoop()来停止draw 循环。(譬如当bright 超过255时执行)

另外没有理解你说的使用4个for循环的意义,为何要重复绘制两遍同样的内容? :)

GordonXu

  • Newbie
  • *
  • 帖子: 6
Re: [ 作业提交 ] P5 Intro Course DAY1 & DAY2 (06/17/2012,06/24/2012)
« 回复 #24 于: 七月 21, 2012, 02:03:54 下午 »
郭老师,如何把移动过程中的残影弄走而不清空画面上其他的图形?求指导

Tags: