flash on 2011-1-24
♥0 |
Line 54 |
Modified 2011-01-24 22:51:14 |
MIT License
archived:2017-03-20 07:45:16
ActionScript3 source code
/**
* Copyright fakestar0826 ( http://wonderfl.net/user/fakestar0826 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7iPD
*/
package {
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private static const TEXTURE_W:uint = 320;
private static const TEXTURE_H:uint = 480;
private static const SEGMENT_W:uint = 8;
private static const SEGMENT_H:uint = 12;
private var _vertices:Vector.<Number>;
private var _indices:Vector.<int>;
private var _uvtData:Vector.<Number>;
public function FlashTest() {
// write as3 code here..
var numVertices:uint = (SEGMENT_W + 1) * (SEGMENT_H + 1) * 2;
var i:uint, x:uint, y:uint;
_vertices = new Vector.<Number>(numVertices, true);
_indices = new Vector.<int>(SEGMENT_W * (6 * SEGMENT_H), true);
_uvtData = new Vector.<Number>(numVertices, true);
var w:Number = TEXTURE_W / SEGMENT_W;
var h:Number = TEXTURE_H / SEGMENT_H;
for(x = 0; x <= SEGMENT_W;++x)
{
for(y = 0;y <= SEGMENT_H;++y)
{
i = (y * (SEGMENT_W + 1) + x) * 2;
_vertices[i] = w * x;
_vertices[i + 1] = h * y;
_uvtData[i] = _vertices[i] / TEXTURE_W;
_uvtData[i + 1] = _vertices[i + 1];
}
}
for(x = 0; x < SEGMENT_W;++x)
{
i = (x * (6 * SEGMENT_H));
for(y = 0;y < SEGMENT_H;++y)
{
_indices[i + y * 6 + 0] = (y + 0) * (SEGMENT_W + 1) + (x + 0);
_indices[i + y * 6 + 1] = (y + 0) * (SEGMENT_W + 1) + (x + 1);
_indices[i + y * 6 + 2] = (y + 1) * (SEGMENT_W + 1) + (x + 0);
_indices[i + y * 6 + 3] = (y + 0) * (SEGMENT_W + 1) + (x + 1);
_indices[i + y * 6 + 4] = (y + 1) * (SEGMENT_W + 1) + (x + 0);
_indices[i + y * 6 + 5] = (y + 1) * (SEGMENT_W + 1) + (x + 1);
}
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
graphics.clear();
graphics.beginFill(0xFF0000);
graphics.drawTriangles(_vertices, _indices, _uvtData);
graphics.endFill();
}
}
}