|
|
发表于 2011-1-12 21:28:53
|
显示全部楼层
看到同学了,注册个号来支持下。
seminar后来我们分小组设计,没有征求过其他小组成员的意见,不好把目前的成果发上来。下面是小组讨论前我的初稿,刚接触processing,不成熟,权当抛砖引玉。(说明:部分代码源于老师 Mr. Ahlquist 给的文件,特别是Tab "cylinder" 里的内容;基本结构参考workshop里的文件,就是楼主上传的那个。)
附件是截图和文件。
Surface.tif
(115.7 KB, 下载次数: 14)
Surface.rar
(1.43 KB, 下载次数: 12)
我把代码也复制一份在下面,方便大家查阅。
首先需要两个library:particles 和 peasycam, 下载后直接拖到processing安装地址的libraries文件夹里。
第一页代码:
import peasy.test.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import simong.*;
import simong.particles.*;
PeasyCam cam;
ParticleSystem ps;
cylinderStructure cy;
void setup(){
size(921,691,P3D);
smooth();
cam = new PeasyCam(this, 0, 0, 0, 1000);
ps= new ParticleSystem(this);
ps.drawForces=true;
ps.setGravity(0,0,-0.1);
ps.defaultMass=0.01;
ps.defaultSpringDamping=0.01;
ps.defaultSpringRestLength=0.3;
strokeWeight(1);
stroke(0,150);
cy = new cylinderStructure();
}
void draw(){
background(255);
ps.draw();
cy.update();
}
新建一个Tab(文件里名为cylinderStructure):
class cylinderStructure{
cylinder[] cyds;
cylinderStructure(){
cyds = new cylinder [8];
cyds[0] = new cylinder(ps, 24, 24, -300, -300, 0);
cyds[1] = new cylinder(ps, 24, 24, 0, -300, 0);
cyds[2] = new cylinder(ps, 24, 24, 300, -300, 0);
cyds[3] = new cylinder(ps, 24, 24, 300, 0, 0);
cyds[4] = new cylinder(ps, 24, 24, 300, 300, 0);
cyds[5] = new cylinder(ps, 24, 24, 0, 300, 0);
cyds[6] = new cylinder(ps, 24, 24, -300, 300, 0);
cyds[7] = new cylinder(ps, 24, 24, -300, 0, 0);
}
void update(){
for (int i=0;i<24; i++)
{
for (int j=0;j<24;j++)
{
for (int m = 0; m <8; m+=2) {
cyds[m].pArr[j].unfix();
if (i==0){
if (j==3)cyds[m].pArr[j].fix();
if (j==9) cyds[m].pArr[j].fix();
if (j==15) cyds[m].pArr[j].fix();
if (j==21) cyds[m].pArr[j].fix();
}
else if (i==23){
if (j==3) cyds[m].pArr[j].fix();
if (j==9) cyds[m].pArr[j].fix();
if (j==15) cyds[m].pArr[j].fix();
if (j==21) cyds[m].pArr[j].fix();
}
}
}
}
for (int i=0;i<24; i++)
{
for (int j=0;j<24;j++)
{
for (int n = 1; n <8; n+=2) {
cyds[n].pArr[j].unfix();
if (i==0){
if (j==3)cyds[n].pArr[j].fix();
if (j==9) cyds[n].pArr[j].fix();
if (j==15) cyds[n].pArr[j].fix();
if (j==21) cyds[n].pArr[j].fix();
}
else if (i==23){
if (j==3) cyds[n].pArr[j].fix();
if (j==9) cyds[n].pArr[j].fix();
if (j==15) cyds[n].pArr[j].fix();
if (j==21) cyds[n].pArr[j].fix();
}
}
}
}
}
}
新建一tab(文件里名为cylinder):
class cylinder{
ParticleSystem ps;
Particle [][] pArr;
Spring [] sArr;
int rCt;
int cCt;
float aInc;
float radius=200.0;
float step = 15.0;
float xpos, ypos, zpos;
public cylinder(ParticleSystem defPS, int definedrCt, int definedcCt,
float x, float y, float z ){
this.ps = defPS;
this.rCt = definedrCt;
this.cCt = definedcCt;
this.xpos = x;
this.ypos = y;
this.zpos = z;
this.createMeshPoints();
this.createMeshEdges();
}
void createMeshPoints(){
pArr = new Particle[rCt][cCt];
aInc=360/cCt;
for (int i=0;i[j]=new Particle(ps,sin(aRad)*radius+xpos,cos(aRad)*radius+ypos,i*step+zpos);
pArr[j].visible=false;
if (i==0 || i==rCt-1)
{
pArr[j].fix();
pArr[j].visible=true;
}
}
}
}
void createMeshEdges(){
sArr = new Spring[10000];
int k=0;
for (int i=0;i[j],pArr[i+1][j]);
k++;
if (j[j],pArr[j+1]);
k++;
if (i==rCt-2)
{
sArr[k]=new Spring(pArr[i+1][j],pArr[i+1][j+1]);
k++;
}
}
else
{
sArr[k]=new Spring(pArr[j],pArr[0]);
k++;
if (i==rCt-2)
{
sArr[k]=new Spring(pArr[i+1][j],pArr[i+1][0]);
k++;
}
}
}
}
}
}
OK,到此为止。
|
|