Tut­o­r­i­a­l­9

by chris Huang
  • Show Code
/** @peep sketch */
float angle = 0.0; // Current angle
float speed = 0.01; // Speed of motion
float radius = 60.0; // Range of motion
float sx = 2.0;
float sy = 2.0;
 
void setup() {
  size(200, 200);
  background(110, 100, 70);
  strokeWeight(18);
}
 
void draw() {
  strokeWeight(2);
  fill(0, 2);
  rect(0, 0, width, height);
  angle += speed; // Update the angle
  fill(155);
  // Set the position of the small circle based on new
  // values from sine and cosine
  float x = width/2 + (cos(angle) * radius);
  float y = height/3 + (sin(angle) * radius);
  ellipse(x, y, 2, 2); // Draw smaller circle
  // Set the position of the large circles based on the
  // new position of the small circle
  float x2 = x + cos(angle * sx) * radius / 2;
  float y2 = y + sin(angle * sy) * radius / 2;
  ellipse(x2, y, 12, 10); // Draw larger circle
}

Comments

Nobody has said anything yet.