![]() |
![]() |
| Smoke Vector Graphics |
Minimal Demo
DescriptionThe entire program is only 20 lines of code. Moreover, performance is excellent from both native-code and interpreted byte-code because much of the time is spent in OpenGL and GLU. All definitions related to 2D vector graphics are in the open Graphics2D Define a radial highlight that interpolates from white to transparent: let highlight =
Fill.radial
(vec2 0.4 0.5) (vec2 0.6 0.7) (vec2 0.1 0.8) Fill.white Fill.clear
Define a closed geometry from two Bezier curves and two straight lines: let geo =
[Contour.Closed, [curve_to (-0.8) 0. (-0.8) 0. (-1.) 1.; line_to 1. 1.;
curve_to 0.8 0. 0.8 0. 1. (-1.); line_to (-1.) (-1.)]] |>
ContourGeometry.make
Define the styles for our shape, starting with a red interior fill, then the white highlight and finally a blue stroke: let styles =
[ Fill.red, Style.Interior `Odd;
highlight, Style.Interior `Odd;
Fill.Flat Fill.blue, Style.stroke ~joins:`Round 0.2 ]
A "portal" defines the visible area and scene: let portal =
{view = Some(vec2 (-1.6) (-1.6), vec2 1.6 1.6); scene = Group [||]}
let paint() = portal.scene <- Transform(rot(time()), Shape(styles, geo)) The Finally, the main program registers our let () = let on_paint = Event.create() in Event.add paint on_paint; GUI.spawn ~on_paint portal This program demonstrates the construction and visualization of a simple scene graph composed of a transform and a vector graphic shape. The scene is updated as a function of time every time the CompilationThis example program may be compiled using our library with: $ ocamlopt -I +lablGL lablgl.cmxa lablglut.cmxa unix.cmxa graphics2D.cmxa demo1.ml -o demo1
(Note: We are not VAT registered and, therefore, cannot provide VAT receipts)
|
| © Flying Frog Consultancy Ltd., 2007 | Contact the webmaster |