## 40559Re: [libertybasic] Re: plot using EXCEL

Expand Messages
• Apr 4, 2010
Been playing w ur example - look below
Happy Easter - Kurt

' 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.
graphicbox #w.g, 0, 0, 530, 580
' Open the window showing this empty graphicbox
open "Kurt 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
RemĀ  WHY CAN't I print these values xRange; " "; yRange - They are real numbers
Rem From a REAL math formula.
Rem These are the "Dot" correct?
' step through the x range with small steps ( try bigger/smaller steps)
for x= -10 to 20 step .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
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.
' 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