Canvas snippets: Difference between revisions

Jump to navigation Jump to search
m
→‎Adding Raster Images: more specific snippets for thorsten's space shuttle avionics effort: http://forum.flightgear.org/viewtopic.php?f=4&t=25747&start=90#p238159
m (→‎Adding Raster Images: http://forum.flightgear.org/viewtopic.php?f=4&t=25747&start=90#p238157)
m (→‎Adding Raster Images: more specific snippets for thorsten's space shuttle avionics effort: http://forum.flightgear.org/viewtopic.php?f=4&t=25747&start=90#p238159)
Line 92: Line 92:
! Screenshot !! Code !!  
! Screenshot !! Code !!  
|-
|-
| [[File:Canvas Snippets-raster image.png|thumb|Canvas snippet demonstrating how to load a raster image]] ||
| [[File:Canvas-raster-images-via-url.png|thumb|screen shot demonstrating how Nasal and Canvas can be used to display raster images downloaded on demand]] ||
<syntaxhighlight lang="nasal" enclose="div">
<syntaxhighlight lang="nasal" enclose="div">


# path is relative to $FG_ROOT (base package)
# create a new window, dimensions are 400 x 200, using the dialog decoration (i.e. titlebar)
var path = "http://www.worldwidetelescope.org/docs/Images/MapOfEarth.jpg";
var window = canvas.Window.new([400,200],"dialog");
 
# adding a canvas to the new window and setting up background colors/transparency
var myCanvas = window.createCanvas().set("background", canvas.style.getColor("bg_color"));
 
# Using specific css colors would also be possible:
# myCanvas.set("background", "#ffaac0");
 
# creating the top-level/root group which will contain all other elements/group
var root = myCanvas.createGroup();
 
 
# path now a URL
var url = "http://www.worldwidetelescope.org/docs/Images/MapOfEarth.jpg";
 
# create an image child for the texture
# create an image child for the texture
var child=root.createChild("image")
var child=root.createChild("image")
          .setFile( path )
                                  .setFile( url)  
  .setTranslation(100,10)
                                  .setTranslation(45,22)
                                   .setSize(130,130);
                                   .setSize(310,155);
</syntaxhighlight>
</syntaxhighlight>


Navigation menu