本文介绍了我如何使用for循环了一圈(在处理)创建的圈子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个回路,将空间界同样围绕在处理一个圆圈。

我知道我能以某种方式实现一个for循环。

我需要能够增加或减少圈数绕这个圈子(与按钮presses),但让他们等间隔的。

我知道公式的我需要在包括FOR循环,以获得X和Y轴。计算公式:

 幸福
   X = R *为cos(角度-90)+ Y0
   Y = R *罪(角-90)+ X0
 

我理解的FOR循环的三个参数;当它启动,当它完成,它运行的时候有什么变化。

我看不出是如何实现的公式为FOR循环。

感谢

下面是code我有

 无效设置(){
  尺寸(600,600);
  背景(255,255,255);
  光滑 ();
  椭圆(宽度/ 2,高度/ 2,200,200); //引导循环。没有必要在最后的code。
}


无效的draw(){


  的for(int i = 0;我小于20;我++){
    为(诠释J = 0; J&小于20; J ++){

      椭圆(I * 20,J * 20,20,20);
    }
  }
}
 

解决方案

感谢大家谁帮助。

我设法做到这一点(略有不同,以您@Jose冈萨雷斯

  INT nbr_circles = 2;
无效设置(){
  尺寸(600,600);

  光滑();
  背景(255);
}

无效的draw(){
  背景(255);
  浮CX =宽度/ 2.0;
  浮CY =身高/ 2.0;
  填写(0);
  //浮动的x,y; //
  的for(int i = 0; I< nbr_circles;我++)
  {
    浮动角= I * TWO_PI / nbr_circles;
    浮X = CX + 110.0 * COS(角);
    浮动Y = CY + 110.0 *罪(角度);
    椭圆(X,Y,20,20);
  }
}

无效鼠标pressed(){

  如果(mouseButton ==左){
    如果(nbr_circles小于20)
    nbr_circles = nbr_circles + 1;

  }否则,如果(mouseButton ==右){
    如果(nbr_circles→2)
      nbr_circles = nbr_circles  -  1;

  }
}
 

I need to create a loop which will space circles equally around a circle in Processing.

I know I can somehow implement a FOR loop.

I need to be able to increase or decrease the number of circles around this circle (with button presses) but keep them equally spaced.

I know the formula's I need to include in the FOR loop to get the X and Y axis. The formulas:

being
   X = R*cos(angle-90)+Y0
   Y = R*sin(angle-90)+X0

I understand the three parameters of the FOR loop; when does it start, when does it finish, what changes when it runs.

What I can't see is how to implement the formulas into the FOR loop.

Many thanks

Here is the code I do have

void setup () {
  size (600, 600);
  background (255, 255, 255);
  smooth ();
  ellipse (width/2, height/2, 200, 200); // the guide circle. Not needed in final code.
}


void draw() {


  for (int i = 0; i < 20; i ++) {
    for (int j = 0; j < 20; j ++) {

      ellipse (i *20, j * 20, 20, 20);
    }
  }
}
解决方案

Thank you to everyone who helped.

I managed to do it (slightly differently to you @Jose Gonzalez

   int nbr_circles = 2;
void setup() {
  size(600, 600);

  smooth();
  background(255);
}

void draw() {
  background(255);
  float cx = width/2.0;
  float cy = height/2.0;
  fill(0);
  //float x, y; //
  for (int i = 0; i < nbr_circles; i++)
  {
    float angle = i * TWO_PI / nbr_circles;
    float x = cx + 110.0 * cos(angle);
    float y = cy + 110.0 * sin(angle);
    ellipse(x, y, 20, 20);
  }
}

void mousePressed() {

  if (mouseButton == LEFT) {
    if (nbr_circles < 20)
    nbr_circles = nbr_circles + 1;

  } else if (mouseButton == RIGHT) {
    if (nbr_circles > 2)
      nbr_circles = nbr_circles - 1;

  }
}

这篇关于我如何使用for循环了一圈(在处理)创建的圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 00:09