Lively Kernel canvas
PropertiesMorphsarethevisualobjectswhichmaketheLivelyKernelsolively.EveryMorphhasasetofbasicpropertiesincludingthingslikeitsposition(inrelationtoitsownermorph),extent,rotation,andcoloraswellasmethodstoreadandwritethoseproperties(get/setPosition.get/setExtent,get/setRotation,get/setFillandsoon).CreateamorphbyevaluatingMorph.makeRectangle(newRectangle(50,100,80,80)).openInWorld()andopenaninspectorforit(alt+clickonthenewlycreatedMorphandchooseinspect).InthebottompartoftheinspectoryoucanwriteandevaluateJavaScriptcode.Thevariablethisintheinspectorisboundtothecurrentlyinspectedmorph.TrytochangetheMorph'spropertieswiththeexpressionsoftheboxtotheright(bycopyingandpastingthemintotheinspector).SubmorphsEverymorphcanhaveanarbitrarynumberofsubmorphsandoneownermorph.TherootMorphinthevisiblehierarchyofMorphsisaWorldMorph(WorldMorph.current()).EveryMorphwhichisaddedtotheWorldMorphandinsideitsboundsisvisible(aslongasitisbigenough,hasnon-transparentfillandsoon).Trythefollowingexpressionsoftheboxtotherightstepbystep.SteppingscriptsToanimateMorphstheycanbetoldtorunamethodinregulartimeintervals.Tryoutevaluatingtheexpressionsoftheboxbelowstepbystep.20
Morphic30
morph1=Morph.makeRectangle(newRectangle(50,100,80,80));morph2=Morph.makeRectangle(newRectangle(20,20,40,40));WorldMorph.current().addMorph(morph1);morph1.addMorph(morph2);morph1.moveBy(pt(50,0));morph1.setRotation(Math.PI/4);morph1.setFill(Color.green);morph1.remove();9
this.setPosition(pt(0,0));this.setRotation(Math.PI/2);this.setExtent(this.getExtent().scaleBy(2));this.setFill(Color.red);this.moveBy(pt(10,1));this.remove();5
//CreateanewsubclassofmorphwithtwonewmethodsBoxMorph.subclass('MyOwnMorph',{moveRight:function(){this.moveBy(pt(15,0))},startSteppingScripts:function(){this.startStepping(1000,"moveRight");//callmoveRighteverysecond}});morph=newMyOwnMorph(newRectangle(50,100,80,80));morph.openInWorld();morph.startSteppingScripts();morph.remove();3
Next22
Previous22
Wikicontroltruetruenull31