© Efflare Systems
website : e-mail

index | examples | api | language
Example 5 • Simple Drawing
In this example simple drawing and user defined functions will be introduced.
<cfx_imageflare source="
  b = Bitmap( '#expandpath('.\ngeo.jpg')#' )
  b.resize( 150, 0 )
  
  c = Color('white')
  
  b.shape( Ellipse( b.width-16, b.height-24, b.width-3, b.height-11 ), Color('white',0), c, 2 )

  b.line( b.width-10, b.height-11, b.width-10, b.height-03, c, 4 )    // handle
  b.line( b.width-10, b.height-21, b.width-10, b.height-15, c, 1 )    // vertical crosshair
  b.line( b.width-13, b.height-18, b.width-07, b.height-18, c, 1 )    // horizontal crosshair
  
  b.save( '#expandpath('.\example05a.jpg')#' )
">
     Using the shape and line methods, we've drawn a circle and 3 lines to represent a simple magnification icon.

Another option here is to paste in a previously created graphic. Using your favorite interactive graphics application create the appropriate image, then save as fully transparent capable png. That png can then be pasted into your thumbnail with ImageFlare.

Now on to user defined functions...
<cfx_imageflare source="
  function drawMagnifyIcon(b,c)
    b.shape( Ellipse( b.width-16, b.height-24, b.width-3, b.height-11 ), Color('white',0), c, 2 )
    b.line( b.width-10, b.height-11, b.width-10, b.height-03, c, 4 )    // handle
    b.line( b.width-10, b.height-21, b.width-10, b.height-15, c )       // vertical crosshair
    b.line( b.width-13, b.height-18, b.width-07, b.height-18, c )       // horizontal crosshair
  end
  
  b = Bitmap( '#expandpath('.\ngeo.jpg')#' )
  b.resize( 150, 0 )
  
  drawMagnifyIcon( b, Color('white') )
  
  b.save( '#expandpath('.\example05a.jpg')#' )
">
This script creates the same output image as above. The function drawMagnifyIcon has been defined, and accepts two parameters, a Bitmap and Color object. We then call the function passing the Bitmap and a Color created anonymously. Remember the variables b and c are local to the function defintion.

You might be thinking a user defined function doesn't do too much good when it is explicitly defined in a single script.
You're right! This is where the FlareScript function include becomes useful ...
<cfx_imageflare source="
  include( '#expandpath('drawMagnifyIcon.fs')#' )
    
  b = Bitmap( '#expandpath('.\ngeo.jpg')#' )
  b.resize( 150, 0 )
  
  drawMagnifyIcon( b, Color('white') )
  
  b.save( '#expandpath('.\example05a.jpg')#' )
">
Similar to most languages, the include function, in effect, replaces itself with the specified file. In this case the file is drawMagnifyIcon.fs, and contains :
function drawMagnifyIcon(b,c)
  b.shape( Ellipse( b.width-16, b.height-24, b.width-3, b.height-11 ), Color('white',0), c, 2 )
  b.line( b.width-10, b.height-11, b.width-10, b.height-03, c, 4 )    // handle
  b.line( b.width-10, b.height-21, b.width-10, b.height-15, c )       // vertical crosshair
  b.line( b.width-13, b.height-18, b.width-07, b.height-18, c )       // horizontal crosshair
end
In this manner reusable FlareScript components can be developed and easily maintained.



As usual, feel free to contact us with questions.
Click here to return to the examples index, or continue on to Example 6.