Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create our application instance
- var app =
- new PIXI.Application
- (
- {
- width: window.innerWidth,
- height: window.innerHeight,
- backgroundColor: 0x2c3e50
- }
- );
- document.body.appendChild(app.view);
- app.loader.add( 'font', 'https://i.imgur.com/AbFrBbV.png' ).load( startup );
- function startup()
- {
- var imageSprite = new PIXI.Sprite(app.loader.resources.font.texture);
- let base64 = app.renderer.plugins.extract.base64( imageSprite );
- console.log( base64 );
- const bwFilter = new PIXI.filters.ColorMatrixFilter();
- bwFilter.greyscale(1);
- imageSprite.filters = [ bwFilter ];
- app.stage.addChild( imageSprite );
- app.ticker.add
- (
- () =>
- {
- app.render();
- }
- );
- let newSprite = PIXI.Sprite.from( base64 );
- newSprite.tint = 0xFFFF00;
- app.stage.addChild( newSprite );
- const charWidth = 9;
- const charHeight = 16;
- const binaryStrings = [];
- let img = imageSprite.texture.baseTexture.resource.source;
- let canvas = document.createElement( "CANVAS" );
- canvas.width = 144; canvas.height = 256;
- let ctx = canvas.getContext( '2d' );
- ctx.drawImage( img, 0, 0 );
- console.log( "canvas width: " + canvas.width + ", canvas height: " + canvas.height );
- console.log( "image width: " + imageSprite.width + ", image height: " + imageSprite.height );
- for( let y = 0; y < canvas.height; y += charHeight )
- {
- for( let x = 0; x < canvas.width; x += charWidth )
- {
- let binaryString = '';
- for( let charY = 0; charY < charHeight; charY++ )
- {
- for( let charX = 0; charX < charWidth; charX++ )
- {
- const pixelData = ctx.getImageData( x + charX, y + charY, 1, 1 ).data;
- if( pixelData[0] === 0 &&
- pixelData[1] === 0 &&
- pixelData[2] === 0 &&
- pixelData[3] === 255 )
- {
- binaryString += '0';
- }
- else
- {
- binaryString += '1';
- }
- }
- }
- binaryStrings.push( binaryString );
- console.log( binaryString.length );
- }
- }
- console.log( binaryStrings.length );
- }
Add Comment
Please, Sign In to add comment