• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 13 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

With pxxl.js and the included BDF font files you can 'render' a text to an array of pixel coordinates. You can then use the pixel coordinates to do your own drawing.

example

With pxxl.js and the included BDF font files you can 'render' a text to an array of pixel coordinates. You can then use the pixel coordinates to do your own rendering. So pxxl.js itself doesn't really render anything to the screen. You might say it's 'as-if' rendering :-)

You can then use the pixel coordinates in any way you can imagine. For example:

  • plot them on a canvas
  • create position:absolute divs
  • use WebGL
  • use 3D CSS
  • etc

Example

example

Download

Install via Bower

You can install Pxxl.js via bower with the following command:

$ bower install pxxl

Quick-start

For simple scenarios, you can use the pxxl() function. It takes care of downloading the font file via ajax, it parses the font, caches the result, and then it 'renders' the text to a 'pixel info' array.

pxxl(<font-url>, <text>, <callback>)
  • <font-url> A url used to retrieve a font file via XHR. The font should be in the BDF format, which is an old text-based format for bitmap fonts.

  • <text> The text you would like you render.

  • <callback> The callback is where the rendering should happen. It is called after the font has loaded and has been parsed. The argument that gets passed is an array of pixels, like this:

    [{ x: 0, y : 0 }, { x: 1, y : 0 }, { x: 2, y : 1 }, { x: 3, y : 1 } ..etc.. ]

Note that the font file won't be downloaded again on subsequent calls because the parsed font is cached.

Simple example

example

pxxl("fonts/c64d.bdf", "Pxxl.js", function (pixels) {
  var ctx = $('canvas')[0].getContext('2d');

  for (var p=0,hue=0 ; p<pixels.length ; p++,hue++) {
    var pixel = pixels[p],
      x = pixel.x*6,
      y = pixel.y*6;

    ctx.fillStyle = "hsl("+ hue +",100%,50%)";
    ctx.fillRect(x,y,5,5);
  }
});

API

Pxxl.LoadFont(url, callback)

Load and parse a font file and execute the callback afterwards.

Pxxl.LoadFont(fontUrl, function(font) {
  ...
});

The font param that is received by the callback is an instance of Pxxl.Font.

Pxxl.Font.getPixels()

Gets the pixel info based on given font and text. The pixel info reflects how the text would be rendered. You can use the pixel info to do your own rendering.

var pixels = font.getPixels(text);

The array looks like this:

[{ x: 0, y : 0 },
 { x: 1, y : 0 },
 { x: 2, y : 1 },
 { x: 3, y : 1 }
 ..etc..        ]

More examples

  • exploding cubes with 3D CSS demo

    example

  • a canvas-based marquee of LEDs with afterglow demo

    example

  • a simple example of a color cycling animation demo

  • isometric 2.5D text you can play with demo

    example

  • exploding fireworks particles that spell 'HAPPY NEWYEAR' demo

    example

Contributing

Any and all feedback is welcome, suggestions, bug reports, pull requests, everything. Notably, I'd really want a WebGL demo for this lib but I haven't found the time to dive into WebGL. Let me know if you can help out! ;-)

Changelog

0.4

  • removed dependency on jQuery
  • code clean up, resulting in a more consistent api using namespaces (Pxxl.Font etc)

More Repositories

1

gcode-preview

A simple GCode parser & previewer with 3D printing in mind. Written in Typescript.
TypeScript
153
star
2

chronos

Reactive time utilities for Meteor. Includes reactive replacements for new Date() and moment().
JavaScript
37
star
3

computron

Computron is for creating reactive computations, just like ReactiveVar is for reactive values
JavaScript
8
star
4

OctoPrint-GCodeThumbs

OctoPrint plugin to enrich the file list with a preview thumbnail for each gcode file.
Python
8
star
5

dataroles.js

Clean separation of style vs behavior using data-* attributes.
JavaScript
8
star
6

retrofyme

See yourself in 8bit retro style. By leveraging the GetUserMedia api and the color palettes of some good old 8-bit computers, a 'retrofied' version of yourself is rendered.
HTML
4
star
7

realstuffforabstractpeople.com

my website
JavaScript
3
star
8

SublimeHandcraft

A Sublime Text 2 plugin for working with Handcraft prototypes
Python
3
star
9

konami

Run a callback when the Konami code is entered
JavaScript
3
star
10

retrofy

convert the font and colors of a webpage to give it that good ol' 8-bit look we so love :-P
JavaScript
3
star
11

quat.js

quaternion math
JavaScript
2
star
12

cube-puzzle

Hey Russ, here's your darn puzzle.
TypeScript
1
star
13

rgb_plasma

JavaScript
1
star
14

on-demand

Film1 On Demand movies sorted by IMDB rating
CSS
1
star
15

rgb-matrix

Web interface to control a ColorDuino LED matrix
JavaScript
1
star
16

Milight-Remote-Control

Demo Android App to Remote Control Milight lamps via the v6 wifi bridge
Kotlin
1
star
17

gcode-preview-vue-demo

This example project demonstrates the use of my gcode-preview in a Vue.js app.
G-code
1
star
18

PrintSchedule

Simple 3D Print Schedule for my good friend Russell โšก๏ธ
Svelte
1
star
19

RijksMemoryGame

JavaScript
1
star
20

frans

website for my father-in-law
Python
1
star
21

bbh

website for my brother in-law
JavaScript
1
star
22

polyhedral-dice-calculator

Simple Android app for rolling any combination of RPG dice, as simple as using a calculator. You can even roll non-existent dice like 1d3 or 1d7! Just enter the formula and ROLL!
Kotlin
1
star
23

sudoku-colors

Each cell is colored dynamically, based on the number of filled in cells in its row (red), column (blue) and quadrant (green). This gives each sudoku a unique color pattern. Also whenever a number is added, the colors change accordingly. So when there are no more valid options, everything is white and you have completed the sudoku.
JavaScript
1
star