Lively Kernel canvas
Wikicontroltruetrue
ImageMorph.subclass('Mobilan',{initialize:function($super){//calltheinitializeofImageMorphwiththemousepicture$super(newRectangle(45,45,49,49),'http://i988.photobucket.com/albums/af4/hadyan_mf/racing20car.png');//movepositiontothecenterofthemorphinsteadoftopleftcorner,nicerrotatingbehaviorthis.moveOriginBy(this.getExtent().scaleBy(0.5));//removethebluebackgroundthis.setFill(null);this.scaleBy(0.3);}});getRandomNumber=function(max){returnMath.floor(Math.random()*max+1)-1};Mobilan.addMethods({maxTurn:Math.PI/2,//defineshowabruptlythedirectioncanbechangedmayBeChangeDirection:function(){if(getRandomNumber(10)==5)this.newDirection()},newDirection:function(){this.rotateBy(getRandomNumber(this.maxTurn*100)/100-this.maxTurn/2);}});Mobilan.addMethods({moveOneStep:function(){this.mayBeChangeDirection();//changethedirectionsometimesvarp=this.getPosition();varangle=this.getRotation()+Math.PI*(1/2);//inwhichdirectiondoIlook?varr=10;//the'radius'orhowfarIcangowithonestepvarnewPos=pt(p.x+r*Math.cos(angle),p.y+r*Math.sin(angle));//stayonscreenwhile(!WorldMorph.current().bounds().containsPoint(newPos)){this.newDirection();varangle=this.getRotation()+Math.PI*(1/2);newPos=pt(p.x+r*Math.cos(angle),p.y+r*Math.sin(angle));}this.setPosition(newPos);}});mobil=newMobilan();mobil.openInWorld();mobil.startSteppingScripts();//removewhendonemobil.remove();40truetruefalsetruetruefalse
false00.11truefalsetruetruefalse
nullfalsetruenullfalse
falsenulltruefalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null6