Lively Kernel canvas
pointTo = function(morph, pos) {
var delta = pos.subPt(morph.getPosition());
morph.setRotation(delta.theta()+Math.PI/2);
}
scaleGradually = function(morph, scale, steps) {
var deltaS = scale - morph.getScale();
var scaleStep = deltaS/steps;
var stepTime = 10;
var actionWhenDone = function() { this.remove() };
var grow = function(remainingSteps) {
if (remainingSteps <= 0) return actionWhenDone.apply(morph);
morph.setScale(morph.getScale()+scaleStep);
Global.setTimeout(grow.curry(remainingSteps-1), stepTime);
}
Global.setTimeout(grow.curry(steps), stepTime);
}
bumm = function(morph) {
morph.remove();
var explosion = Morph.makeCircle(morph.getPosition(), 10, 0, null, Color.random());
explosion.openInWorld();
explosion.suppressHandles = true;
scaleGradually(explosion, getRandomNumber(20)+10, 10)
}
makeRocket = function(pos) {
var m = Morph.makeRectangle(new Rectangle(0,0,5,50));
var head = Morph.makePolygon([pt(0,-10), pt(-10,2), pt(10,2)], null, null, m.getFill());
head.moveBy(m.getExtent().scaleBy(0.5).withY(0));
m.addMorph(head);
m.setPosition(pos)
m.openInWorld();
return m;
}
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())}
w = WorldMorph.current();
createAndInitRocket = function() {
var width = w.getExtent().x*2/3;
var restWidth = w.getExtent().x - width;
var targetArea = pt(restWidth/2,0).extent(pt(width,300));
var start=getRandomPoint(5,5).addXY(w.getExtent().x/2, w.getExtent().y-100);
var x = makeRocket(start);
x.launch = function() {
var target = getRandomPtFromRect(targetArea);
pointTo(this, target);
var cb = function() {
this.stopStepping();
bumm(this);
};
this.animatedInterpolateTo(target, 10, 1, cb);
}
return x;
}
startLoop = function() {
Global.setTimeout(
function() {createAndInitRocket().launch(); startLoop() },
getRandomNumber(1000)+ 2000);
};
i=3
while(i>0) {
i--;
startLoop()
}
HappyNewYear!40
0.16053.803602484363342.268146928204159
0.7161991000175476
10000.13508517176729928Wikicontroltrue
10000.1853020188851842Wikicontroltrue
null49