Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Postscript to Vector Converter
FFT
INM's Impressario
Direct FTP 2.0
JTMR KoolMarquee
cXtraStringGrid
Animated Slider Puzzle by J.R.D.R.
Display Full Screen
Send E-mail using Buddy API
Vector Shape - Create Polygon
 

 

 

Behavior Graphing a Function

Added on 7/8/1999

 

Compatibilities:
D6_5 D7 D8 Mac PC Script Shockwave

This item has not yet been rated

Author: MatthewCaldwell

Draw a graph with lingo

-- some parameters to govern the way the graph displays
  -- set these before actually running drawGraph

  global xMin, xMax         -- range of values of x for which to compute y
  global yMin, yMax         -- range of values for y to display
  global xPrecision         -- number of steps to draw

  -- for the sake of argument, we"ll put a sprite in channel 1 to specify
  -- the bounds within which the graph is to be drawn, and put the drawing
  -- implement (a sprite containing a dot with trails on) in channel 2


  on drawGraph
    -- calculate scale factors
    set xRange = XMax - XMin
    set graphWidth = the right of sprite 1 - the left of sprite 1
    set xScale = float(graphWidth)/xRange
    set yRange = YMax - YMin
    set graphHeight = the bottom of sprite 1 - the top of sprite 1
    set yScale = float(graphHeight)/yRange
    set xBase = the left of sprite 1
    set yBase = the bottom of sprite 1

    -- calculate the difference between consecutive x values used
    set xInterval = float(xRange)/xPrecision

    repeat with i = 0 to xPrecision
      -- calculate x and y
      set x = xMin + xInterval * i
      set y = yourFunction(x)

      -- scale and offset them to stage coordinates
      set h = xBase + integer( i * xInterval * xScale )
      set v = yBase - integer( (y - yMin) * yScale )

      -- draw the point if it"s within the constraining sprite
      if v <= yBase and v >= the top of sprite 1 then
        set the locH of sprite 2 = h
        set the locV of sprite 2 = v
        updateStage
      end if
     end repeat
  end drawGraph

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail