Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML ><html lang="en"><head><title>
- UIN_ADA
- </title></head><body></body><script> //://///////////////////://
- //://////////////////////////////////////////////////////////://
- //:GW: Global_Whatever:
- //:GWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGW://
- var GLO_DAT = null; //:GLOBAL_DATA
- var GLO_FUN = null; //:GLOBAL_FUNCTIONS
- var GLO_OBJ = null; //:GLOBAL_OBJECTS
- //:GWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGWGW://
- //://////////////////////////////////////////////////////////://
- //: Main function to execute once all script is loaded:
- function main(){
- "use strict"
- //://////////////////////////////////////////////////////://
- GLO_DAT=( INIT_GLOBAL_DATA( ) );
- Object.seal( GLO_DAT );
- GLO_FUN=( INIT_GLOBAL_FUNCTION( ) );
- Object.seal( GLO_FUN );
- GLO_OBJ=( INIT_GLOBAL_OBJECT( ) );
- Object.seal( GLO_OBJ );
- //://////////////////////////////////////////////////////://
- //:******************************************************://
- //:******************************************************://
- //:******************************************************://
- //:******************************************************://
- //[ BUF_VEW --> UIN_ADA, upgrades: ]//
- //[ 1:When pressing arrow keys, the camera will move ]//
- //[ exactly one camera in the direction of arrow press.]//
- //[ 2:Pressing "+" or "-" keys will zoom in or out ]//
- //[ by doubling or halving off-screen viewport size. ]//
- //:GLO_FUN.DoMapping_vp1_TO_vp0();
- GLO_OBJ.vp1_sna.ForceUpdate();
- //:******************************************************://
- //:******************************************************://
- //:******************************************************://
- //:******************************************************://
- };;
- //://////////////////////////////////////////////////////////://
- //:GD:Global_Data:(BELOW):-----------------------------------://
- //:GDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGD://
- function INIT_GLOBAL_DATA( ){
- "use strict"
- var til_map=( CreateTileMap(512) );
- var ini_til_wid=( til_map.map_wid );
- var ini_til_hig=( til_map.map_hig );
- var ini_can_wid = 640 ; //:ini_wid:of:Canvas
- var ini_can_hig = 640 ; //:ini_hig:of:Canvas
- //: [0]: INPUT VIEWPORT:
- var rec_vp0 ={
- x_0 : 0 + 32
- , y_0 : 0 + 32
- , x_1 : ini_can_wid - 32
- , y_1 : ini_can_hig - 32
- };; Object.seal( rec_vp0 );
- //: [1]: INPUT VIEWPORT:
- var rec_vp1 ={
- x_0 : 0 + 64
- , y_0 : 0 + 64
- , x_1 : ini_til_wid - 64
- , y_1 : ini_til_hig - 64
- };;Object.seal( rec_vp1 );
- var GLO_DAT={
- til_map : til_map
- , rec_vp0 : rec_vp0
- , rec_vp1 : rec_vp1
- , ini_can_wid : ini_can_wid //:initial_canvas_wid
- , ini_can_hig : ini_can_hig //:initial_canvas_hig
- , ini_til_wid : ini_til_wid //:initial_tilemap_wid
- , ini_til_hig : ini_til_hig //:initial_tilemap_hig
- , glo_eve : NEW_GlobalEventStruct( )
- };;
- Object.seal( GLO_DAT );
- return( GLO_DAT );
- };;
- //:GDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGDGD://
- //:GD:Global_Data:(ABOVE):-----------------------------------://
- //:GF:Global_Function:(BELOW):-------------------------------://
- //:GFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGF://
- function INIT_GLOBAL_FUNCTION( ){
- "use strict"
- var GLO_FUN ={ //:GLO_FUN:GLObal_FUNctions (container )
- //::::::::vp1_TO_vp0::::::::::::::::::vp1_TO_vp0
- DoMapping_vp1_TO_vp0 : SOTM_DoMapping_vp1_TO_vp0
- };;
- Object.seal( GLO_FUN );
- return( GLO_FUN );
- };;
- //:GFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGFGF://
- //:GF:Global_Function:(BELOW):-------------------------------://
- //:GO:Global_Objects:(OBJ==Data+Funcs):(BELOW):--------------://
- //:GOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGO://
- function INIT_GLOBAL_OBJECT( ){
- "use strict"
- //: Create a [ can / canvas ]:
- var can = attachCanvasToDom(
- GLO_DAT.ini_can_wid
- , GLO_DAT.ini_can_hig
- );;
- var GLO_OBJ={
- uin_ada : NEW_UserInputAdapterSingleton( can )
- , can_ada : NEW_CanvasAdapter( can )
- , vp1_sna : NEW_ViewportOneSnapper( )
- };;
- //: can_ada: Has pixel putting and getting functions:
- Object.seal( GLO_OBJ );
- return( GLO_OBJ );
- };;
- //:GOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGOGO://
- //:GO:Global_Objects:(OBJ==Data+Funcs):(ABOVE):--------------://
- //://////////////////////////////////////////////////////////://
- function NEW_ViewportOneSnapper( ){ //:GLO_OBJ.vp1_sna
- "use strict"
- var vp1_sna =( new ViewportOneSnapper( ) );
- Object.seal( vp1_sna );
- return( vp1_sna );
- };;
- function ViewportOneSnapper( ){ //: vp1_sna
- "use strict"
- //:V:Visible (Exported/Public) Functions:
- //:VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV://
- this.ReadEvent = ( _ReadEvent );
- this.ForceUpdate = ( _ForceUpdate );
- //:VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV://
- //:H:Hidden_Variables:
- //:HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH://
- var _ = {};
- _.til_exp = 7; //:Tile_Exponent/ViewportSize
- _.t_x = 1; //:Tile_X:Coordinate_Of_VP1_Position
- _.t_y = 1; //:Tile_Y:Coordinate_Of_VP1_Position
- Object.seal( _ );
- //:HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH://
- function _UpdateGraphics( ){
- console.log("[TODO:_UpdateGraphics]");
- GLO_FUN.DoMapping_vp1_TO_vp0();
- };;
- function _UpdateCoordinates_VP1( ){
- var map_wid = GLO_DAT.til_map.map_wid ; //:pix_wid
- var map_hig = GLO_DAT.til_map.map_hig ; //:pix_hig
- if( map_wid != map_hig ){
- throw("[DesignedForPerfectlySquareTileMaps]");
- };;
- var map_san = ( map_wid | map_hig );
- var max_exp = ( Math.log2( map_san ) );
- if( _.til_exp < 0 ){ _.til_exp = 0 ; };
- if( _.til_exp > max_exp ){ _.til_exp = max_exp; };
- var til_san=( Math.pow( 2, _.til_exp ) );//:pix_san
- //://////////////////////////////////////////////////://
- //:How big is the tilemap when measured in terms
- //:of cameras stacked ajacently next to each other
- //:until they fill entire til_map 100% without
- //:any overlap.
- //:SUMMARY:
- //: How big is the grid in camera_tiles.
- //: ( camera_tiles === til_san )
- var gri_wid = map_wid / til_san ; //:grid_wid
- var gri_hig = map_hig / til_san ; //:grid_hig
- //://////////////////////////////////////////////////://
- var m_x = ( gri_wid - 1 ); //:max_index:t_x
- var m_y = ( gri_hig - 1 ); //:max_index:t_y
- if( _.t_x < 0 ){ _.t_x = 0; }; //:LOWER_BOUND : t_x
- if( _.t_y < 0 ){ _.t_y = 0; }; //:LOWER_BOUND : t_y
- if( _.t_x > m_x){ _.t_x =m_x;};
- if( _.t_y > m_y){ _.t_y =m_y;};
- var rec_vp1 = GLO_DAT.rec_vp1;
- var x_0 = _.t_x * til_san;
- var y_0 = _.t_y * til_san;
- GLO_DAT.rec_vp1.x_0 = x_0;
- GLO_DAT.rec_vp1.y_0 = y_0;
- GLO_DAT.rec_vp1.x_1 = ( x_0 + til_san - 1 );
- GLO_DAT.rec_vp1.y_1 = ( y_0 + til_san - 1 );
- };;
- function _ReadEvent( glo_eve ){
- var key = glo_eve.key;
- var val =( 0 - 666 );
- if( 0
- || "ARR_UPP" == key
- || "ARR_DOW" == key
- || "ARR_LEF" == key
- || "ARR_RIG" == key
- ){
- if( key == "ARR_UPP" ){ _SnapMoveVP1_UPP( ); }else
- if( key == "ARR_DOW" ){ _SnapMoveVP1_DOW( ); }else
- if( key == "ARR_LEF" ){ _SnapMoveVP1_LEF( ); }else
- if( key == "ARR_RIG" ){ _SnapMoveVP1_RIG( ); }else
- {
- //:EDCL:Expected_Dead_Code_Line:
- throw("[EDCL:EXPECTED_ONE_OF_FOUR_KEYS_ABOVE]");
- };;
- _Update();
- };;
- if( 0
- || "+" == key
- || "=" == key
- || "-" == key
- || "_" == key
- ){
- if( "+"==key || "="==key ){
- //:ZOOM_IN
- _.til_exp =( _.til_exp - 1 );
- };;
- if( "-"==key || "_"==key ){
- //:ZOOM_OUT:
- _.til_exp =( _.til_exp + 1 );
- };;
- _Update();
- };;
- };;
- function _Update(){
- _UpdateCoordinates_VP1();
- _UpdateGraphics();
- };;
- function _ForceUpdate( ){
- _Update();
- };;
- function _SnapMoveVP1_UPP( ){
- _.t_y =( _.t_y - 1 );
- console.log("_SnapMoveVP1_UPP");
- };;
- function _SnapMoveVP1_DOW( ){
- _.t_y =( _.t_y + 1 );
- console.log("_SnapMoveVP1_DOW");
- };;
- function _SnapMoveVP1_LEF( ){
- _.t_x =( _.t_x - 1 );
- console.log("_SnapMoveVP1_LEF");
- };;
- function _SnapMoveVP1_RIG( ){
- _.t_x =( _.t_x + 1 );
- console.log("_SnapMoveVP1_RIG");
- };;
- };;
- //://////////////////////////////////////////////////////////://
- function NEW_UserInputAdapterSingleton( can /**canvas**/ ){
- "use strict"
- var uin_ada=( new UserInputAdapterSingleton( can ) );
- Object.seal( uin_ada );
- return( uin_ada );
- };;
- function UserInputAdapterSingleton(
- can /** html5_canvas **/
- ){
- "use strict"
- //:Private Variables:
- //:PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP://
- var _ = {};
- _.can = null;
- //:PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP://
- function _Constructor( can ){
- if(!can){throw("[ERR:2020_05_08:0303PM]");};
- _.can = can;
- _.can.addEventListener(
- "click" //:<------------ TypeOfEventAsString
- , _NativeClickEventHandler //:Callback_Function
- );;
- document.addEventListener(
- "keydown" //:<----------- TypeOfEventAsString
- , _NativeKeyboardEventHandler //:Callback_Function
- );;
- };;
- function _NativeKeyboardEventHandler( nat_eve ){
- var glo_eve = GLO_DAT.glo_eve;
- //://////////////////////////////////////////////////://
- //:Store keyboard key that was pressed:
- //://////////////////////////////////////////////://
- var key = nat_eve.key.toUpperCase( );
- if( "ARROWLEFT" == key ){ key = "ARR_LEF"; };
- if( "ARROWRIGHT" == key ){ key = "ARR_RIG"; };
- if( "ARROWUP" == key ){ key = "ARR_UPP"; };
- if( "ARROWDOWN" == key ){ key = "ARR_DOW"; };
- glo_eve.key = key;
- //://////////////////////////////////////////////://
- GLO_OBJ.vp1_sna.ReadEvent( glo_eve );
- console.log( glo_eve );
- //://////////////////////////////////////////////////://
- };;
- function _NativeClickEventHandler( nat_eve ){
- var glo_eve = GLO_DAT.glo_eve;
- //://////////////////////////////////////////////////://
- var rec =( _.can.getBoundingClientRect() );
- var CAN_X=( nat_eve.clientX - rec.left );
- var CAN_Y=( nat_eve.clientY - rec.top );
- glo_eve.c_x=( CAN_X ); //:Click_X
- glo_eve.c_y=( CAN_Y ); //:Click_Y
- //://////////////////////////////////////////////////://
- console.log("[CLICKITY_CLICK]");
- };;
- _Constructor( can );
- };;
- //://////////////////////////////////////////////////////////://
- function NEW_GlobalEventStruct( /** void **/ ){
- "use strict"
- var glo_eve ={
- TYP : "glo_eve"
- //: sub_typ : "mouse_event" or "keyboard_event" ?
- //:KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK://
- , key : "" //:What key was pressed?
- , k_d : 0 //:IsKeyCurrentlyDown?
- , k_u : 0 //:IsKeyCurrentlyUp?
- //:KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK://
- //:M:Mouse Event Stuff:
- //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
- , m_x : 0 //:Mouse x
- , m_y : 0 //:Mouse y
- , c_x : 0 //:Mouse CLICK: x
- , c_y : 0 //:Mouse CLICK: y
- , u_x : 0 //:Mouse UP ( u_x == "Up X" )
- , u_y : 0 //:Mouse UP ( u_y == "Up Y" )
- , d_x : 0 //:Mouse DOWN
- , d_y : 0 //:Mouse DOWN
- //:If both are set or unset,
- //:that is an error:
- , m_d : 0 //:IsMouseCurrentlyDown?
- , m_u : 0 //:IsMouseCurrentlyUp?
- //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
- };;Object.seal( glo_eve );
- return( glo_eve );
- };;
- //://////////////////////////////////////////////////////////://
- function CreateTileMap( map_san /** span==wid==hig **/ ){
- "use strict"
- var til_map={ /** map_dat **/
- map_u8a : null
- , map_wid : map_san
- , map_hig : map_san
- , map_com : 4 /**NumberOfComponentsPerPixel:ARGB**/
- };;
- Object.seal( til_map );
- var map_len=( 1
- * til_map.map_wid
- * til_map.map_hig
- * til_map.map_com
- );;
- til_map.map_u8a= new Uint8Array( map_len );
- FillTilemapWithTestPattern( til_map );
- return( til_map );
- };;
- //://////////////////////////////////////////////////////////://
- //: GLO_FUN.DoMapping_vp1_TO_vp0();
- function SOTM_DoMapping_vp1_TO_vp0( ){
- "use strict"
- var til_map = GLO_DAT.til_map;
- var can_ada =( GLO_OBJ.can_ada = GLO_OBJ.can_ada );
- var rec_src = GLO_DAT.rec_vp1; //: [vp1|vp2|vp3]
- var rec_dst = GLO_DAT.rec_vp0;
- DoMapping(
- can_ada //: <--------- rec_dst puts to here.
- , til_map //: <--------- rec_src takes from here.
- , rec_src //:source______rectangle
- , rec_dst //:destination_rectangle
- );;
- };;
- //://////////////////////////////////////////////////////////://
- //:Read data off of til_map using rec_dst
- //:and then write to canvas_adapter using rec_src.
- function DoMapping(
- canvas_adapter
- , til_map
- , rec_src //:source______rectangle
- , rec_dst //:destination_rectangle
- ){
- "use strict"
- //://////////////////////////////////////////////////://
- if(!canvas_adapter){ throw("[2020_05_07:300PM:A]"); };
- if(!til_map ){ throw("[2020_05_07:300PM:B]"); };
- if(!rec_src ){ throw("[2020_05_07:300PM:C]"); };
- if(!rec_dst ){ throw("[2020_05_07:300PM:D]"); };
- if( rec_src === rec_dst ){
- throw("[Rectangle_Objects_Are_Identical]");
- };;
- //://////////////////////////////////////////////////://
- var rgb_black=[0,0,0,255];
- var rgb=[1,2,3,4];//:rgba
- //:SOURCE:
- var sx0 = rec_src.x_0; //: rec_vp1
- var sx1 = rec_src.x_1; //: rec_vp1
- var sy0 = rec_src.y_0; //: rec_vp1
- var sy1 = rec_src.y_1; //: rec_vp1
- //:DEST:
- var dx0 = rec_dst.x_0; //: rec_vp0
- var dx1 = rec_dst.x_1; //: rec_vp0
- var dy0 = rec_dst.y_0; //: rec_vp0
- var dy1 = rec_dst.y_1; //: rec_vp0
- //:Rather than just looping over every pixel of
- //:destination viewport, we will loop through every
- //:pixel of canvas and draw a BLACK pixel if the
- //:point is outside of the viewport to create a
- //:letter-boxing effect.
- var cx0 = 0;
- var cy0 = 0;
- var cx1 = canvas_adapter.GetWid() - 1;
- var cy1 = canvas_adapter.GetHig() - 1;
- //:Loop through every pixel of CANVAS
- //:instead of every pixel of destination
- //:viewport.
- for(var d_x = cx0; d_x <= cx1; d_x++){
- for(var d_y = cy0; d_y <= cy1; d_y++){
- var outside_destination_viewport=( true );
- if( d_x >= rec_dst.x_0 ){ //:LEFT
- if( d_x <= rec_dst.x_1 ){ //:RIGT
- if( d_y >= rec_dst.y_0 ){ //:TOP
- if( d_y <= rec_dst.y_1 ){ //:BOT
- outside_destination_viewport=( false );
- };;};;};;};;
- if( outside_destination_viewport ){
- canvas_adapter.PutPix(d_x,d_y,rgb_black);
- }else{
- //: Percentages (dpx & spy):
- //: dpx = (d_x - dx0) / ( dx1 - dx0 )
- //: spx = (s_x - sx0) / ( sx1 - sx0 )
- //:........................SOLVE_FOR
- //:..........................|||
- //:..........................VVV
- //: (d_x-dx0)/(dx1-dx0) === (s_x-sx0)/(sx1-sx0)
- //:((d_x-dx0)/(dx1-dx0))*(sx1-sx0) === s_x-sx0
- //:(((d_x-dx0)/(dx1-dx0))*(sx1-sx0))+sx0 === s_x
- var s_x =(((d_x-dx0)/(dx1-dx0))*(sx1-sx0))+sx0;
- var s_y =(((d_y-dy0)/(dy1-dy0))*(sy1-sy0))+sy0;
- s_x = Math.floor( s_x );
- s_y = Math.floor( s_y );
- //:canvas_adapter.GetPix(s_x,s_y,rgb);
- //://////////////////////////////////////////://
- //:Convert XY to index:
- var wid = til_map.map_wid;
- var com = til_map.map_com;
- var dex = ( (s_y*com) * wid) + (s_x*com);
- rgb[ 0 ] = til_map.map_u8a[dex+0];
- rgb[ 1 ] = til_map.map_u8a[dex+1];
- rgb[ 2 ] = til_map.map_u8a[dex+2];
- rgb[ 3 ] = til_map.map_u8a[dex+3];
- //://////////////////////////////////////////://
- canvas_adapter.PutPix(d_x,d_y,rgb);
- };; //:[ outside_destination_viewport ? ]
- };;};; //:Next[ d_x , d_y ]
- canvas_adapter.Apply();
- };;//://///////////////////////////////////////:DoMapping://
- //://////////////////////////////////////////////////////////://
- function attachCanvasToDom(
- ini_can_wid //: initial_canvas_wid //:In_Pixels
- , ini_can_hig //: initial_canvas_hig //:In_Pixels
- ){
- "use strict"
- //:C: [ can / canvas ] Creation:
- //:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC://
- //:Create Canvas and append to body: ------------------- ://
- var can = document.createElement('canvas');
- document.body.appendChild(can);
- //: Make canvas non-zero in size, so we can see it:
- can.width = ini_can_wid; //:initial_canvas_wid;
- can.height = ini_can_hig; //:initial_canvas_hig;
- //: Get the context, fill [ can / canvas ] to get visual:
- var ctx = can.getContext("2d");
- ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
- ctx.fillRect(0,0,can.width, can.height);
- //:CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC://
- //:Return the canvas that was created:
- return( can );
- };;
- //://////////////////////////////////////////////////////////://
- function NEW_CanvasAdapter( can ){
- "use strict"
- var canvas_adapter =( new CanvasAdapterClass( can ) );
- return( canvas_adapter );
- };;
- //://////////////////////////////////////////////////////////://
- //:Canvas Adapter Class:
- function CanvasAdapterClass( can /** canvas **/ ){
- "use strict"
- var self=( this );
- //:Publicly Exposed Functions
- //:PEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPE://
- this.PutPix = _putPix;
- this.GetPix = _getPix;
- this.GetWid = _getWid;
- this.GetHig = _getHig;
- this.Apply = _apply;
- //:PEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPEPE://
- if(!can){
- throw("[NilCanvasGivenToPenConstruct:2020_05_06]");
- };;
- function _constructor( canvas_adapter /** self **/ ){
- //://////////////////////////////////////////////////://
- //: Setup inclusive bounds:
- var x0 = 0;
- var x1 = can.width - 1;
- var y0 = 0;
- var y1 = can.height -1;
- //: Iterate over entire [can / canvas], and set pixels:
- var rgb=[1,2,3,4];
- for(var x = x0; x <= x1; x++){
- for(var y = y0; y <= y1; y++){
- rgb[0]= x%256;
- rgb[1]= y%256;
- rgb[2]= (x+y)%256;
- rgb[3]= 255;
- canvas_adapter.PutPix( x, y, rgb );
- };;};; //:next X/Y
- //: Show changes on screen:
- canvas_adapter.Apply();
- //://////////////////////////////////////////////////://
- };;
- var _can = can;
- var _ctx = can.getContext("2d");
- //:Cache size of canvas and handles to internal data.
- var _w = _can.width;
- var _h = _can.height;
- var img_dat = _ctx.createImageData(_w,_h); //: _絵資
- var dat_dat = img_dat.data; //: _筆
- function _putPix(x,y,inn_rgb /** rgb:[r,g,b,a] **/ ){
- //:Convert XY to index:
- var dex = ( (y*4) * _w) + (x*4);
- dat_dat[dex+0] = inn_rgb[0];
- dat_dat[dex+1] = inn_rgb[1];
- dat_dat[dex+2] = inn_rgb[2];
- dat_dat[dex+3] = inn_rgb[3];
- };;
- function _getPix(x,y,out_rgb /** rgb:[r,g,b,a] **/ ){
- //:Convert XY to index:
- var dex = ( (y*4) * _w) + (x*4);
- out_rgb[ 0 ] = dat_dat[dex+0];
- out_rgb[ 1 ] = dat_dat[dex+1];
- out_rgb[ 2 ] = dat_dat[dex+2];
- out_rgb[ 3 ] = dat_dat[dex+3];
- };;
- function _getWid(){ return( _w ); };
- function _getHig(){ return( _h ); };
- function _apply(){
- _ctx.putImageData( img_dat, 0,0 );
- };;
- _constructor( self );
- };;
- //://////////////////////////////////////////////////////////://
- function FillTilemapWithTestPattern(
- til_map
- ){
- "use strict"
- var num_pix =( 1
- * til_map.map_wid
- * til_map.map_hig
- );;
- if( til_map.map_com != 4 ){
- throw("[LogicCodedFor4ComponentsPerPixel]");
- };;
- for( var pix_dex = 0; pix_dex < num_pix; pix_dex++ ){
- var dex = ( pix_dex * til_map.map_com );
- var wid = til_map.map_wid ;
- var p_x = pix_dex % wid ;
- var p_y = (pix_dex-p_x)/ wid ;
- var per_x =( p_x / til_map.map_wid );
- var per_y =( p_y / til_map.map_hig );
- var R = Math.floor( per_x * 255 );
- var G = Math.floor( per_y * 255 );
- var B = ( p_x + p_y ) % 256;
- til_map.map_u8a[dex+0] = R; //:R
- til_map.map_u8a[dex+1] = G; //:G
- til_map.map_u8a[dex+2] = B; //:B
- til_map.map_u8a[dex+3] = 255; //:A
- };;
- };;
- //://////////////////////////////////////////////////////////://
- main();
- //://////////////////////////////////////////////////////////://
- //://///////////////////////////////////////:// </script></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement