Here we go again and it's again time for some canvas...
Those of you who followed this blog know that i started to port some of the components of the steelseries java library to html5 canvas. Because i'm not a javascript coder i had no idea how to build a library from these components and so i started playing around, trying this and that...
Finally i found a way that looks ok to me (but i might be wrong) and today i could present you the first version of the javascript version of the steelseries library (it only contains the Radial and RadialBargraph right now).
I tried to implement most of the features of the java version but right now there are still some feature missing.
Here is a list of the features that are supported by the javascript version:
GaugeType:
PointerType:
- TYPE1
- TYPE2
- TYPE3
- TYPE4
- TYPE5
- TYPE6
- TYPE7
- TYPE8
FrameDesign:
- BLACK_METAL
- METAL
- SHINY_METAL
- BRASS
- STEEL
- CHROME
- GOLD
BackgroundColor:
- DARK_GRAY
- SATIN_GRAY
- LIGHT_GRAY
- WHITE
- BLACK
- BEIGE
- BROWN
- RED
- GREEN
- BLUE
- BEIGE
- BLUE
- ORANGE
- RED
- YELLOW
- WHITE
- GRAY
- BLACK
- GREEN
- BLUE2
- BLUE_BLACK
- BLUE_DARKBLUE
- BLUE_GRAY
- STANDARD
- BLUE_BLUE
- REDDARKRED
- RED_LED
- GREEN_LED
- BLUE_LED
- ORANGE_LED
- YELLOW_LED
- CYAN_LED
- MAGENTA_LED
- RED
- GREEN
- BLUE
- ORANGE
- YELLOW
- CYAN
- MAGENTA
- WHITE
- GRAY
- BLACK
- RAITH
- GREEN_LCD
- JUG_GREEN
The Radial component also supports sections and areas. So there's no track right now (but it will come).
To make use of the library you have to add two files to your html page:
So a typical html5 page header will look like this...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Test</title>
<script type='text/javascript' src='js/tween.js'></script>
<script type='text/javascript' src='js/steelseries.js'></script>
...
To use the library you need to add a <canvas> tag for each gauge to the <body> of the page.
e.g.
...
<body onload='init()'>
<canvas id='canvas1' width='200' height='200'>
No canvas in your browser...sorry...
</canvas>
<canvas id='canvas2' width='200' height='200'></canvas>
<canvas id='canvas3' width='200' height='200'></canvas>
</body>
...
Now we only have to add the init() method in the <head> of the page, where we create the canvas components.
!!! OLD VERSION !!!
function init()
{
// Define some sections
var sections = Array(steelseries.Section(0, 25, 'rgba(0, 0, 220, 0.3)'),
steelseries.Section(25, 50, 'rgba(0, 220, 0, 0.3)'),
steelseries.Section(50, 75, 'rgba(220, 220, 0, 0.3)'));
// Define one area
var areas = Array(steelseries.Section(75, 100, 'rgba(220, 0, 0, 0.3)'));
// Create one radial gauge
var radial1 = new steelseries.Radial(
'canvas1', // the canvas element
steelseries.GaugeType.TYPE4, // type of gauge
200, // size of gauge
0, // minimum value
100, // maximum value
50, // threshold
sections, // sections
areas, // areas
'Test', // title string
'Unit', // unit string
steelseries.FrameDesign.METAL, // frame design
steelseries.BackgroundColor.DARK_GRAY, // background color
steelseries.PointerType.TYPE8, // pointer type
steelseries.ColorDef.RED, // pointer color
steelseries.LcdColor.STANDARD, // lcd color
true, // lcd visible
steelseries.LedColor.RED_LED, // led color
true, // led visible
false); // play audio
// Create a second radial gauge
var radial2 = new steelseries.Radial(
'canvas2',
steelseries.GaugeType.TYPE2,
200,
0,
50,
40,
Array(steelseries.Section(0, 40, 'rgba(0, 255, 0, 0.3)')),
Array(steelseries.Section(40, 50, 'rgba(255, 0, 0, 0.5)')),
'Test',
'Unit',
steelseries.FrameDesign.CHROME,
steelseries.BackgroundColor.LIGHT_GRAY,
steelseries.PointerType.TYPE2,
steelseries.ColorDef.BLUE,
steelseries.LcdColor.BLUE2,
true,
steelseries.LedColor.BLUE_LED,
true,
false);
// Create a radial bargraph gauge
var radial3 = new steelseries.RadialBargraph(
'canvas3', // the canvas element
steelseries.GaugeType.TYPE3, // type of gauge
200, // size of gauge
0, // minimum value
100, // maximum value
50, // threshold
null, // sections (not supported)
"Title", // title string
"Unit", // unit string
steelseries.FrameDesign.BLACK_METAL, // frame design
steelseries.BackgroundColor.LIGHT_GRAY, // background color
steelseries.ColorDef.YELLOW, // color of the bargraph led's
steelseries.LcdColor.YELLOW, // lcd color
true, // lcd visible
steelseries.LedColor.YELLOW_LED, // led color
true); // led visible
// Let's set some values...
radial1.setValueAnimated(70);
radial2.setValueAnimated(41);
radial3.setValueAnimated(70);
}
As you can see the drawback of the current design are the long constructors. I'm still not sure how to make these nicer but i'm working on that...
UPDATE:
Thanx to Andres Almiray who pointed me in the right direction i modified the constructor of the Radial and RadialBargraph component in the way that it now takes a hash as a set of parameters. This means you don't have to put in all the default parameters anymore which makes the initialization of the components look like this...
!!! NEW VERSION !!!
function init()
{
// Define some sections
var sections = Array(steelseries.Section(0, 25, 'rgba(0, 0, 220, 0.3)'),
steelseries.Section(25, 50, 'rgba(0, 220, 0, 0.3)'),
steelseries.Section(50, 75, 'rgba(220, 220, 0, 0.3)'));
// Define one area
var areas = Array(steelseries.Section(75, 100, 'rgba(220, 0, 0, 0.3)'));
// Create one radial gauge
var radial1 = new steelseries.Radial(
'canvas1', {
section: sections,
area: areas,
titleString: 'Test',
unitString: 'Unit',
pointerType: steelseries.PointerType.TYPE8
});
// Create a second radial gauge
var radial2 = new steelseries.Radial(
'canvas2', {
gaugeType: steelseries.GaugeType.TYPE2,
maxValue: 50,
threshold: 40,
section: Array(steelseries.Section(0,40,'rgba(0,255,0,0.3)')),
area: Array(steelseries.Section(40,50,'rgba(255,0,0,0.5)')),
titleString: 'Test',
unitString: 'Unit',
frameDesign: steelseries.FrameDesign.CHROME,
backgroundColor: steelseries.BackgroundColor.LIGHT_GRAY,
pointerType: steelseries.PointerType.TYPE2,
pointerColor: steelseries.ColorDef.BLUE,
lcdColor: steelseries.LcdColor.BLUE2,
ledColor: steelseries.LedColor.BLUE_LED,
});
// Create a radial bargraph gauge
var radial3 = new steelseries.RadialBargraph(
'canvas3', {
gaugeType: steelseries.GaugeType.TYPE3,
titleString: "Title",
unitString: "Unit",
frameDesign: steelseries.FrameDesign.BLACK_METAL,
backgroundColor: steelseries.BackgroundColor.LIGHT_GRAY,
valueColor: steelseries.ColorDef.YELLOW,
lcdColor: steelseries.LcdColor.YELLOW,
ledColor: steelseries.LedColor.YELLOW_LED,
});
// Let's set some values...
radial1.setValueAnimated(70);
radial2.setValueAnimated(41);
radial3.setValueAnimated(70);
}
Guess that looks much better than before... :-)
If you put all these things together in one html page you should see something like this...
If you are to lazy to play around you might want to click here to see it in action...
There are two versions of the library available right now, the uncompressed (101 kb) and compressed (61 kb) version. You could download the version clicking on one of the following links:
uncompressed version: steelseries.js
compressed version: steelseries-min.js
animation library: tween.js
Keep in mind that this project is work in progress and things might change in the future...
Enjoy the upcoming weekend and keep coding...