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

40568Re: [libertybasic] Re: plot using EXCEL

Expand Messages
  • RipSaw
    Apr 4, 2010
    • 0 Attachment
       
      Can I use "EasterEgg" instead of w.g?

      graphicbox #w.g, 2, 2, 800, 700
      OK 2, 2 is the border AROUND THE inner box - I dont like borders so I make it
      graphicbox #w.g, 0, 0, 800, 700
      800 is the vertical height 700 wide correct
       
      Where do I close BOTH windows?   window for lovely plot and window for data?
       
      ALL GRAPHICS PIXELS are from upper top left!  BUT WE MUST "trick" LB to an offset from bottom  -  TRUE/ FALSE?
       
      This line below, is how we plot the pixels  -  we "SET"     AM I CORRECT?
      #w.g, "set "; xScreen; " "; yScreen
       
      Im used to having a pretty 18 19 yr old keep me up all night! not a silly basic program!



      ________________________________
      From: John Fisher <mr.john.f@...>
      To: libertybasic@yahoogroups.com
      Sent: Sun, April 4, 2010 3:06:34 PM
      Subject: Re: [libertybasic] Re: plot using EXCEL

       
      Keep at it!
      Have altered the lines where you raised queries- see lines with
      ************ *

      ' We didn't need the text-only 'mainwin' but it helps debugging ***********
      ' by allowing us to see values.
      ' nomainwin '********* I've 'rem'arked this out. Now you can print ***
      ' BUT it is a separate window.
      ' Underneath YOUR window. Remember to close BOTH! **********

      ' We DO need a graphicbox area in a 'Window'
      ' Choose size of this window (allow for scrollbars)
      ' ************ ** These make a box - I like bigger *******
      ' *******sure- up to your screensize, eg 1280 by 1024 *****
      ' ***** the values below allow 800x700 plus title and borders****
      WindowWidth = 816
      WindowHeight = 740

      ' ***** Change positioning of your window ********
      UpperLeftX =1
      UpperLeftY =1
      ' Fit a 800 by 700 box to draw graphics with a nice border gap.
      ' ************ ** The window could be called 'MyWin' and the
      ' graphicbox 'MyWin.gbox' ************ ****
      ' Is there anything special abt #w.g? No. ************ ***
      ' Box inside outer box - I like 0,0,600,600 - Bigger box, fill paper.
      graphicbox #w.g, 2, 2, 800, 700

      ' 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

      'Why cant I print xRange and yRange? they are numbers from
      ' a math formula. I get a silly error msg ************ ********
      print xRange; " "; yRange ' It prints to the OTHER mainwin *****

      ' 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 each x position.
      y = 1 /2 *x +1
      ' Now you need to change so x_min plots at 0 and x_max at 800
      ' <<<< This number 500 is that 500 pixels from BOTTOM.***** YES

      xScreen = int( ( x -xMin) /xRange *800)
      ' 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.

      rem IF I UNDERSTAND EVERYTHING IS REFERENCED FROM BOTTOM, NEEDS OFFSET
      TO make plot
      ' ****** the 700 below IS the offset. On its own LB counts down from
      the top for y.***
      ' **** by adding offset 700 then SUBTRACTING calc'd y we **********
      ' **** find ourselves displaying back upwards from bottom, as
      wanted.*****
      yScreen =700 -int( ( y -yMin) /yRange *700)
      ' 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"
      Rem I do not see a line number 0, Is this pixel (dot) 0? *******
      ' ******** This line sets a size 4-pixel-wide red pen.

      #w.g, "up ; goto 0 "; 700 -int( ( 0 -yMin) /yRange *700)
      #w.g, "down ; goto 800 "; 700 -int( ( 0 -yMin) /yRange *700)
      ' Now the vertical axis - the two xRange * 500 - they for up down vertical?
      #w.g, "up ; goto "; int( ( 0 -xMin) /xRange *800); " 0"
      #w.g, "down ; goto "; int( ( 0 -xMin) /xRange *800); " 700"
      ' 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