Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import flash.display.Graphics;
- import flash.display.Sprite;
- class Point extends flash.geom.Point {
- public function new(x,y) {
- super(x,y);
- }
- public function mid(pt2:Point) {
- return new Point((pt2.x+x)/2, (pt2.y+y)/2);
- }
- }
- class Sierpinsky extends Sprite {
- public var w:Int;
- public var h:Int;
- public function new() {
- super();
- flash.Lib.current.addChild(this);
- w = flash.Lib.current.stage.stageWidth;
- h = flash.Lib.current.stage.stageHeight;
- }
- public function triangle(a:Point, b:Point, c:Point) {
- graphics.moveTo(a.x, a.y);
- graphics.lineStyle(1);
- graphics.lineTo(b.x, b.y);
- graphics.lineTo(c.x, c.y);
- graphics.lineTo(a.x, a.y);
- }
- public function sier(a:Point, b:Point, c:Point, iter:Int) {
- if(iter == 0) {
- return ;
- }
- triangle(a.mid(b),b.mid(c),c.mid(a));
- sier(a.mid(b), b, b.mid(c), iter-1);
- sier(a.mid(b), a, a.mid(c), iter-1);
- sier(b.mid(c), a.mid(c), c, iter-1);
- }
- public static function main() {
- var s = new Sierpinsky();
- s.triangle(new Point(s.w / 2, 0), new Point(s.w,s.h), new Point(0,s.h));
- s.sier(new Point(s.w / 2, 0), new Point(s.w,s.h), new Point(0,s.h), 7);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement