commented: flash on 2016-8-8
forked from flash on 2016-8-8 (diff: 25)
ActionScript3 source code
/**
* Copyright hemingway ( http://wonderfl.net/user/hemingway )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/Ah1E
*/
// forked from mutantleg's flash on 2016-8-8
package {
import flash.events.Event;
import flash.geom.Rectangle;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
skin = new BitmapData(32,32,false,0);
skin.noise(2);
skin.fillRect(new Rectangle(0,0,32,2), 0xFF);
skin.fillRect(new Rectangle(0,30,32,2), 0xFF);
skin.fillRect(new Rectangle(0,0,2,32), 0xFF);
skin.fillRect(new Rectangle(30,0,2,32), 0xFF);
skin.fillRect(new Rectangle(14,14,4,4), 0);
skin.setPixel(1,1,0xFFffFF);
vecVert = Vector.<Number>([0,0, 0,0, 0,0, 0,0]);
vecUv = Vector.<Number>([0,0, 0,0, 0,0, 0,0]);
//viewport is made up of two triangles, remove '2,1,3' from vecFace parameters to see
vecFace= Vector.<int>([0,1,2, 2,1,3]);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var skin:BitmapData;
public var vecVert:Vector.<Number>;
public var vecUv:Vector.<Number>;
public var vecFace:Vector.<int>;
public function onEnter(e:Event):void {
graphics.clear();
graphics.lineStyle(2, 0);
//drawTriagnles viewport
vecVert[0] =0; vecVert[1] =0; //top-left
vecVert[2] =465; vecVert[3] =0; //top-right
vecVert[4] =0; vecVert[5] =465; //bottom-left
vecVert[6] =465; vecVert[7] =465; //bottom-right
var ax:Number; var ay:Number;
ax = stage.mouseX;
ay = stage.mouseY;
//for centering texture on mouse
ax = ((ax/465)*2)-0.5;
ay = ((ay/465)*2)-0.5;
//texture coordiantes using our modified mouse position (texture will move with mouse)
vecUv[0] = -ax;
vecUv[1] = -ay;
vecUv[2] = -ax+2; //change this and vecUv[7] to +1 to see how drawTriangles emulates a 3D surface
vecUv[3] = -ay;
vecUv[4] = -ax;
vecUv[5] = -ay+2;
vecUv[6] = -ax+2;
vecUv[7] = -ay+2; //change this and vecUv[2] to +1 to see how drawTriangles emulates a 3D surface
graphics.beginBitmapFill(skin, null,false, false);
graphics.drawTriangles(vecVert,vecFace,vecUv);
graphics.endFill();
}//onenter
}//classend
}