• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 10 years ago

Reviews

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

Repository Details

🎨 JavaScript graphic library for retro CG

gretro

NPM Version Bower Build Status Coverage Status Dependency Status devDependency Status

Gretro (grétrou, グレトロ) is a JavaScript graphic library for retro CG.

Features

  • 16 colors chosen from available 4096 colors
  • 16 default tile patterns and 16 custom tile patterns
  • drawing in pixels, no anti aliasing
  • plugin architecture for extending gretro.Canvas

Online Playground

Install

browser
$ bower install gretro
<script src="/path/to/gretro.js"></script>
node.js
% npm install gretro

Usage

var canvas = new gretro.Canvas(220, 110);

canvas
  .stroke(13).circle( 40, 40, 30)
  .stroke( 7).circle(110, 40, 30)
  .stroke(10).circle(180, 40, 30)
  .stroke(14).circle( 75, 70, 30)
  .stroke(12).circle(145, 70, 30);

Rendering

browser
var gretroCanvas = new gretro.Canvas(640, 400).draw(fn);

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var imageData = context.createImageData(640, 400);

imageData.data.set(gretroCanvas.toRGBA());

context.putImageData(imageData, 0, 0);

draw directly to the html-canvas

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var imageData = context.getImageData(0, 0, 640, 400);

new gretro.Canvas(640, 400, imageData.data).draw(fn);

context.putImageData(imageData, 0, 0);
node.js

use node-png npm install png

var Png = require("png").Png;
var fs  = require("fs");

var png = new Png(new Buffer(gretroCanvas.toRGB()), 640, 400, "rgb");
var png_image = png.encodeSync();

fs.writeFileSync("./image.png", png_image.toString("binary"), "binary");

API

Canvas

Constructor

  • new Canvas(width:int=640, height:int=400, buffer:Uint8Array=null) : Canvas

Instance methods

Environment
Setting
Color
Region
Shape
Image
Output
Utility

Color

You can use 16 colors on a canvas. It is possible to select from 4096 colors.

default color palette

customize color

canvas
  .setColor(0, 0x44dd77).setColor(1, 0x22aa88)
  .fill(1).rect(20, 20, 60, 60);

color generator

set a function that returns a calculated color number instead of a color number.

canvas
  .fill(function(x, y) {
    return 16 * Math.random();
  }).rect(20, 20, 60, 60);

Tile

A tile is a 4 x 4 dot pattern with 2 colors that is used to express gradation in generally.

usage

Set array that contains color1, color2 and tile-index instead of a color number.

canvas.fill([ color1, color2, tileIndex ]);

default tile palette

custom tile

TileIndex 16-31 are customizable.

canvas
  .setTile(16, 0x4a12)
  .stroke(13).fill([ 0, 13, 16 ])
  .circle(50, 50, 40, 40);
/* 1 2 4 8
   □ ■ □ □ = 2
   ■ □ □ □ = 1
   □ ■ □ ■ = a
   □ □ ■ □ = 4
            0x */

Plugins

gretro-text

plugin to draw a text

gretro-paint

plugin to paint a region

Contribution

  1. Fork (https://github.com/mohayonao/gretro/fork)
  2. Create a feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'add some feature')
  4. Run test suite with the gulp travis command and confirm that it passes
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

Gretro is available under the The MIT License.

More Repositories

1

timbre.js

JavaScript library for objective sound programming
JavaScript
962
star
2

timbre

345
star
3

pico.js

Audio processor for the cross-platform
JavaScript
312
star
4

web-audio-engine

Pure JS implementation of the Web Audio API
JavaScript
242
star
5

CoffeeCollider

Sound Processing Language for Web Audio
JavaScript
216
star
6

web-audio-scheduler

Event Scheduler for Web Audio API
JavaScript
90
star
7

ciseaux

JavaScript utility to chop an audio buffer
JavaScript
81
star
8

old-neume.js

Neume.js is a Web Audio API library for developing browser music.
JavaScript
79
star
9

subcollider

👷
JavaScript
71
star
10

web-audio-test-api

Web Audio API for CI
JavaScript
67
star
11

inline-worker

JavaScript utility to create a WebWorker from a function
JavaScript
65
star
12

wave-tables

JavaScript
54
star
13

mml-emitter

MML(Music Macro Language) event emitter for Web Audio API.
JavaScript
52
star
14

virtual-midi-keyboard

Electron-based Virtual MIDI Keyboard
JavaScript
52
star
15

web-audio-lesson

JavaScript
49
star
16

virtual-midi-matrix-pad

Electron-based Virtual MIDI Controller that like Novation Launchpad
JavaScript
40
star
17

wav-decoder

promise-based wav decoder
JavaScript
38
star
18

wav-encoder

promise-based wav encoder
JavaScript
36
star
19

adsr-envelope

ADSREnvelope for Web Audio API
JavaScript
36
star
20

web-audio-api-shim

shim for legacy Web Audio API
JavaScript
33
star
21

audio-worker-shim

AudioWorker compatibility shim for legacy Web Audio API
JavaScript
26
star
22

seurat

🎨 JavaScript utility to generate a braille text from an image
JavaScript
25
star
23

fm-synth

simple frequency modulation synthesizer
JavaScript
22
star
24

scsynth

JavaScript
20
star
25

mohayonao.herokuapp.com

ウェブ楽器とかのコード
JavaScript
18
star
26

audio-worker-node

AudioWorkerNode for legacy Web Audio API
JavaScript
18
star
27

pluck-string-node

Pluck String AudioNode for Web Audio API
JavaScript
17
star
28

osc-msg

OSC message decoder/encoder with fault tolerant
JavaScript
17
star
29

launch-control

