Skip to content

Instantly share code, notes, and snippets.

@hushin
Created December 13, 2012 16:01
Show Gist options
  • Save hushin/4277431 to your computer and use it in GitHub Desktop.
Save hushin/4277431 to your computer and use it in GitHub Desktop.
xjsfl.init(this); //xJSFL init
clear(); //出力パネルをクリア
deleteAllLayers(); //タイムラインにあるフレームなどすべて消す
for (var i = 0; i < 10; i++)
{
//描いてはフレームを進める
draw();
$timeline.insertKeyframe(i);
}
draw();
function deleteAllLayers()
{
function layerCallback(layer, index)
{
$timeline.deleteLayer(index)
}
Iterators.layers(Context.create(), layerCallback);
}
function draw()
{
$('*').deleteElements(); //既に描かれているものを消す
makeSquares(30); //四角を何個か描く
//色をランダムに変える
function randColor()
{
return "#" + (new HSV(Math.random(), 0.7, 0.8)).toHex();
}
$('*').reach(
function (element, index, elements)
{
$dom.selectNone();
$dom.selection = [element];
$dom.setInstanceTint(randColor(), 100);
}).refresh();
//位置などをランダムで変える
$('*').attr('rotation', function ()
{
return Math.random() * 90;
})
.attr('position', function ()
{
return [Math.random() * $dom.width, Math.random() * $dom.height];
})
.attr('scale', function ()
{
return Math.random() + 0.2;
})
.refresh();
}
function makeSquares(num, cols)
{
// variables
num = num || 9;
cols = cols || 3;
var dom = $dom;
var lib = $library;
var context = Context.create();
// make square
if (!lib.itemExists('square'))
{
lib.addNewItem('movie clip', 'square');
lib.editItem('square');
dom.addNewRectangle(
{
left: -25,
top: -25,
right: 25,
bottom: 25
}, 0);
dom.selectAll();
dom.setFillColor('#FF000066');
dom.setStroke('#000000', 0.5, 'solid')
context.goto();
}
// add items to scene
var collection = $('*');
for (var i = 0; i < num; i++)
{
var x = i % cols;
var y = (i - x) / cols;
var name = 'Item_' + Utils.pad(i + 1, 2, '0');
if (collection.find(name).length == 0)
{
trace(name);
lib.addItemToDocument(
{
x: (x * 50) + 50,
y: (y * 50) + 50
}, 'square');
$selection[0].name = name;
}
}
dom.selectNone();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment