Difference between revisions of "Today"

From CodeStuff
Jump to: navigation, search
Line 16: Line 16:
  
  
<edcode>var c={x:320, y:240, lastx:320, lasty:240, power:0.1, penSize:4};
+
<edcode>var c = {x:320, y:240, lastx:320, lasty:240, power:0.1, penSize:4};
  
var maryx=200;
+
var mary = {x:200, y:240};
var maryy=240;
+
var frank = {x:380, y:240};
 +
var bob = {x:580, y:100};
  
var frankx=380;
+
var chasers = [mary,frank,bob];
var franky=240;
+
  
 
function drawSpot(x,y) {
 
function drawSpot(x,y) {
Line 29: Line 29:
 
   setColour("yellow");
 
   setColour("yellow");
 
   fillCircle(x,y,7);
 
   fillCircle(x,y,7);
+
}
 +
 
 +
function moveTowards(seeker,target) {
 +
  if (seeker.y < target.y) {
 +
    seeker.y+=0.3;
 +
  }
 +
 
 +
  if (seeker.y > target.y) {
 +
    seeker.y-=0.3;
 +
  }
 +
 
 +
  if (seeker.x <target.x) {
 +
    seeker.x+=0.3;
 +
  }
 +
 
 +
  if (seeker.x > target.x) {
 +
    seeker.x-=0.3;
 +
  }
 +
 
 
}
 
}
  
Line 79: Line 97:
 
    
 
    
 
   //move mary towards c
 
   //move mary towards c
  if (maryy < c.y) {
+
   moveTowards(mary,c);
    maryy+=0.3;
+
  }
+
    
+
  if (maryy > c.y) {
+
    maryy-=0.3;
+
  }
+
 
+
  if (maryx <c.x) {
+
    maryx+=0.3;
+
  }
+
 
+
  if (maryx > c.x) {
+
    maryx-=0.3;
+
  }
+
 
+
 
   //move frank towards c
 
   //move frank towards c
  if (franky < c.y) {
+
  moveTowards(frank,c);
    franky+=0.3;
+
   //move bob towards c
   }
+
  moveTowards(bob,c);
 
    
 
    
  if (franky > c.y) {
 
    franky-=0.3;
 
  }
 
 
 
  if (frankx <c.x) {
 
    frankx+=0.3;
 
  }
 
 
 
  if (frankx > c.x) {
 
    frankx-=0.3;
 
  }
 
 
 
   clear();
 
   clear();
 
      
 
      
Line 117: Line 108:
 
   fillCircle(c.x,c.y,c.penSize);
 
   fillCircle(c.x,c.y,c.penSize);
  
   drawSpot(maryx,maryy);
+
   drawSpot(mary.x,mary.y);
   drawSpot(frankx,franky);
+
   drawSpot(frank.x,frank.y);
 +
  drawSpot(bob.x,bob.y);
 
   
 
   
 +
  setColour("black");
 +
  print(":-)");
 
}
 
}
  
 
run(move);
 
run(move);
 +
 
</edcode>
 
</edcode>

Revision as of 07:58, 3 July 2017

Useful things to refer to.

The API page has a list of some of the functions you can use such as