Make a nice Church Window

small drawing program with a robot arm with a pen at its end.

a lot of experiments possible:

  • the 2 radii
  • and the 2 speeds with which the angles change
  • color…

// A robot arm rotates with a pen at its end.
// Hold mouse to hide arm.

// Arm part 1 from middle of the screen to x1,y1, rotating.
// Arm part 2 from x1,y1 to x2,y2, rotating around x1,y1.
// pen is at x2,y2.
//

float x1, y1,
  x2, y2,
  angle1, angle2;

float angle1Speed = 0.025;
float angle2Speed = 0.0521;

float rad1 = 100; // good is 100 with 60 // or 100 with 50
float rad2 = 60;

float x2old, y2old;

ArrayList<PVector> list = new ArrayList();

// ---------------------------------------------------------------

void setup() {
  size(800, 600);
} // func

void draw() {
  background(255);

  calcData();

  if (!mousePressed) {
    // the robot arm
    showLines();
    showPoints();
  }

  // store pen drawing and display it
  list.add(new PVector(x2, y2));
  stroke(255, 0, 0);
  for (PVector pv : list) {
    rect(pv.x, pv.y, 4, 4);
  }
  //
} // func

//--------------------------------------------------------------------

void calcData() {

  x1 = width/2 + rad1 * cos(angle1);
  y1 = height/2 + rad1 * sin(angle1);

  angle1 += angle1Speed;

  x2old=x2;
  y2old=y2;

  x2 = x1 + rad2 * cos(angle2);
  y2 = y1 + rad2 * sin(angle2);

  angle2 += angle2Speed;
  // angle2Speed +=0.0001;
}

void showLines() {
  stroke(0, 255, 0);
  line(width/2, height/2,
    x1, y1);
  line(x1, y1,
    x2, y2);
}

void  showPoints() {
  stroke(0, 255, 0);
  rect(width/2, height/2, 4, 4);
  rect(x1, y1, 4, 4);
  rect(x2, y2, 4, 4);
}

wef

4 Likes