Skip to content

Instantly share code, notes, and snippets.

@technosophos
Created December 20, 2014 17:26
Show Gist options
  • Select an option

  • Save technosophos/0e743e51ab94c8f814e9 to your computer and use it in GitHub Desktop.

Select an option

Save technosophos/0e743e51ab94c8f814e9 to your computer and use it in GitHub Desktop.
BonsaiJS Christmas Tree
treegreen = color('green');
new Text('Merry Christmas').addTo(stage).attr({
fontFamily: 'Arial, sans-serif',
fontSize: '48',
textFillColor: 'red',
textStrokeColor: 'green',
textStrokeWidth: 2,
x: -400
}).animate('2s', {x:150, y:50}, {
easing: "bounceIn"
});
new Text('From the Butchers').addTo(stage).attr({
fontFamily: 'Arial, sans-serif',
fontSize: '48',
textFillColor: 'red',
textStrokeColor: 'green',
textStrokeWidth: 2,
x: -400
}).animate('2s', {x:170, y:90}, {
delay: '3s',
easing: "bounceIn"
});
// The tree is three triangles.
tier1 = new Polygon(150, 150, 40, 3);
tier1.fill(treegreen);
tier1.attr('filters', new filter.DropShadow(1, 1, 2, 0x000000FF));
tier2 = new Polygon(150, 190, 60, 3);
tier2.fill(treegreen);
tier2.attr('filters', new filter.DropShadow(1, 1, 2, 0x000000FF));
tier3 = new Polygon(150, 230, 80, 3);
tier3.fill(treegreen);
tier3.attr('filters', new filter.DropShadow(1, 1, 2, 0x000000FF));
// The trunk
trunk = new Rect(142, 270, 20, 25);
trunk.fill(color('brown').darker());
trunk.attr('filters', new filter.DropShadow(1, 1, 2, 0x000000FF));
// The star on top
pretty = new Star(150, 108, 20, 5);
pretty.fill('yellow').stroke('orange',1);
pretty.attr('filters', new filter.DropShadow(1, 1, 2, 'orange'));
// Make the star twinkle
sparkle = new KeyframeAnimation('3s', {
'0%': {fillColor: 'white', strokeColor: 'yellow'},
'50%': {fillColor: 'yellow', strokeColor: 'orange'},
'100%': {fillColor: 'orange', strokeColor: 'yellow'}
});
sparkle.repeat = Infinity;
pretty.animate(sparkle);
// Add it all.
trunk.addTo(stage);
tier3.addTo(stage);
tier2.addTo(stage);
tier1.addTo(stage);
pretty.addTo(stage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment