Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const ELLIPSE_SIZE = 100;
  2. const CANVAS_SIZE = 500;
  3.  
  4. let x, y, velX, velY;
  5.  
  6. // Draw an ellipse that travels diagonally from the top left corner of the canvas to the bottom right
  7. function topLeftToBottomRight() {
  8.     x = -50;
  9.     y = -50;
  10.     velX = 5;
  11.     velY = 5;
  12. }
  13.  
  14. // Draw an ellipse that travels diagonally from the top right corner of the canvas to the bottom left
  15. function topRightToBottomLeft() {
  16.     x = 550;
  17.     y = -50;
  18.     velX = -5;
  19.     velY = 5;
  20. }
  21.  
  22. // Draw an ellipse that travels vertically from the bottom centre of the canvas to the top centre of the canvas.
  23. function bottomCenterToTopCenter() {
  24.     x = 250;
  25.     y = 550;
  26.     velX = 0;
  27.     velY = -5;
  28. }
  29.  
  30. function setup() {
  31.     createCanvas(CANVAS_SIZE, CANVAS_SIZE);
  32.     fill(0);
  33.     topLeftToBottomRight();
  34. }
  35.  
  36. function draw() {
  37.     background(255);
  38.     x += velX;
  39.     y += velY;
  40.     ellipse(x, y, ELLIPSE_SIZE, ELLIPSE_SIZE);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement