Skip to content

Instantly share code, notes, and snippets.

@lemarcque
Last active February 10, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemarcque/6377996 to your computer and use it in GitHub Desktop.
Save lemarcque/6377996 to your computer and use it in GitHub Desktop.
package;
import flash.display.Shape;
import flash.Lib;
/**
* ...
* @author Lemarcque
* Description : Random artistic Bar color
*/
class BarColor
{
private var nbrBar:Int;
private var multiple:Bool;
private var degree:Int;
private var baseColor:UInt;
private var paletColor:Array<UInt>;
private var width:Int;
private var height:Array<Int>;
private var point:Array<Float>;
var AB:Float; var AC:Float;
var posX:Float; var posY:Float;
var marge:Float;
public static function main() { new BarColor(); }
function new(multiple:Bool = false)
{
this.multiple = multiple;
degree = 50;
baseColor = 0x070038;
paletColor = [0x070038, 0x4B315E, 0x6C246D, 0xB21D6F, 0xF81469];
width = 15;
height = [50, 20, 120, 70, 100];
point = new Array<Float>();
marge = Math.sqrt(2 * (width * width));
posX = Lib.current.stage.stageWidth - marge - 10;
posY = 10;
AB = marge;
AC = AB * Math.cos(degree);
posX += marge;
loop(posY, Lib.current.stage.stageHeight);
}
function loop(i:Float, length:Float)
{
while (i < length)
{
point = [AB, AC];
var segment:Float = Math.sqrt((point[0] * point[0]) +(point[1] * point[1]));
if (!multiple)
{
var barColor:Shape = bar(segment, 16.5);
barColor.x = posX; barColor.y = posY;
Lib.current.stage.addChild(barColor);
}else
{
segment = segment / 3;
var tierSegment = segment / 3;
var tableSegments:Array<Float> = new Array<Float>();
tableSegments.push(tierSegment + Std.random(4) * 10);
tableSegments.push(tierSegment + Std.random(3) * 10);
tableSegments.push(segment - (tableSegments[0] + tableSegments[1]));
var diagonale:Float = posX;
var verticale:Float = posY;
for (i in 0...3)
{
var barColor:Shape = bar(tableSegments[i]);
barColor.x = diagonale; barColor.y = verticale;
Lib.current.stage.addChild(barColor);
diagonale += barColor.width - 10.5;
verticale += barColor.height - 12.5;
}
}
posX -= marge;
AB += marge;
AC = AB;
i++;
}
}
function bar(height:Float, size:Float = 15):Shape
{
var pos:Int = Std.random(6);
var rect:Shape = new Shape();
rect.graphics.beginFill(paletColor[pos]);
rect.graphics.drawRect(0, 0, size, height);
rect.rotation = degree * - 1;
return rect;
}
}
-swf BarColor.swf
-main BarColor
-swf-header 500:700:24:FFFFFF
@lemarcque
Copy link
Author

For the moment it's just possible to compile on Flash target.

@lemarcque
Copy link
Author

A little refactoring of my code :p !
Two years later !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment