Skip to content

Commit

Permalink
Added files
Browse files Browse the repository at this point in the history
  • Loading branch information
vesteraas committed Dec 25, 2014
1 parent e97754f commit 7c6871f
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 178 deletions.
16 changes: 16 additions & 0 deletions examples/berries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");
fb.clear();

var xMax = fb.size().width;
var yMax = fb.size().height;

fb.image(x, y, "raspberry-pi.png");

for (var n=0; n<1000; n++) {
var x = Math.random() * (xMax + 32) - 16;
var y = Math.random() * (yMax + 32) - 16;

fb.image(x, y, "raspberry-pi-icon.png");
}
22 changes: 19 additions & 3 deletions examples/circles.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");

fb.clear();

var xMax = fb.size().width;
var yMax = fb.size().height;

for (var n=0; n<1000; n++) {
for (var n=0; n<250; n++) {
var x, y, radius, r, g, b;

x = parseInt(Math.random() * xMax, 10);
Expand All @@ -19,5 +18,22 @@ for (var n=0; n<1000; n++) {
b = Math.random();

fb.color(r, g, b);
fb.circle(x, y, radius, false, 5);
fb.circle(x, y, radius, false, 1);
}

fb.clear();

for (var n=0; n<250; n++) {
var x, y, radius, r, g, b;

x = parseInt(Math.random() * xMax, 10);
y = parseInt(Math.random() * yMax, 10);
radius = parseInt(Math.random() * yMax / 2, 10);

r = Math.random();
g = Math.random();
b = Math.random();

fb.color(r, g, b);
fb.circle(x, y, radius, true);
}
94 changes: 58 additions & 36 deletions examples/clock.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,70 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");

var fb = new pitft.FrameBuffer("/dev/fb1", true);
fb.clear();

var rad = 180 / Math.PI;

var xMax = fb.size().width;
var yMax = fb.size().height;
var rad = 180/Math.PI;

fb.color(1, 1, 1);
fb.circle(xMax / 2, yMax / 2, 100);

fb.color(0, 0, 0);
for (var a=0; a<360; a+=30) {
var x0 = xMax / 2 + Math.sin(a / rad) * 85;
var y0 = yMax / 2 + Math.cos(a / rad) * 85;
var hand = function(_fb, x, y, angle, length, width) {
var x0 = xMax/2 + Math.sin(angle/rad);
var y0 = yMax/2 - Math.cos(angle/rad);

var x1 = xMax / 2 + Math.sin(a / rad) * 95;
var y1 = yMax / 2 + Math.cos(a / rad) * 95;
var x1 = xMax/2 + Math.sin(angle/rad) * length;
var y1 = yMax/2 - Math.cos(angle/rad) * length;

fb.line(x0, y0, x1, y1, 5);
fb.line(x0, y0, x1, y1, width);
}

fb.color(1, 0, 0);

var a, x0, y0, x1, y1;

a = 10 / 12 * 360;

x0 = xMax / 2 - Math.sin(a / rad);
y0 = yMax / 2 - Math.cos(a / rad);

x1 = xMax / 2 - Math.sin(a / rad) * 50;
y1 = yMax / 2 - Math.cos(a / rad) * 50;

fb.line(x0, y0, x1, y1, 5);

a = 2 / 12 * 360;

x0 = xMax / 2 - Math.sin(a / rad);
y0 = yMax / 2 - Math.cos(a / rad);

x1 = xMax / 2 - Math.sin(a / rad) * 80;
y1 = yMax / 2 - Math.cos(a / rad) * 80;
var drawDial = function() {
fb.color(1, 1, 1);
fb.circle(xMax/2, yMax/2, 100);

fb.color(0, 0, 0);
for (var a = 0; a < 360; a += 6) {
var x0, y0;

var x0 = xMax/2 + Math.sin(a/rad) * 95;
var y0 = yMax/2 + Math.cos(a/rad) * 95;

if (a % 30 == 0) {
x1 = xMax/2 + Math.sin(a/rad) * 85;
y1 = yMax/2 + Math.cos(a/rad) * 85;
fb.line(x0, y0, x1, y1, 5);
} else {
x1 = xMax/2 + Math.sin(a/rad) * 90;
y1 = yMax/2 + Math.cos(a/rad) * 90;
fb.line(x0, y0, x1, y1, 1);
}
}
}

fb.line(x0, y0, x1, y1, 5);
var updateHands = function() {
fb.color(1, 1, 1);
fb.circle(xMax/2, yMax/2, 85);

var now = new Date(),
midnight = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
0,0,0),
hours = (now.getTime() - midnight.getTime())/1000/60/60,
minutes = (hours * 60) % 60;
seconds = parseInt((minutes * 60) % 60);

fb.color(1, 0, 0);
hand(fb, 0, 0, hours/12 * 360, 60, 5);
hand(fb, 0, 0, minutes/60 * 360, 80, 5);
fb.color(0, 0, 0);
hand(fb, 0, 0, seconds/60 * 360, 80, 1.5);
fb.color(1, 0, 0);
fb.circle(xMax/2, yMax/2, 7.5);
fb.blit();
};

drawDial();
setInterval(function() {
updateHands();
}, 100);
25 changes: 0 additions & 25 deletions examples/image.js

This file was deleted.

3 changes: 1 addition & 2 deletions examples/lines.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");

fb.clear();

var xMax = fb.size().width;
var yMax = fb.size().height;

for (var n=0; n<1000; n++) {
for (var n=0; n<500; n++) {
var x0, y0, x1, y1, r, g, b;

x0 = parseInt(Math.random() * xMax, 10);
Expand Down
Binary file added examples/raspberry-pi-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/raspberry-pi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 24 additions & 2 deletions examples/rectangles.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
var pitft = require("../pitft");

var fb = new pitft.FrameBuffer("/dev/fb1");

fb.clear();

var xMax = fb.size().width;
var yMax = fb.size().height;

for (var n=0; n<1000; n++) {
for (var n=0; n<500; n++) {
var x, y, w, h, r, g, b;

do {
x = parseInt(Math.random() * xMax, 10);
w = parseInt(Math.random() * xMax, 10);
} while ((x + w) >= xMax)

do {
y = parseInt(Math.random() * yMax, 10);
h = parseInt(Math.random() * yMax, 10);
} while ((y + h) >= yMax)

r = Math.random();
g = Math.random();
b = Math.random();

fb.color(r, g, b);
fb.rect(x, y, w, h, false, 1);
}

fb.clear();

for (var n=0; n<500; n++) {
var x, y, w, h, r, g, b;

do {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pitft",
"description": "A C++ extension for node.js that gives javascript access to the PiTFT framebuffer",
"version": "0.0.6",
"version": "0.0.7",
"main": "pitft.js",
"author": "Werner Vesteraas <[email protected]>",
"license": {
Expand Down
Loading

0 comments on commit 7c6871f

Please sign in to comment.