NCF参数化建筑论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 13108|回复: 16
打印 上一主题 下一主题

[工作记录] 请教大家简化这个code的方法

[复制链接]
跳转到指定楼层
1m
发表于 2011-3-14 17:58:09 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 volcanoohead 于 2011-3-15 12:49 编辑 float x,y,nx1,ny1,nx2,ny2,nx3,ny3,nx4,ny4,nx5,ny5,nx6,ny6,px,py,scf,scfx,scfy; float scfl = 0.95; float t1 = 0; float l1 = 160; float st1 = 0.01; float elf = 1.5; float t2 = 1; float l2 = l1 * scfl; float st2 = 0.02; float t3 = 2; float l3 = l2 * scfl; float st3 = 0.05; float t4 = 3; float l4 = l3 * scfl; float st4 = 0.07; float t5 = 4; float l5 = l4 * scfl; float st5 = 0.09; float t6 = 5; float l6 = l5 * scfl; float st6 = 0.07; float t7 = 6; float l7 = l6 * scfl; float st7 = 0.05; void setup(){ size(1100,1100); smooth(); } void draw(){ //refresh background background(255); x = mouseX; y = mouseY; scfx = 0.6*((width/2)-(abs(x-(width/2))))/(width / 2); scfy = 0.6*((height/2)-(abs(y-(height/2))))/(height / 2); scf = min(scfx,scfy); // set circle point algorithms nx1 = x+scf*elf*l1*sin(t1); ny1 = y+scf*l1*cos(t1); t1=t1+st1; nx2 = nx1+scf*l2*sin(t2); ny2 = ny1+scf*elf*l2*cos(t2); t2=t2-st2; nx3 = nx2+scf*elf*l3*sin(t3); ny3 = ny2+scf*l3*cos(t3); t3=t3+st3; nx4 = nx3+scf*l4*sin(t4); ny4 = ny3+elf*scf*l4*cos(t4); t4=t4-st4; // set a circle point algorithm nx5 = nx4+elf*scf*l5*sin(t5); ny5 = ny4+scf*l5*cos(t5); t5=t5+st5; // set a circle point algorithm nx6 = nx5+elf*scf*l6*sin(t6); ny6 = ny5+scf*l6*cos(t6); t6=t6-st6; //draw some circles if ( x < width/2){ if ( y < height/2){ fill(0,128,255,100); } else if ( y >= height/2){ fill(255,0,0,100); } } else{ if ( y < height/2){ fill(200,255,120,100); } else if ( y >= height/2){ fill(255,255,0,100); } } noStroke(); ellipse(x,y,scf*l1*(sin(t1)+cos(t1))*2,scf*l1*(sin(t1)+cos(t1))*2); ellipse(nx1,ny1,scf*l2*(sin(t2)+cos(t2))*2,scf*l2*(sin(t2)+cos(t2))*2); ellipse(nx2,ny2,scf*l3*(sin(t3)+cos(t3))*2,scf*l3*(sin(t3)+cos(t3))*2); ellipse(nx3,ny3,scf*l4*(sin(t4)+cos(t4))*2,scf*l4*(sin(t4)+cos(t4))*2); ellipse(nx4,ny4,scf*l5*(sin(t5)+cos(t5))*2,scf*l5*(sin(t5)+cos(t5))*2); ellipse(nx5,ny5,scf*l6*(sin(t6)+cos(t6))*2,scf*l6*(sin(t6)+cos(t6))*2); ellipse(nx6,ny6,scf*l7*(sin(t7)+cos(t7))*2,scf*l7*(sin(t7)+cos(t7))*2); //draw a bezier noFill(); stroke(255); strokeWeight(3); beginShape(); curveVertex(x,y); curveVertex(nx1,ny1); curveVertex(nx2,ny2); curveVertex(nx3,ny3); curveVertex(nx4,ny4); curveVertex(nx5,ny5); curveVertex(nx6,ny6); curveVertex(x,y); curveVertex(nx1,ny1); curveVertex(nx2,ny2); endShape(); noStroke(); bezier (x,y,nx1,ny1,nx2,ny2,nx3,ny3); bezier (nx3,ny3,nx4,ny4,nx5,ny5,nx6,ny6); bezier (nx6,ny6,x,y,nx1,ny1,nx2,ny2); bezier (nx2,ny2,nx3,ny3,nx4,ny4,nx5,ny5); bezier (nx5,ny5,nx6,ny6,x,y,nx1,ny1); bezier (nx1,ny1,nx2,ny2,nx3,ny3,nx4,ny4); bezier (nx4,ny4,nx5,ny5,nx6,ny6,x,y); // draw center point stroke(0); strokeWeight(5); ellipseMode(CENTER); ellipse(x,y,5,5); ellipse(nx1,ny1,5,5); ellipse(nx2,ny2,5,5); ellipse(nx3,ny3,5,5); ellipse(nx4,ny4,5,5); ellipse(nx5,ny5,5,5); ellipse(nx6,ny6,5,5); stroke(255); strokeWeight(1); ellipseMode(CENTER); ellipse(x,y,5,5); ellipse(nx1,ny1,2,2); ellipse(nx2,ny2,2,2); ellipse(nx3,ny3,2,2); ellipse(nx4,ny4,2,2); ellipse(nx5,ny5,2,2); ellipse(nx6,ny6,2,2); //draw clock arms stroke(100); strokeWeight(1); line(x,y,nx1,ny1); line(x,y,nx2,ny2); line(nx1,ny1,nx2,ny2); line(nx1,ny1,nx3,ny3); line(nx1,ny1,nx4,ny4); line(nx1,ny1,nx5,ny5); line(nx2,ny2,nx3,ny3); line(nx2,ny2,nx4,ny4); line(nx2,ny2,nx5,ny5); line(nx3,ny3,nx4,ny4); line(nx3,ny3,nx5,ny5); line(nx4,ny4,nx5,ny5); line(nx5,ny5,nx6,ny6); line(nx4,ny4,nx6,ny6); line(nx3,ny3,nx6,ny6); line(nx2,ny2,nx6,ny6); line(nx1,ny1,nx6,ny6); line(x,y,nx6,ny6); // draw coordinate lines stroke(255,100); strokeWeight(1); line(0,y,width,y); line(x,0,x,height); line(0,ny1,width,ny1); line(nx1,0,nx1,height); line(0,ny2,width,ny2); line(nx2,0,nx2,height); line(0,ny3,width,ny3); line(nx3,0,nx3,height); line(0,ny4,width,ny4); line(nx4,0,nx4,height); line(0,ny5,width,ny5); line(nx5,0,nx5,height); line(0,ny6,width,ny6); line(nx6,0,nx6,height); //draw center white point stroke(255); strokeWeight(1); ellipseMode(CENTER); ellipse(x,y,5,5); ellipse(nx1,ny1,2,2); ellipse(nx2,ny2,2,2); ellipse(nx3,ny3,2,2); ellipse(nx4,ny4,2,2); ellipse(nx5,ny5,2,2); ellipse(nx6,ny6,2,2); println("scf = " +scf + " x = " + x + " y = " + y + " nx1 = " + nx1 + " ny1 = " + ny1); }
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2m
 楼主| 发表于 2011-3-14 17:58:59 | 显示全部楼层
我知道我写得很罗嗦很罗嗦。有没有什么办法简化这个code呢?
3m
 楼主| 发表于 2011-3-15 10:58:19 | 显示全部楼层
7# panhao1 谢谢。我刚学到教材60页。看了看class在300多页。
4m
 楼主| 发表于 2011-3-15 12:01:31 | 显示全部楼层
4# yy6669 请问定义的时候如何简化呢?

小黑屋|手机版|NCF参数化建筑论坛 ( 浙ICP备2020044100号-2 )    辽公网安备21021102000973号

GMT+8, 2024-5-23 00:18 , Processed in 0.064615 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表