JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://www.mokgames.com/pixi/pixi142.js"></script>
JavaScript
var stage = new PIXI.Stage(0xEEEEEE);
var renderer = PIXI.autoDetectRenderer(340, 120);
if(!(renderer instanceof PIXI.WebGLRenderer)) {
renderer.context.mozImageSmoothingEnabled = false
renderer.context.webkitImageSmoothingEnabled = false;
}
document.body.appendChild(renderer.view);
function rectangle( x, y, width, height, backgroundColor, borderColor, borderWidth ) {
var box = new PIXI.Graphics();
box.beginFill(backgroundColor);
box.lineStyle(borderWidth , borderColor);
box.drawRect(0, 0, width - borderWidth, height - borderWidth);
box.endFill();
box.position.x = x + borderWidth/2;
box.position.y = y + borderWidth/2;
return box;
};
// create a 100x100 white rectangle with a 10px black border at position 10/10
stage.addChild(rectangle(10, 10, 100, 100, 0xFFFFFF, 0x000000, 10));
var colorTextures = {};
function getTexture(color) {
if(colorTextures[color] === undefined) {
var canvas = document.createElement('canvas')
canvas.width = 1;
canvas.height = 1;
ctx = canvas.getContext('2d');
ctx.fillStyle = '#' + color.toString(16);
ctx.beginPath();
ctx.rect(0,0,1,1);
ctx.fill();
ctx.closePath();
colorTextures[color] = PIXI.Texture.fromCanvas(canvas);
}
return colorTextures[color];
};
function rectangle2( x, y, width, height, backgroundColor, borderColor, borderWidth ) {
var box = new PIXI.DisplayObjectContainer();
var border = new PIXI.Sprite(getTexture(borderColor));
border.width = width;
border.height = height;
box.addChild(border);
var background = new PIXI.Sprite(getTexture(backgroundColor));
background.width = width - 2 * borderWidth;
background.height = height - 2 * borderWidth;
background.position.x = borderWidth;
background.position.y = borderWidth;
box.addChild(background);
box.position.x = x;
box.position.y = y;
return box;
};
// create a 100x100 red rectangle with a 10px purple border at position 120/10
stage.addChild(rectangle2(120, 10, 100, 100, 0xFF0000, 0x2E0854, 10));
function rectangle3( x, y,...