forked from: flash on 2011-5-6
thought I might try making an all-white version for MIUI
ended up not using it though
edit: bigger
/**
* Copyright wh0 ( http://wonderfl.net/user/wh0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nnik
*/
// forked from wh0's flash on 2011-5-6
package {
import flash.net.FileReference;
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.utils.*;
import com.adobe.images.PNGEncoder;
public class FlashTest extends Sprite {
private var sh:Shape;
private var ba:ByteArray;
public function FlashTest() {
var cx:Number = 13.5;
var cy:Number = 13.5;
var g:Graphics = init();
stroke(g, 2);
arc(g, cx, cy, 12.5, 150, 330, false, 6);
stroke(g, 3);
arc(g, cx, cy, 12, 330, 390, false, 2);
stroke(g, 1);
for (var i:int = 5; i <= 13; i++) {
var t:Number = i * 30;
sincos(g, t, 13.5, cx, cy, false);
sincos(g, t, 9, cx, cy, true);
}
g.lineStyle();
fill(g);
g.drawCircle(cx, cy, 2.25);
g.endFill();
fill(g);
sincos(g, 210, 1.25, cx, cy, false);
sincos(g, 300, 9, cx, cy, true);
sincos(g, 30, 1.25, cx, cy, true);
preview();
}
private function fill(g:Graphics):void {
g.beginFill(0xffffff);
}
private function stroke(g:Graphics, thickness:Number=1):void {
g.lineStyle(thickness, 0xffffff, 1, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER, 4);
}
private function arc(g:Graphics, cx:Number, cy:Number, r:Number, t0:Number, t1:Number, c:Boolean=true, d:int=4):void {
sincos(g, t0, r, cx, cy, c);
var dt:Number = (t1 - t0) / d;
var r2:Number = r / Math.cos(dt / 360 * Math.PI);
for (var i:int = 0; i < d; i++) {
var ta:Number = t0 + (i + 0.5) * dt;
var tb:Number = t0 + (i + 1) * dt;
g.curveTo(cos(ta, r2, cx), sin(ta, r2, cy), cos(tb, r, cx), sin(tb, r, cy));
}
}
private function sincos(g:Graphics, deg:Number, r:Number, cx:Number, cy:Number, c:Boolean=false):void {
(c ? g.lineTo : g.moveTo)(cos(deg, r, cx), sin(deg, r, cy));
}
private function cos(deg:Number, amp:Number=1, zero:Number=0):Number {
return Math.cos(deg / 180 * Math.PI) * amp + zero;
}
private function sin(deg:Number, amp:Number=1, zero:Number=0):Number {
return Math.sin(deg / 180 * Math.PI) * amp + zero;
}
private function init():Graphics {
graphics.beginFill(0x000000);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
graphics.lineStyle(0, 0x202020);
var i:int;
for (i = 4; i <= 465; i += 12) {
graphics.moveTo(i, 0);
graphics.lineTo(i, 465);
graphics.moveTo(0, i);
graphics.lineTo(465, i);
}
graphics.lineStyle(0, 0x00ff00);
graphics.drawRect(64, 64, 324, 324);
sh = new Shape();
sh.scaleX = 12;
sh.scaleY = 12;
sh.x = 64;
sh.y = 64;
addChild(sh);
stage.addEventListener(MouseEvent.CLICK, save);
return sh.graphics;
}
private function preview():void {
var back:Shape = new Shape();
back.graphics.beginFill(0x000000);
back.graphics.drawRect(0, 0, 38, 38);
addChild(back);
var bd:BitmapData = new BitmapData(27, 27, true, 0x00000000);
bd.draw(sh, null, null, null, null, true);
ba = PNGEncoder.encode(bd);
var b:Bitmap = new Bitmap(bd);
b.x = 5;
b.y = 5;
addChild(b);
}
private function save(e:MouseEvent):void {
new FileReference().save(ba, 'icon.png');
}
}
}