Giter Site home page Giter Site logo

graphical's Introduction

graphical

Graphical is a very lightweight framework used to dynamically draw graphics from NodeJS straight to the browser. Graphical is great for visualizing server-side data such as X, Y coordinates and accelerometer output in real-time.

No more having to deal with console.log spamming, make your debugging graphical!

alt steam controller example

Example visualizing the steam controller (Source code)

Getting started

First steps

Install graphical through NPM:

npm install --save-dev graphical

var { graphical } = require('graphical');

graphical(8111); // listen on port 8111

Graphical should now be accessible on http://localhost:8111/

Drawing Shapes

var { Rectangle, graphical } = require('graphical');

graphical(8111);

var rectangle = new Rectangle();
rectangle.setPos(0, 0);
rectangle.setColor('blue');
rectangle.setSize(20, 20);

Check out ./test.js for more examples.

API

graphical( [port, sendRate] )

sendRate is how frequently graphical should send state changes. Default is every 10 milliseconds.

new Drawable()

Base class for all graphical objects.

  • .destroy() Removes the Drawable.
  • .setColor( color: String ) Sets the fill-color of the drawable. color could be any variation of a CSS-style color: "red", "#ff0000", "rgb(255, 0, 0)".
  • .setPos( x: Number, y: Number )
  • .setZ( zIndex: int = 0 ) Changes drawing order. Set z-index to a negative number to draw behind every Drawable. Set z-index to a positive number to draw in front of every Drawable. If two objects have the same z-index, then they are drawn based on creation time.

new Circle()

extends from Drawable

  • .setRadius( radius: Number )
  • .setOutlineWidth( width: Number = 0 ) Thickness of the circle's outline, in pixels.
  • .setOutlineColor( color: String )

new Rectangle()

extends from Drawable

  • .setSize( width: Number, height: Number )
  • .setWidth( width: Number )
  • .setHeight( height: Number )
  • .setOutlineWidth( width: Number = 0 ) Thickness of the rectangle's outline, in pixels.
  • .setOutlineColor( color: String )

new Line()

extends from Drawable

  • .setPos2( x: Number, y: Number ) Sets the position for the line's second end-point. (To be used in-conjunction with setPos)
  • .setWidth( width: Number ) Thickness of the line, in pixels.

new Text()

extends from Drawable

  • .setFont( font: String ) CSS-style description of font and font size. Ex: "12pt Times New Roman", "bold 12px Arial", "italic bold 16px Arial".
  • .setText( text: String )
  • .setLineHeight( lineHeight: number = 0 ) How tall each line should be (in pixels) when breaking up multi-line text. If set to 0, don't break up multiline text.
  • .setOutlineWidth( width: Number = 0 ) Thickness of the text's outline, in pixels.
  • .setOutlineColor( color: String )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.