circles

edited October 2016 in Questions about Code

Безымянный

Hello! I want to locate circles like on the picture (red colour). I want change variable "n" to change ammount of circles (now n=4). I want every sircle moves to his right position and stop.

Sorry for newby question.

float gradx;
float x  ;
float grady;
float y;
float easing = 0.01;
//float diameter = 12;
int rad = 100;
int n = 4;

float [] step = new float [n];
//float [] yy = new float [n];

void setup() {
  size(500, 500); 
  //translate (250,250);
  smooth();
  for (int i = 0; i <= n-1; i++)
  {
    step[i] = 360/n * i;

  }


;
}
void draw() {
  translate (250,250);
  background (0);
  ellipse(0 , 0, 200, 200);
  circle(n);



}

void circle (int n)
{
  for (int i = 0; i <= n-1; i++)
  {
  float target_anglex = step[i];
  gradx += (target_anglex - gradx) * easing;

  println(gradx);
  x = cos(radians(gradx))* rad;
  println(x + "+");

  float target_angley = step[i];
  grady += (target_angley - grady) * easing;
  y = sin(radians(grady)) * rad;

  noFill();

  ellipse(x , y, 30, 30);
  //ellipse(x+20 , y+20, 12, 12);
  stroke(255);
  //line (300,300,x,y);
  //println(x +"+"+ y);
    }
}
Tagged:

Answers

  • Answer ✓

    Got it.

    int n = 4;
    
    
    
    float easing = 0.01;
    
    int rad = 100;
    
    float [] step = new float [n];
    
    float [] x = new float [n];
    float [] y = new float [n];
    
    float [] gradx = new float [n];
    float [] grady = new float [n];
    
    
    void setup() {
      size(500, 500); 
      //translate (250,250);
      smooth();
      for (int i = 0; i <= n-1; i++)
      {
        step[i] = 360/n * i;
    
      }
    
    
    ;
    }
    void draw() {
      translate (250,250);
      background (0);
      ellipse(0 , 0, 200, 200);
      circle(n);
    
    
    
    }
    
    void circle (int n)
    {
      for (int i = 0; i <= n-1; i++)
      {
      float target_anglex = step[i];
      gradx[i] += (target_anglex - gradx[i]) * easing;
    
      println(gradx);
      x[i] = cos(radians(gradx[i]))* rad;
      println(x + "+");
    
      float target_angley = step[i];
      grady[i] += (target_angley - grady[i]) * easing;
      y[i] = sin(radians(grady[i])) * rad;
    
      noFill();
    
      ellipse(x[i] , y[i], 30, 30);
      //ellipse(x+20 , y+20, 12, 12);
      stroke(255);
      //line (300,300,x,y);
      //println(x +"+"+ y);
        }
    }
    
Sign In or Register to comment.