Facebook
From joe, 1 Year ago, written in JavaScript.
This paste is a reply to Re: Untitled from Idiotic Sloth - view diff
Embed
Download Paste or View Raw
Hits: 138
  1. let x = 320;
  2. let y = 180;
  3. let xspeed = 5;
  4. let yspeed = 2;
  5.  
  6. let r = 25;
  7.  
  8. function setup() {
  9.   createCanvas(640, 360);
  10. }
  11.  
  12. function draw() {
  13.   background(0);
  14.  
  15.  
  16.   let d = dist(x, y, mouseX, mouseY);
  17.   if(d > 25){
  18.     fill(255,0,0)
  19.   }else{
  20.     fill(0,0,255)
  21.   }
  22.   ellipse(x, y, r*2, r*2);
  23.  
  24.  
  25.   // console.log(d)
  26.   x += xspeed;
  27.   y += yspeed;
  28.   if (x > width - r || x < r) {
  29.     xspeed = -xspeed;
  30.   }
  31.   if (y > height - r || y < r) {
  32.     yspeed = -yspeed;
  33.   }
  34.  
  35.  
  36. }