Search content:

 

Personal Menu
Username:
Password:
Save password

Become a member

Forgot Password?

 

Don't miss these
Copy Text - Non Editable Fields & Shockwave
cXtraTransitionMorphing
MPEG Video
Export Text for proofing
Hybrid CD
2D Collision from Explore Science
Which Keys
E-mailExec 3 Pro
Simple Paint application
Drop File
MediaMacros Xtras Mall
 

 

 

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

 


Upload Provided by ABCUpload ASP

Contact

MMI
22 West Court Sq
Suite 2C
Newnan, GA 30263
USA

Fax - (206) 339-5833

Send e-mail