To use raster.js, include the raster library and call some methods on the ra object
const ra = require('raster');
// size of the display
ra.setSize(20, 25);
// pixels appear 4 times larger
ra.setZoom(4);
// overlay a grid using 1x1 pixel placement
ra.setGrid(1);
ra.run();
This code creates a field (the thing that gets drawn to) that is 20 pixels wide with a height of 25 pixels. Setting the zoom to 4 doesn't change the number of pixels in the field, it just makes them appear 4x larger, while still keeping crisp and sharp edges. Next the grid is enabled, showing up at every pixel after the zoom is taken into account. Finally ra.run
is what displays the results.
Most methods are flexible in how they can be given arguments. For example instead of calling ra.setSize
using positional arguments, as seen above, we can use named parameters by passing a javascript object literal, to provide the width and height:
const ra = require('raster');
ra.setSize({w: 20, h: 25});
ra.setZoom(4);
ra.setGrid(1);
ra.run();
Table of Contents | Next: Draw shapes |