How to manipulate Canvas elements
Jump to navigation
Jump to search
The FlightGear forum has a subforum related to: Canvas |
The purpose of this document is to introduce the plot2D tool and provide basic information about its use.
Plot2D is nothing more than a collection of helpers that aims to facilitate the task of coding. It makes intensive use of the Canvas API, a mandatory reference for those who intend to refine the result beyond what is offered by plot2D.
It is assumed here that you already have a minimal knowledge about Canvas.
For now Plot2D (which you can see here) resides in the SpokenGCA addon, but the idea is that in the future it could be included in the $FG-ROOT/Nasal/canvas directory.
"Create" helpers
line
Parameters: (group, from, to, color)
Plots a line as <group>'s child.
- from as [x,y] in pixels.
- to as [x,y] in pixels.
- color optional as [r,g,b] or "#rrggbb", Black by default.
example | Screenshot |
---|---|
var window = canvas.Window.new([200,200],"dialog")
.set("title","Plot2D demo" );
var myCanvas = window.createCanvas()
.set("background", "#eeeeee");
var root = myCanvas.createGroup();
var myGroup = root.createChild("group");
var red = "#ee0000";
canvas.plot2D.line(myGroup,[20,20],[50,100],red);
canvas.plot2D.line(myGroup,[20,180],[180,20],'#ee0000')
.setStrokeLineWidth(2); |
ig oyg |