SHARE
TWEET

Untitled

a guest Nov 12th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var NUM_CIRCLES = 3;
  2. var RADIUS = 30;
  3. var curElem = null;
  4.  
  5. function start(){
  6.     drawCircles();
  7.     mouseDownMethod(mouseDown);
  8.     mouseDragMethod(drag);
  9.     mouseUpMethod(mouseUp);
  10. }
  11.  
  12. function mouseDown(e){
  13.     var elem = getElementAt(e.getX(), e.getY());
  14.     curElem = elem;
  15. }
  16.  
  17. function drag(e){
  18.     if(curElem != null){    
  19.         curElem.setPosition(e.getX(), e.getY());
  20.     }
  21. }
  22.  
  23. function mouseUp(e){
  24.     curElem = null;
  25. }
  26.  
  27. function drawCircles(){
  28.     for (var i = 0; i < NUM_CIRCLES; i++) {
  29.         var circle = new Circle(RADIUS);
  30.         var x = Randomizer.nextInt(RADIUS, getWidth() - RADIUS);
  31.         var y = Randomizer.nextInt(RADIUS, getHeight() - RADIUS);
  32.         circle.setPosition(x, y);
  33.         circle.setColor(Randomizer.nextColor());
  34.         add(circle);
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top