Lively Kernel canvas getRandomNumber = function(max) { return Math.floor(Math.random()*max+1)-1}; getRandomPoint = function(maxX, maxY) { return pt(getRandomNumber(maxX), getRandomNumber(maxY)) }; getRandomPtFromRect = function(r) { return getRandomPoint(r.width, r.height).addPt(r.topLeft())} // this script is evaluated on world load10Math.PI/2function($super) { // call the initialize of ImageMorph with the mouse picture $super(new Rectangle(45, 45, 49, 49), 'http://livelykernel.sunlabs.com/repository/lively-wiki/mouse.png'); // move position to the center of the morph instead of top left corner, nicer rotating behavior this.moveOriginBy(this.getExtent().scaleBy(0.5)); // remove the blue background this.setFill(null); }function() { var p = this.getPosition(); var angle = this.getRotation()+Math.PI*(1/2); var r = this.howFarCanIGoWithOneStep; return pt(p.x+r*Math.cos(angle), p.y+r*Math.sin(angle)); }function() { this.mayBeChangeDirection(); var newPos = this.calculateNewPosition(); // while (!WorldMorph.current().bounds().containsRect(this.bounds().translatedBy(newPos))) { var activeBounds = pt(document.body.clientWidth, document.body.clientHeight).subPt(this.getExtent()).extentAsRectangle(); var i=0; while (!activeBounds.containsPoint(newPos)) { this.newDirection(); newPos = this.calculateNewPosition(); i++; if (i>100) newPos = pt(100,100); } this.setPosition(newPos); this.eatCheese(); }function() { if (getRandomNumber(10) == 5) this.newDirection() }function() { this.rotateBy(getRandomNumber(this.maxTurn*100)/100 - this.maxTurn/2); }function() { this.startStepping(20, 'moveOneStep') }function() { this.owner.submorphs .select(function(ea) { return ea.isCheese && this.bounds().intersect(ea.bounds()) }, this) .forEach(function(ea) { ea.remove(); console.log('Hmmm, delicious!') }); } null 20 96.34192912390125 3.0775931533037197 null 20 78.41351514659594 0.279661426775583 null 20 86.48543665921409 0.5459463500280475 20 75.34684585854299 -2.0444045012381413 20 74.90277221925506 -2.4750397760428875 null 20 70.05796478934121 -0.9273218541233041 20 64.34129289020576 -1.5902632123409537 null 20 66.6068349040763 2.8672724463908805 true null 20 64.67568800775479 2.437602086459524 null 20 69.99124815313807 1.1413383744046215 null 20 73.22173132218943 -1.3224822075797276 20 65.84978310759277 -1.5342434492480088 null 20 85.39440066977774 -3.173454658541457 null 20 70.82440138040604 3.2536972104359374 null 20 64.22739295748455 -3.091509756618013 null 20 87.63708893504439 -1.0876199527711148 null 20 72.60213870078906 0.7345929034467744 null 20 66.61961071812976 2.1227322955625594 20 80.89662855099421 -1.9195799268712426 20 78.4797901882809 2.113697210435931 null 20 62.02354168621909 0.6271655440866116 null 20 80.26393290442962 2.7630228581220018 20 67.14764410451868 3.108850027804004 20 78.15473951813904 -1.1533628284138637 null 20 75.48831059348937 0.9563616812033856 20 89.15438459744401 -0.40008569110669157 null 20 72.07898697514608 -0.9231867042470365 20 76.1124048701892 -0.9350473121312415 null 20 77.29736526563791 -2.0378954431538667 20 76.25294838287726 -1.9794730245669712 20 64.88611591568045 -1.638523181870281 null 20 65.2799530334691 1.0489267857549023 null 20 87.18414073376357 1.5486437592837896 null 20 68.7429773259799 -3.153018116168554 20 71.12374995908442 0.5702439489619351 null 20 88.10452004785222 2.4172498381258656 null 20 62.891848320688055 -1.9459430051420616 null 20 68.62152352735383 0.5438733346027587 null 20 71.11404509652587 1.7000828969717865 null 1251921136166 11488 1 14 null 1251921136