先看官网的processing代码 3L是我修改了的代码 揭露原理
[attach]9047[/attach] int NUM_POINTS = 12; float x[]; // point x float y[]; // point y float av[]; // point angular velocity color c[]; // point color
// draw the cones pushMatrix();
// -10 means the cones are below the surface
// (so we can draw on top of them later) translate(0,0,-10); for (int i = 0; i < NUM_POINTS; i++) { fill(c); noStroke();
// if you have more points, use a smaller radius
// (but you risk having gaps)
cone(x,y,200.0,10.0);
} popMatrix();
// give user control of first point
x[0] = mouseX;
y[0] = mouseY;
// just inits the points of a circle,
// if you're doing lots of cones the same size
// then you'll want to cache height and radius too staticvoid coneDetail(int det) {
coneDetail = det;
unitConeX = newfloat[det+1];
unitConeY = newfloat[det+1]; for (int i = 0; i <= det; i++) { float a1 = TWO_PI * i / det;
unitConeX = (float)Math.cos(a1);
unitConeY = (float)Math.sin(a1);
}
}
如果是专业卡的机子 ,用OPENGL比P3D效果更好作者: panhao1 时间: 2010-6-30 01:26
[attach]9048[/attach]
int NUM_POINTS = 12;
float x[]; // point x
float y[]; // point y
float av[]; // point angular velocity
color c[]; // point color
float time;
void setup() {
size(400,400, P3D);
// FIXME: ortho seems to be a bit strange, I am investigating
//ortho(-width/2,width/2,-height/2,height/2,-10,10);
x = new float[NUM_POINTS];
y = new float[NUM_POINTS];
av = new float[NUM_POINTS];
c = new color[NUM_POINTS];
for (int i = 0; i < NUM_POINTS; i++) {
x = random(width);
y = random(height);
av = random(-0.02,0.02);
c = color(random(255),random(255),random(255));
}
}
void draw() {
background(0);
// draw the cones
pushMatrix();
// -10 means the cones are below the surface
// (so we can draw on top of them later)
//translate(0,0,-10);
translate(200,200,-10);
//真相
rotateX(time);
rotateY(time*2);
time+=0.01;
//真相
for (int i = 0; i < NUM_POINTS; i++) {
fill(c);
noStroke();
// if you have more points, use a smaller radius
// (but you risk having gaps)
cone(x,y,200.0,100.0);
}
popMatrix();
// give user control of first point
x[0] = mouseX;
y[0] = mouseY;
// on mouse pressed, orbit the points around the centre of the screen
if (mousePressed) {
for (int i = 1; i < NUM_POINTS; i++) {
float r = dist(width/2,height/2,x,y);
float a = atan2(y-(height/2),x-(width/2)) + av;
x = (width/2) + (r * cos(a));
y = (height/2) + (r * sin(a));
}
}
// draw dots for the points
for (int i = 0; i < NUM_POINTS; i++) {
fill(0);
noStroke();
ellipse(x,y,5.0,5.0);
}
}
static float unitConeX[];
static float unitConeY[];
static int coneDetail;
static {
coneDetail(24);
}
// just inits the points of a circle,
// if you're doing lots of cones the same size
// then you'll want to cache height and radius too
static void coneDetail(int det) {
coneDetail = det;
unitConeX = new float[det+1];
unitConeY = new float[det+1];
for (int i = 0; i <= det; i++) {
float a1 = TWO_PI * i / det;
unitConeX = (float)Math.cos(a1);
unitConeY = (float)Math.sin(a1);
}
}
// places a cone with it's base centred at (x,y),
// beight h in positive z, radius r.
void cone(float x, float y, float r, float h) {
pushMatrix();
translate(x,y);
scale(r,r);
beginShape(TRIANGLES);
for (int i = 0; i < coneDetail; i++) {
vertex(unitConeX,unitConeY,0.0);
vertex(unitConeX[i+1],unitConeY[i+1],0.0);
vertex(0,0,h);
}
endShape();
popMatrix();
}作者: goodsky2009 时间: 2010-6-30 01:39
写得太好了~!就是看不懂啊~等待高手回帖作者: skywoolf 时间: 2010-6-30 06:23
{:3_52:}犀利了~不过还有没理解为什么会是圆锥,调节圆锥的z轴难道可以做加权的voronoi?想到圆锥不同纬度上半径增加速度有比例关系的。作者: lihaikai 时间: 2010-6-30 10:50
弱弱地问下,这是什么代码?作者: 夜神 时间: 2010-6-30 11:07
好久不用C++了,看了楼主的代码既亲切又陌生,呵呵!
顶一下楼主!这个领域大有作为!