Actionscript:
-
// build some functions:
-
var redGradient:Function = sl(16, add(100, mult(5)));
-
-
// grid positioning
-
var xPos:Function = add(50, mult(30, cInt(div(4))));
-
var yPos:Function = add(50, mult(30, mod(4)));
-
-
// create some shapes:
-
var shapes:Array = createShapes(this, 22, [["beginFill", 0xCCCCCC], ["drawCircle", 0, 0, 10], ["endFill"], ["lineStyle",1, redGradient], ["drawRect", -5, -5, 10, 10]], {x:yPos, y:xPos, rotation:mult(10)});
-
-
function createShapes(par:DisplayObjectContainer, num:Number,
-
funcs:Array, props:Object):Array {
-
var shapes:Array = [];
-
for (var i:int = 0; i<num; i++){
-
shapes[i] = par.addChild(new Shape());
-
for (var j:int = 0; j<funcs.length; j++) {
-
var a:Array = funcs[j].concat();
-
for (var k:int = 0; k<a.length; k++){
-
if (a[k] is Function){
-
a[k] = a[k](i);
-
}
-
}
-
for (var key:String in props){
-
var v:* = props[key];
-
if (v is Function){
-
shapes[i][key] = v(i);
-
}else{
-
shapes[i][key] = v;
-
}
-
}
-
shapes[i].graphics[a[0]].apply(shapes[i].graphics, a.slice(1));
-
}
-
}
-
return shapes;
-
}
-
-
// function building blocks
-
const F:Function = function(a:*):*{return a};
-
-
function cInt(f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return int(f(n));
-
}
-
}
-
-
function mod(m:Number, f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return f(n) % m;
-
}
-
}
-
-
function div(d:Number, f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return f(n) / d;
-
}
-
}
-
-
function mult(scalar:Number, f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return f(n) * scalar;
-
}
-
}
-
-
function add(off:Number, f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return f(n) + off;
-
}
-
}
-
// shift left
-
function sl(amount:int, f:Function=null):Function{
-
if (f == null) f = F;
-
return function(n:Number):Number {
-
return f(n) <<amount
-
}
-
}
This is an unusual snippet I wrote a couple weeks back.... not sure where I was going with this really... has some interesting ideas in it.