JavaScript hack
Relatd javascript Articles
Sebastien Gruhier has created useful libraries such as the Prototype Windowcomponent.
Now, he has created the Prototype Graphic Framework(PGF) - a framework based on prototype to display vectorial shapes inside a web browser.
The framework has various renderers that sit on top of SVG, Canvas, and VML, so you can plug and play (although canvas support is limited right now).
-
- // Create an SVG renderer
- varrenderer = newSVGRenderer ("whiteboard");
-
- // Create a rectangle with some attributes like color and bounds
- varrect = newGraphic. Rectangle(renderer);
- rect.setFill({r: 255, g: 0, b: 0, a: 128});
- rect.setStroke({r: 255, g: 255, b: 0, a: 128, w: 5});
- rect.setBounds(10, 20, 200, 300);
- rect.setRoundCorner(10, 10);
- rect.translate(10, 20);
- rect.rotate(30);
-
- renderer.add(rect);
-
Dylan Schiemann, co-creator of the Dojo toolkit, has written a broad piece on creating cross browser vector graphics with Dojo.
The article delves into the new dojo.gfxlibrary that abstracts the slight mess of SVG vs. Canvas vs. VML.
One of the examples in the article discusses drawing a clock with this snippet that shows drawing the clock hands, along with their shadows:
-
- this.shadows.hour.shadow= this._initPoly(this.surface, hP)
- . setFill([0, 0, 0, 0.1]);
- this.hands.hour= this._initPoly(this.surface, hP)
- . setStroke({color: this.handStroke, width:1 })
- . setFill({
- type: "linear",
- x1: 0, y1:0, x2:0, y2:-27,
- colors: [{offset:0, color:"#fff"}, {offset:0.33, color:this.handColor}]
- });
- this.shadows.minute.shadow= this._initPoly(this.surface, mP)
- . setFill([0, 0, 0, 0.1]);
- this.hands.minute= this._initPoly(this.surface, mP)
- . setStroke({color: this.handStroke, width:1 })
- . setFill({
- type: "linear",
- x1: 0, y1:0, x2:0, y2:-38,
- colors: [{offset:0, color:"#fff"}, {offset:0.33, color:this.handColor}]
- });
-

What features are supported
- Strokes (borders)
- Fills
- Shapes and Paths
- Opacity
- Linear Transformations
- Rounded Corners
If you have wanted "the ability to draw and modify non-rectangular, browser-native shapes" then check out the article and dig deeper:
- Dojo: documentation, book, and download
- Clock: demoand source
- Circles: demo and source
- Charts: demo
- Canvas: mozilla tutorial
- Comet: Cometd, Lightstreamer, KnowNow, and DWR
Related javascript Projects
jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.
MooTools is a compact, modular, Object-Oriented JavaScript framework designed for the intermediate to advanced JavaScript developer. It allows you to write powerful, flexible, and cross-browser code with its elegant, well documented, and coherent API.
Er.js piggybacks on Neil Mix’s Thread.js which fakes threading in JavaScript 1.7 using coroutines and nested generator continuations. The goal is to replicate Erlang’s concurrent lockless process model and message-passing APIs in JavaScript.



