Guest User

Untitled

a guest
Aug 22nd, 2019
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Follow 1
  3. * based on code from Keith Peters.
  4. *
  5. * A line segment is pushed and pulled by the cursor.
  6. */
  7.  
  8. float x = 100;
  9. float y = 100;
  10. float angle1 = 0.0;
  11. float segLength = 50;
  12.  
  13. void setup() {
  14. size(640, 360);
  15. strokeWeight(20.0);
  16. stroke(255, 100);
  17. }
  18.  
  19. void draw() {
  20. background(0);
  21.  
  22. float dx = mouseX - x;
  23. float dy = mouseY - y;
  24. angle1 = atan2(dy, dx);
  25. x = mouseX - (cos(angle1) * segLength);
  26. y = mouseY - (sin(angle1) * segLength);
  27.  
  28. segment(x, y, angle1);
  29. ellipse(x, y, 20, 20);
  30. }
  31.  
  32. void segment(float x, float y, float a) {
  33. pushMatrix();
  34. translate(x, y);
  35. rotate(a);
  36. line(0, 0, segLength, 0);
  37. popMatrix();
  38. }
RAW Paste Data