作者 主题: [ 作业讨论 ] DAY3 - DNA Helix  (阅读 15987 次)

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
[ 作业讨论 ] DAY3 - DNA Helix
« 于: 十一月 01, 2011, 09:39:50 上午 »
作业需要达到的效果图在DAY3 pdf 第20页上。

提示:用一个for 循环就可完成,但由于涉及到三维空间上的坐标系偏移旋转,需要频繁使用到push 与pop 的嵌套。

这个作业有一定的难度,基础略低的童鞋完成Grainy Screen 即可。 8)
« 最后编辑时间: 十一月 01, 2011, 09:46:02 上午 作者 RavenKwok »

kulala

  • Newbie
  • *
  • 帖子: 6
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #1 于: 十一月 03, 2011, 12:33:03 上午 »


有个错误提示,说too many call to pushMatrix(),查了半天找不出原因,Raven帮我看看啥问题。

程序代码
import processing.opengl.*;

void setup(){
  size(600,600,OPENGL);
  lights();
  smooth();
  background(0);
}

void draw(){
pushMatrix();
  fill(255);
  translate(300,600,-50);//set 300,550,0 zero point
  pushMatrix();
  translate(100,0,0);
  pushMatrix();
  for (int m=0;m<30;m++){
  box(120,5,5);
  translate(0,-30,0);
  rotateY(-PI/6);
   }
  popMatrix();
 
  pushMatrix();
  for(int n=0;n<30;n++){
  pushMatrix();
  translate(-60*cos(PI/6*n),0,-60*sin(PI/6*n));
  fill(255);
  sphereDetail(4);
  sphere(10);
  popMatrix();
  translate(0,-30,0);
  }
  popMatrix();
 
  pushMatrix();
  for(int b=0;b<30;b++){
  pushMatrix();
  translate(60*cos(PI/6*b),0,60*sin(PI/6*b));
  fill(255);
  sphereDetail(4);
  sphere(10);
  popMatrix();
  translate(0,-30,0);
  }
  popMatrix();
}

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #2 于: 十一月 03, 2011, 03:14:00 下午 »
@kulala

少了一次pop,一般来说push 和pop 的数目应当是一致的。 8)

钱 卓 韵

  • Newbie
  • *
  • 帖子: 7
  • 学习中 恩
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #3 于: 十一月 05, 2011, 11:10:38 下午 »
本来觉得很难的一直没做,果然不能怕困难




程序代码
int totalAmount;

void setup() {
  size(500, 500, P3D);
  lights();
  totalAmount = 20;
}

void draw() {
  background(255);
  translate(width/2, height/2);
  rotateX(mouseY * 0.05);
  rotateY(mouseX * 0.05);
  for (int i=0;i<totalAmount;i++){
    DrawDna(i*30-height/2);
    rotateY(10);
  }
}

void DrawDna(int Y_) {
  pushMatrix();
  translate(-50, Y_, 0);
  sphereDetail(4);
  sphere(10);
  popMatrix();
  pushMatrix();
  translate(50, Y_, 0);
  sphereDetail(4);
  sphere(10);
  popMatrix();
  line(50, Y_,-50, Y_);
}




Linyew

  • Newbie
  • *
  • 帖子: 7
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #4 于: 十一月 05, 2011, 11:35:18 下午 »
程序代码
void setup(){
  size(400, 600, P3D);
  smooth();
}

void draw(){
  background(0);
  translate(width/2, height/2);
  rotateX(radians((height/2 - mouseY)*0.6));
  rotateY(radians((mouseX)));
  for (int i=0; i<20;i++){
    pushMatrix();
    rotateY(radians(30*i));
    drawSphere(-50, i, color(255,0,0));//draw first sphere
    drawSphere(50, i, color(0,0,255));//draw second sphere
    stroke(150);
    line(-50, -height/2+30*i, 0, 50, -height/2+30*i, 0);
    popMatrix();
  }
}

void drawSphere(int transX, int a, int color_){
  pushMatrix();
  translate(transX, -height/2+30*a);
  noStroke();
  fill(color_);
  sphere(8);
  popMatrix();
}

 :)

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #5 于: 十一月 07, 2011, 12:22:59 下午 »
@钱 卓 韵

 ;) 不错,很多问题没有看上去的那么困难。

RavenKwok

  • Sr. Member
  • ****
  • 帖子: 277
  • Artist/ Animator/ Coder/ Cynical Asshole
Re: [ 作业讨论 ] DAY3 - DNA Helix
« 回复 #6 于: 十一月 07, 2011, 12:24:15 下午 »
@Linyew

Cool~  :)

Tags: