Loading ...
Sorry, an error occurred while loading the content.

40532Re: [libertybasic] Re: plot using EXCEL

Expand Messages
  • RipSaw
    Apr 1, 2010
    • 0 Attachment
      look below,   I wish u were here.   This is like Greek.
      In England do you use any cool swear words that you can teach me?
      I cant slander the lord's name at easter.


      ________________________________
      From: John Fisher <mr.john.f@...>
      To: libertybasic@yahoogroups.com
      Sent: Thu, April 1, 2010 7:05:12 PM
      Subject: Re: [libertybasic] Re: plot using EXCEL

       
      Hope the following makes sense- I'd next want to add numbers and minor
      grid lines!
      Just copy & paste into LB/JB.
      Try altering bits you understand a tiny bit at a time, and check what
      happens.
      Reverse anything that fails to do what you want!
      We all started simple, and learned from others' code.
      The Help files are your first source- for eg. the names of available
      colours.

      JohnF

      ' We don't need the text-only 'mainwin' but it may help debugging
      ' by allowing us to see values.
      nomainwin
      ' But we DO need a graphicbox area in a 'Window'
      ' Choose size of this window (allow for scrollbars)
      WindowWidth = 530
      WindowHeight = 580
      ' Fit a 500 by 500 box to draw graphics with a nice border gap.
      WHAT IS #w.g,??  10, 10, is that thickness of border
      graphicbox #w.g, 10, 10, 500, 500 

      ' Open the window showing this empty graphicbox
      open "Simple Graph" for window as #w
      ' Make sure clicking 'close' icon at top RH exits cleanly.
      #w, "trapclose [quit]"
      ' Tell LB to put printing 'pen' down on page.
      #w.g, "down"
      ' Tell LB we want a rather bigger dot size than the normal 1 pixel.
      #w.g, "size 2"

      ' Work out how far apart lowest & highest x and y values are
      xMin =-10
      xMax = 20
      yMin = ( 1 /2 * -10 +1)
      yMax = ( 1 /2 * 20 +1)
      yRange = yMax -yMin
      xRange = xMax -xMin

      print xRange; " "; yRange

      ' step through the x range with small steps ( try bigger/smaller
      steps)
      for x= -10 to 20 step 0.1
      ' Work out the function's value at eac x position.
      y = 1 /2 *x +1
      ' Now you need to change so x_min plots at 0 and x_max at 500
      WHY NEED TO CHANGE ABOVE PLOTS?
      xScreen = int( ( x -xMin) /xRange *500)
      ' and same for y. BUT y in LB/MS counts down from top...
      ' so we subtract it from 500 so it counts up from bottom.
      yScreen =500 -int( ( y -yMin) /yRange *500)
      ' Send a 'set x y' command- it plots a dot at ( x_screen,
      y_screen)
      #w.g, "set "; xScreen; " "; yScreen
      next x

      ' This is hard to interpret, without axes drawn. We need range (
      -10, -5) to
      ' ( 20, 11) to be shown, with zero axes through ( 0, 0),
      ' but as before we scale, and invert y direction.
      ' First, horiz. axis thru. origin.
      ' Choose thicker line in colour red.
      #w.g, "size 4 ; color red"
      #w.g, "up ; goto 0 "; 500 -int( ( 0 -yMin) /yRange *500)
      #w.g, "down ; goto 500 "; 500 -int( ( 0 -yMin) /yRange *500)
      ' Now the vertical axis
      #w.g, "up ; goto "; int( ( 0 -xMin) /xRange *500); " 0"
      #w.g, "down ; goto "; int( ( 0 -xMin) /xRange *500); " 500"
      ' Should see now it goes from (-10, -4) through ( 0, 1) to ( 20, 11)

      ' This makes the graphics 'stick'. Otherwise if covered and then
      ' uncovered they are eerased and not re-drawn.
      #w.g, "flush"

      ' Hang around for 10 seconds ( 10000 ms)
      timer 10000, [on]
      wait
      [on]
      timer 0

      ' Put up a message for you to confirm (or not) printout.
      confirm "Send to printer?"; answer
      ' If wanted, do a printout..
      if answer then #w.g, "print vga"

      ' Wait, with graphic on-screen.wait

      ' Come to here only if 'close' icon clicked.
      [quit]
      ' Shut the window
      close #w
      ' Tell LB the program has ended!
      end







      [Non-text portions of this message have been removed]
    • Show all 22 messages in this topic