JavaScript utility for novation LAUNCH CONTROL
JavaScript
17
star
30

stereo-panner-node

StereoPannerNode for legacy Web Audio API
JavaScript
17
star
31

osc-hub

broadcast osc messages over the network
JavaScript
17
star
32

biquad-coeffs

collection of formulae for biquad filter coefficients
JavaScript
16
star
33

MMLEmitter

this package is renamed to mml-emitter
16
star
34

worker-timer

Timer API that works stable in background tabs
JavaScript
14
star
35

wae-cli

web-audio-engine command line
JavaScript
14
star
36

es6-project-boilerplate

JavaScript
13
star
37

the.mohayonao.com

JavaScript
13
star
38

mml-iterator

MML(Music Macro Language) Iterator
JavaScript
13
star
39

midi-device

isomorphic abstract class for MIDI device
JavaScript
12
star
40

promise-decode-audio-data

Promise-based decodeAudioData for legacy Web Audio API
HTML
12
star
41

xs-808

JavaScript
11
star
42

web-audio-api-spec-checker

HTML
11
star
43

waa-lab

HTML
11
star
44

midi-keyboard

JavaScript utility for MIDI keyboard
JavaScript
10
star
45

pseudo-audio-param

Simulate scheduled AudioParam values
JavaScript
10
star
46

web-audio-utils

Utility functions for Web Audio API
JavaScript
10
star
47

stereo-analyser-node

JavaScript
10
star
48

get-float-time-domain-data

getFloatTimeDomainData for legacy Web Audio API
JavaScript
10
star
49

virtual-midi-knob-knob-pad

Electron-based Virtual MIDI Controller that like Novation Launch Control
JavaScript
9
star
50

xs-seq

minimum sequencer with React/Redux
JavaScript
9
star
51

sushi-repl

Yet Another JavaScript REPL
JavaScript
9
star
52

MutekiTimer

A stable timer that run in the background
CoffeeScript
9
star
53

synthdef-json-decoder

Decode SuperCollider Synth Definition File Format and convert to JSON
JavaScript
9
star
54

web-midi-test-api

Web MIDI API for CI
JavaScript
8
star
55

CnvUI

A tiny UI base on HTMLCanvasElement
JavaScript
8
star
56

react-code-reading

8
star
57

perlin-noise

simple 1d perlin noise generator
JavaScript
8
star
58

SCScript

JavaScript port of SuperCollider
JavaScript
8
star
59

script-synthesizer

Script Syntesizer with timbre.js and WebMidiLink
JavaScript
8
star
60

prominence

Call a callback-based function as ES6 Promise
JavaScript
8
star
61

cubic-sequencer

JavaScript
7
star
62

duolet

2 layered architecture for sound programming in JavaScript
JavaScript
7
star
63

web-music-hackathon-04

project for web music hackathon 04
JavaScript
7
star
64

start-web-audio

JavaScript
6
star
65

mimi-grep

auralization grep command
JavaScript
6
star
66

seq-emitter

EventEmitter for Web Audio API sequencer
JavaScript
6
star
67

ksdn808

関西電気保安協会リズムマシーン
JavaScript
6
star
68

white-noise-node

WhiteNoiseNode for Web Audio API
HTML
6
star
69

launch-pad-color

color code of Novation LaunchPad
JavaScript
6
star
70

libogg.js

JavaScript port to the libogg 1.3.0
JavaScript
6
star
71

tickable-timer

Manual ticking timer API
JavaScript
5
star
72

fetch-as-audio-buffer

util function to fetch audio buffer
JavaScript
5
star
73

is-zero

is ±0 ?
JavaScript
5
star
74

worker-builder

WorkerBuilder builds a WebWorker from a funtion
JavaScript
5
star
75

brown-noise-node

BrownNoiseNode for Web Audio API
HTML
5
star
76

triolet

3 layered architecture for sound programming in JavaScript
JavaScript
5
star
77

json-touch-patch

Immutable JSON Patch implementation based on RFC 6902
JavaScript
5
star
78

web-audio-sound-examples

JavaScript
4
star
79

envelope

simple envelope
JavaScript
4
star
80

web-music-hack0913

JavaScript
4
star
81

pico.driver

audio driver for sound programming in JavaScript
JavaScript
4
star
82

xs-key

minimum keyboard with React/Redux
JavaScript
4
star
83

biquad-filter-kernel

collection of biquad filter kernel
JavaScript
4
star
84

ouroboros-worker

WebWorker to share the code of the main thread
JavaScript
4
star
85

pink-noise-node

PinkNoiseNode for Web Audio API
JavaScript
4
star
86

web-audio-mock-api

mock API which implements the Web Audio API's interfaces only
JavaScript
4
star
87

drunk-timer

Staggering timer API
JavaScript
4
star
88

GLISTAGRAM

glitched instagram viewer
JavaScript
3
star
89

ableton-live-utils

JavaScript utility for ableton live
JavaScript
3
star
90

thisis

習作
JavaScript
3
star
91

web-audio-test-api-2

Web Audio API for CI
JavaScript
3
star
92

request-midi-access

requestMIDIAccess for all
JavaScript
3
star
93

dorilasound

JavaScript
3
star
94

chai-deep-closeto

deep.closeTo for chai
JavaScript
3
star
95

virtual-midi-device

👷 Utils for Virtual MIDI Device
JavaScript
3
star
96

gretro-text

JavaScript
3
star
97

audiodata

definition of audio data interface
JavaScript
3
star
98

constant-source-node

ConstantSourceNode for legacy Web Audio API
JavaScript
3
star
99

power-audio-node

enhance the connecting interface of AudioNode for custom AudioNode
JavaScript
3
star
100

freqr

Compute the frequency response of a digital filter.
JavaScript
3
star