TextDraw.js
Importing/Installing
Require text-draw after you have installed it.
var TextDraw = ;
You can also download text-draw.js (found in build folder on github page) and place it where you can access it.
var TextDraw = ;
Or, if you would like to use the minified TextDraw.
var TextDraw = ;
Note: something like browserify is required to use text-draw on web pages.
Initializing
Once you have imported TextDraw..
First, create a TextDraw object and initialize it.
var myCanvas = TextDraw;
Create a canvas of size(x, y)
for your text.
myCanvas;
Note: Drawing must be contained within the canvas or you will recieve an error.
Drawing
There are many options for drawing, but this demo will stick to creating a basic square with some text inside it.
Create a square
on the canvas.
myCanvassquare;//square.draw(character, width, height, x, y, extras)
Then place some text
inside.
myCanvastext;//text.draw(text, x, y)
Displaying
You can display the canvas that you have drawn with logConsole
.
myCanvas;//ormyCanvas;//for consoles that do not support color.
You can also display the canvas on a web page by using drawCanvas
.
var container = document;containerinnerHTML = myCanvas;
Make sure to wrap any element that you plan to insert a canvas into with pre
tags.
Result
You should see something similar to:
#####################
#####################
#####################
#####################
#####Hello World#####
#####################
#####################
#####################
#####################