找回密码
 注册
搜索
查看: 64642|回复: 40

假前最后一贴,极其变态的voronoi求法

[复制链接]
发表于 2010-6-30 01:11:01 | 显示全部楼层 |阅读模式
本帖最后由 panhao1 于 2010-6-30 01:31 编辑

先看官网的processing代码  3L是我修改了的代码 揭露原理
1.jpg
int NUM_POINTS = 12;
float x[];  // point x
float y[];  // point y
float av[]; // point angular velocity
color c[];  // point color

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);
  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;

  // 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();
}

评分

参与人数 1强度 +7 照度 +80 收起 理由
skywoolf + 7 + 80 很有启发

查看全部评分

发表于 2014-8-5 19:36:12 | 显示全部楼层
尽管不懂  也来支持一下
回复

使用道具 举报

发表于 2012-2-18 22:48:54 | 显示全部楼层
学习学习~~~~~~~
回复

使用道具 举报

发表于 2012-1-14 22:11:45 | 显示全部楼层
仰望啊仰望
回复

使用道具 举报

发表于 2012-1-14 21:00:59 | 显示全部楼层
潘大的帖子向来看不懂,求入门……
回复

使用道具 举报

发表于 2012-1-14 20:26:12 | 显示全部楼层
很厉害的算法啊 还以为voronoi只能用点上色来做呢。。。 赞!
回复

使用道具 举报

发表于 2011-12-4 21:30:26 | 显示全部楼层
学习了。。。。。
回复

使用道具 举报

发表于 2011-12-4 09:52:05 | 显示全部楼层
感谢分享~~~~~
回复

使用道具 举报

发表于 2011-11-7 00:27:38 | 显示全部楼层
牛人 {:3_46:}
回复

使用道具 举报

发表于 2011-11-2 16:49:56 | 显示全部楼层
大开眼界!!!!
回复

使用道具 举报

发表于 2011-10-5 08:04:25 | 显示全部楼层
可是我尝试了加i还是不行啊?求jie
回复

使用道具 举报

发表于 2011-10-4 10:36:15 | 显示全部楼层
写得太好了~!就是看不懂啊~等待高手回帖
回复

使用道具 举报

发表于 2011-10-4 10:14:03 | 显示全部楼层
感谢楼主分享啊,正在学习中~
回复

使用道具 举报

发表于 2011-9-20 04:52:14 | 显示全部楼层
带着谦虚的心来求学
回复

使用道具 举报

发表于 2011-9-16 20:03:24 | 显示全部楼层
processing有群吗,如果没有希望楼主建个群,大家可以方便交流
回复

使用道具 举报

发表于 2011-9-16 19:33:09 | 显示全部楼层
学习中,很有帮助,谢谢
回复

使用道具 举报

发表于 2011-8-22 23:09:29 | 显示全部楼层
回复

使用道具 举报

发表于 2011-8-17 00:01:01 | 显示全部楼层
欣赏吧  自己试试。
回复

使用道具 举报

发表于 2011-8-16 22:11:37 | 显示全部楼层
怎么导出DWG?请问。。
回复

使用道具 举报

发表于 2011-8-16 21:55:23 | 显示全部楼层
怎么到处DWG?请问。。
回复

使用道具 举报

发表于 2010-10-6 23:37:48 | 显示全部楼层
强悍!!!
要学习的东西还好多
回复

使用道具 举报

NCFZ微信公众号

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

GMT+8, 2026-12-3 17:19 , Processed in 0.053372 second(s), 29 queries , Gzip On.

Powered by Discuz! X5.0 Licensed

© 2001-2026 Discuz! Team.

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