iso
♥0 |
Line 45 |
Modified 2012-11-10 22:40:21 |
MIT License
archived:2017-03-20 15:33:53
ActionScript3 source code
/**
* Copyright lizhi ( http://wonderfl.net/user/lizhi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/HBgb
*/
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.Point;
/**
* ...
* @author lizhi http://game-develop.net/
*/
public class TestGrid extends Sprite
{
private var shape:Shape = new Shape;
public function TestGrid()
{
for (var x:int = 0; x < 10;x++ ) {
for (var y:int = 0; y < 10;y++ ) {
var p:Point = toP(x, y);
graphics.lineStyle(0);
graphics.drawCircle(p.x*20+200, p.y*20+100, 2);
}
}
addChild(shape);
stage.addEventListener(MouseEvent.CLICK, stage_click);
}
private function stage_click(e:MouseEvent):void
{
shape.graphics.clear();
shape.graphics.lineStyle(0, 0xff0000);
var x:Number = (mouseX - 200) / 20;
var y:Number = (mouseY - 100) / 20;
p = fromP(x, y);
x = p.x;
y = p.y;
for (var i:int = x; i <= x+1;i++ ) {
for (var j:int = y; j<=y+1;j++ ) {
var p:Point = toP(i, j);
shape.graphics.drawCircle(p.x*20+200, p.y*20+100, 2);
}
}
}
public function toP(x:Number, y:Number):Point {
return new Point(x - y, (x + y) * .5);
}
public function fromP(sx:Number, sy:Number):Point {
return new Point(sy + sx * .5, sy - sx * .5);
}
}
}