Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. float prevX, prevY;
  2. PGraphics canvas;
  3. float goldenRatio = 1.61803398875;
  4.  
  5. void setup() {
  6. size(400, 400, P2D);
  7. background(0);
  8. canvas = createGraphics(width, height, P2D);
  9. canvas.beginDraw();
  10. canvas.background(0);
  11. canvas.endDraw();
  12. }
  13.  
  14. void draw() {
  15. //get some x and y coordinates that go in a circle with time
  16. float t = frameCount*.05f;
  17. float radius = min(width, height)*.3;
  18. float originR = radius*.3;
  19. float originX = originR*cos(t*goldenRatio);
  20. float originY = originR*sin(t*goldenRatio);
  21. float x = originX+radius*cos(t); // polar to cartesian conversion
  22. float y = originY+radius*sin(t);
  23.  
  24. if (prevX != 0 && prevY != 0) {
  25. canvas.beginDraw(); // no background is drawn over the canvas so that every line on it stays drawn
  26. canvas.translate(canvas.width/2, canvas.height/2); //move canvas origin to canvas center
  27. canvas.stroke(255);
  28. canvas.strokeWeight(2);
  29. canvas.line(x, y, prevX, prevY); //draw a line between this and the last wobbly coordinate
  30. canvas.endDraw();
  31. }
  32. prevX = x; //remember this position as the next last position
  33. prevY = y;
  34.  
  35. translate(width/2, height/2); //move main matrix origin to center of window
  36. strokeWeight(2);
  37. fill(0);
  38. stroke(255);
  39. pushMatrix();
  40. rotate(-t); //rotate backwards around center, comment this to see lines being drawn by a moving pen on a stationary canvas
  41. imageMode(CENTER);
  42. image(canvas, 0, 0); //draw rotated canvas as the background
  43. ellipse(0, 0, originR*2, originR*2);
  44. line(x, y, originX, originY); //the same rotation is used for the pen so that it appears stationary rotation-wise
  45. ellipse(originX, originY, 10, 10);
  46. popMatrix();
  47.  
  48. if(t < 20*TWO_PI){
  49. //saveFrame("capture/####.jpg");
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement