線と塗りで立方体ぽくするテスト(flash on 2009-8-19)
♥0 |
Line 46 |
Modified 2009-08-19 17:04:33 |
MIT License
archived:2017-03-20 15:25:07
ActionScript3 source code
/**
* Copyright krogue ( http://wonderfl.net/user/krogue )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tu0c
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.display.Graphics;
public class Cubes extends Sprite {
public function Cubes() {
const cols:int = 7; // 表示列数
const rows:int = 7; // 表示行数
const size:int = 30; // 一つのCubeの横幅
const marginLeft:int = 10; // Cube同士の間隔(左右)
const marginTop:int = 10; // Cube同士の間隔(上下)
for (var i:int = 0; i < rows; i++) {
for (var j:int = 0; j < cols; j++) {
var s:Shape = addChild(new Shape()) as Shape;
drawCube(s.graphics, j * (size + marginLeft), i * (size + marginTop), size);
}
}
}
private function drawCube(g:Graphics, x:int, y:int, width:int):void {
const bs:int = width / 2;
const bx:int = x;
const by:int = y + bs * Math.sqrt(3);
// draw top
g.beginFill(0xFF0000);
g.moveTo(bx, by);
g.lineTo(bx + bs, by - bs / Math.sqrt(3));
g.lineTo(bx + 2 * bs, by);
g.lineTo(bx + bs, by + bs / Math.sqrt(3));
g.lineTo(bx, by);
g.endFill();
// draw left
g.beginFill(0x00FF00);
g.moveTo(bx, by);
g.lineTo(bx + bs, by + bs / Math.sqrt(3));
g.lineTo(bx + bs, by + bs * 3 / Math.sqrt(3));
g.lineTo(bx, by + bs * 2 / Math.sqrt(3));
g.lineTo(bx, by);
g.endFill();
// draw right
g.beginFill(0x0000FF);
g.moveTo(bx + bs, by + bs / Math.sqrt(3));
g.lineTo(bx + 2 * bs, by);
g.lineTo(bx + 2 * bs, by + bs * 2 / Math.sqrt(3));
g.lineTo(bx + bs, by + bs * 3 / Math.sqrt(3));
g.lineTo(bx + bs, by + bs / Math.sqrt(3));
g.endFill();
}
}
}