如何使用处理2使点仅填充圆的边缘而不是整个区域?

时间:2014-11-13 21:31:12

标签: processing

    void setup()
    {
    size(600, 600);
    colorMode(HSB);
    background(255);
    }

    void draw()
    int size;
    size(600, 600);
    smooth();
    noFill();
    float cx = width/2;
    float cy = height/2;
    float diameter = width;   
    ellipse(cx, cy, diameter, diameter);
    size = 10;

    for (int x=size; x<width; x+=size) {
        for (int y=size; y<height; y+=size) {
            float dist;
            dist = 10;
            fill((x + y)%256, 255, 255);
            noStroke();
            ellipseMode(CENTER);
            ellipse(x, y, size, size);
        }
    }
}

这是我到目前为止所做的,我似乎无法弄清楚如何制作它所以它只填充到圆的边缘。这是使用麻省理工学院创建的处理2程序。 https://www.processing.org/

2 个答案:

答案 0 :(得分:1)

或者你是说这个?

void setup()
{
  size(600, 600);
  colorMode(HSB);
  background(255);
}

void draw(){
  int size;
  size(600, 600);
  smooth();
  noFill();
  float cx = width/2;
  float cy = height/2;
  float diameter = width;  
  float radius = diameter/2;
  float radiusSqrd = radius*radius; 
  ellipse(cx, cy, diameter, diameter);
  size = 10;

  for (int x=size; x<width; x+=size) {
      for (int y=size; y<height; y+=size) {
          float dist;
          //dist = sqrt( (cx-x)*(cx-x) + (cy-y)*(cy-y) );
          float distSqrd = (cx-x)*(cx-x) + (cy-y)*(cy-y);
          if ( distSqrd <= radiusSqrd ){
            fill((x + y)%256, 255, 255);
            noStroke();
            ellipseMode(CENTER);
            ellipse(x, y, size, size);
          }
      }
  }
}

这将检查x和y离中心(cx,cy)的距离,如果小于圆,则绘制椭圆。使用距离平方和半径平方,因为数学更快。

答案 1 :(得分:0)

你是说这个?

    void setup()
    {
    size(600, 600);
    colorMode(HSB);
    background(255);
    }

    void draw(){
    int size;
    size(600, 600);
    smooth();
    noFill();
    float cx = width/2;
    float cy = height/2;
    float diameter = width;   
    ellipse(cx, cy, diameter, diameter);
    size = 10;

    for (int a=0; a<360; a+=2) {

            float dist;
            dist = 10;
            fill((a)%256, 255, 255);
            noStroke();
            float x = width/2 + cos(radians(a))*diameter/2;
            float y = height/2 + sin(radians(a))*diameter/2;
            ellipseMode(CENTER);
            ellipse(x, y, size, size);

    }
}