Liberty BASIC Community Forum
« Sample Program .bas code »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 12:17am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 ... 4 5 6 7  Notify Send Topic Print
 locked  Author  Topic: Sample Program .bas code  (Read 907 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program spaceshp.bas
« Reply #75 on: Aug 18th, 2017, 2:41pm »

spaceship.bas

Simple tidy


Code:
    'open a graphical window and display spaceships

    nomainwin
    drawX = 40
    drawY = 40

    WindowWidth = 300
    WindowHeight = 250
    button #1, " OK ", [ok], LR, 40, 20
    open "SPACESHIPS" for graphics as #1
    #1 "trapclose [ok]"
    #1 "fill black"
    #1 "color white"

    for x = 1 to 5
        for y = 1 to 3
            gosub [Spaceships]
            drawY = drawY + 40
            angle = angle + 15
        next y
        drawY = 40
        drawX = drawX + 40
    next x

    wait

[ok]
    close #1
    end

[Spaceships]
    #1 "color white"
    #1 "place "; drawX; " "; drawY
    #1 "north; turn "; angle; "; down; turn 275; go 8; turn 85; go 10; turn 180; size 3; go 14"
    #1 "size 1"
    #1 "place "; drawX; " "; drawY
    #1 "north; turn "; angle; "; turn 85; go 8; turn 275; go 10; turn 180; size 3; go 14"
    #1 "size 1"
    #1 "place "; drawX; " "; drawY
    #1 "north; turn "; angle; "; turn 180; go 10; size 12; go 0"
    #1 "flush"
    #1 "size 1"
    return

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program sprgetxy.bas
« Reply #76 on: Aug 18th, 2017, 2:48pm »

sprgetxy.bas


Added a timer to slow things down and make it all visible and added quit


Code:
    'SPRGETXY.BAS  - demonstrate spritexy?
    'nomainwin

    'load the bitmaps we'll use as sprites & background
    loadbmp "smiley1", "sprites\smiley1.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"

    'open a window and graphicbox
    WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300

    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"
    #w.g "down"

    'add a background and sprite
    #w.g "background landscape";
    #w.g "addsprite smiley smiley1 smiley2 smiley3 smiley4";

    'tell the sprite to cycle one frame at a time, and move x5, y5
    #w.g "cyclesprite smiley 1"
    #w.g "spritemovexy smiley 5 5"


    timer 100, [draw]
    wait

[draw]
    'draw the next frame of animation
    #w.g "drawsprites"
    'get the x and y position of our sprite and print it out
    #w.g "spritexy? smiley x y"
    print x;" ";y
    if x>WindowWidth or y>WindowHeight then [quit]
    wait


[quit]
    print "program terminated"
    timer 0
    close#w
    end

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program spritepv.bas
« Reply #77 on: Aug 19th, 2017, 03:44am »

spritepv.bas

edit to add, this actually combines spritepv.bas and sprittim.bas

Simple tidy but also added a timed run to really show the difference between untimed and timed. Call it spriteTimer.bas ?

Code:
    'This program runs two sprite demos, the first free running
    'the second on a timed cycle.
    'nomainwin

    'get the sprite images and background
    loadbmp "smiley1", "sprites\smiley1.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"

    'open a window and graphicbox
    WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300
    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"

    'add a background and 4 sprites and animation cycling
    #w.g "background landscape"
    for x = 1 to 4
        spriteName$ = word$("smiley smiler smiled smiles", x)
        #w.g "addsprite "; spriteName$; " smiley1 smiley2 smiley3 smiley4"
        #w.g "cyclesprite "; spriteName$; " "; x; " once"
    next x

[freerunningAnimation]

    'set the sprite positions
    #w.g "spritexy smiley 0 0"
    #w.g "spritexy smiler 100 0"
    #w.g "spritexy smiled 0 100"
    #w.g "spritexy smiles 100 100"

    'set the sprite movement
    #w.g "spritemovexy smiley 1 1"
    #w.g "spritemovexy smiler -1 1"
    #w.g "spritemovexy smiled 1 -1"
    #w.g "spritemovexy smiles -1 -1"

    start = time$("ms")


[cycle]
    scan 'break out if user asks

    'draw another cycle of animation
    cycles = cycles + 1
    if cycles = 120 then
    'set the sprite movement
        #w.g "spritemovexy smiley -1 -1"
        #w.g "spritemovexy smiler 1 -1"
        #w.g "spritemovexy smiled -1 1"
        #w.g "spritemovexy smiles 1 1"
    end if
    if cycles = 340 then [finishfree]
    #w.g "backgroundxy "; cycles * 4; " 0"
    #w.g "drawsprites ; spritecollides smiley list$"
    if list$ > "" then #w.g "cyclesprite smiley 1 once"
    goto [cycle]


[finishfree]

    elapsed = (time$("ms") - start) / 1000
    print "Free running animation"
    print "Elapsed time: "; elapsed; " seconds"
    print "Frames per seconds: "; cycles / elapsed
    print
    print "that ran so fast you didn't even see it."
    print

[timedAnimation]
    'set the sprite positions
    #w.g "spritexy smiley 0 0"
    #w.g "spritexy smiler 100 0"
    #w.g "spritexy smiled 0 100"
    #w.g "spritexy smiles 100 100"

    'set the sprite movement
    #w.g "spritemovexy smiley 1 1"
    #w.g "spritemovexy smiler -1 1"
    #w.g "spritemovexy smiled 1 -1"
    #w.g "spritemovexy smiles -2 -2"

    start = time$("ms")
    cycles=0

    'set up a timer every 60 milliseconds
    timer 60, [timed]

[timed]

    'draw a cycle of animation then wait
    'for the timer to call [timed]
    cycles = cycles + 1
    if cycles = 120 then
    'set the sprite movement
        #w.g "spritemovexy smiley -1 -1"
        #w.g "spritemovexy smiler 1 -1"
        #w.g "spritemovexy smiled -1 1"
        #w.g "spritemovexy smiles 2 2"
    end if
    if cycles = 340 then [finishtimed]
    #w.g "backgroundxy "; cycles * 4; " 0"
    #w.g "drawsprites ; spritecollides smiley list$"
    if list$ > "" then #w.g "cyclesprite smiley 1 once"
    wait 'user can break out here

[finishtimed]

    elapsed = (time$("ms") - start) / 1000
    print "Timed animation"
    print "Elapsed time: "; elapsed; " seconds"
    print "Frames per seconds: "; cycles / elapsed
    print
    print "A timed animation is much more PC friendly than an untimed loop."

[quit]

    close #w
    end
 
« Last Edit: Aug 19th, 2017, 03:47am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program sprittst.bas
« Reply #78 on: Aug 19th, 2017, 03:53am »

sprittst.bas

Tidy and added trapclose/nomainwin etc

Code:
    'Simple sprite cycle demo
    nomainwin

    loadbmp "smiley1", "sprites\smiley1.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"
    WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300
    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"

    #w.g "background landscape";
    #w.g "addsprite smiley smiley1 smiley2 smiley3 smiley4";
    #w.g "cyclesprite smiley 1"

    timer 60, [draw]

[draw]
    #w.g "spritexy smiley "; x; " "; x
    #w.g "drawsprites";
    x=x+1
    if x=100 then [quit]
    wait

[quit]
    timer 0
    close #w
    end
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program sprttst2.bas
« Reply #79 on: Aug 19th, 2017, 04:09am »

sprttst2.bas


Tidy and timer nomainwin etc

Code:
    'Simple cycle sprite and sprite collide example
    nomainwin

    loadbmp "smiley1", "sprites\smiley1.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"
    WindowHeight = 300
    WindowWidth = 400
    'graphicbox #wg, 0, 0, 400, 300
    open "sprite test" for graphics_nf_nsb as #wg
    #wg "trapclose [quit]"

    #wg "background landscape";
    #wg "addsprite smiley smiley1 smiley2 smiley3 smiley4";
    #wg "addsprite smiler smiley1 smiley2 smiley3 smiley4";
    #wg "addsprite smiled smiley1 smiley2 smiley3 smiley4";
    #wg "addsprite smiles smiley1 smiley2 smiley3 smiley4";
    #wg "cyclesprite smiley 1 once"
    #wg "cyclesprite smiler 1"
    #wg "cyclesprite smiled 1"
    #wg "cyclesprite smiles 1"

    timer 60, [draw]

    [draw]

        #wg "spritexy smiley "; x; " "; x
        #wg "spritexy smiler "; 100-x; " "; x
        #wg "spritexy smiled "; 100-x; " "; 100-x
        #wg "spritexy smiles "; x; " "; 100-x
        #wg "drawsprites";
        #wg "spritecollides smiley list$"
        if list$ > "" then #wg "cyclesprite smiley 1 once"
    x=x+1
    if x=100 then [quit]
    wait


    [quit]
    timer 0
    close #wg
    end
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program sprttst3.bas
« Reply #80 on: Aug 19th, 2017, 04:19am »

sprtst3.bas


Tidy, timer nomainwin etc


Code:
    'Simple sprite visible demo
    nomainwin

    loadbmp "smiley", "sprites\smiley.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"
    WindowHeight = 300
    WindowWidth = 400
    graphicbox #w.g, 0, 0, 400, 300
    open "sprite test" for window_nf as #w
    #w "trapclose [quit]"

    #w.g "background landscape"
    #w.g "addsprite smiley smiley"
    timer 60, [draw]

[draw]
    if visible = 2 then
        visible = 1
    else
        visible = 2
    end if
    #w.g "spritexy smiley "; x; " "; x
    #w.g "spritevisible smiley "; word$("on off", visible)
    #w.g "drawsprites"
    x=x+2
    if x>=100 then [quit]
  wait

[quit]
  timer 0
  close #w
  end
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program sqrt.bas
« Reply #81 on: Aug 19th, 2017, 04:23am »

sqrt.bas


Code:
    'how to get the square root of a number
    'your own function
    print "The square root of "; 2; " is "; sqrt(2)

    'built in function
    print "The square root of 2 is ";sqr(2)
    end

function sqrt( a )
  sqrt = a ^ 0.5
end function
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program stringFromHex.bas
« Reply #82 on: Aug 19th, 2017, 04:30am »

stringFromHex.bas


Code:

print stringFromHex$("48 45 4C 4C 4F")

function stringFromHex$(hexValues$)

    'hexValues$ should be passed in this format "48 45 4C 4C 4F"
    hex$ = word$(hexValues$, 1)
    while hex$ <> ""
        stringFromHex$ = stringFromHex$ + chr$(hexDec(hex$))
        index = index + 1
        hex$ = word$(hexValues$, index+1)
    wend

end function
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program superEllipse.bas
« Reply #83 on: Aug 19th, 2017, 05:07am »

Don't plan to touch this though one or two things could be amended, flush for example.


superEllipse.bas
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program terminal.bas
« Reply #84 on: Aug 19th, 2017, 05:29am »

terminal.bas

This is about talking to a modem, I cant test it, not sure if it is relevant anymore but might as well keep it in the examples.


Code:

    'TERMINAL.BAS   -  A Liberty BASIC comms example
    'This program is to demonstrate the use of a communications port in Liberty
    'BASIC and is in no way intended to be useful for anything else.

    'Notes:
    '#comm is the handle for our comm port (we are using com1.  Change it if your modem
    '      is not on com1.

    '#window is the handle for our window

    '#window.te is the handle for our texteditor.  To display on-screen, we print to this

    '#window.gb is the handle for our graphicbox.  This object is outside the borders of
    '      our window so that it is hidden, and this is where we get the user keystrokes

    'Also, we use lof(#comm) to find out how many characters are waiting to be read from
    '      the com port, and we read those characters using the input$() function.

    nomainwin

    WindowWidth = 400
    WindowHeight = 300
    texteditor #window.te, 0, 0, 391, 254     'The handle for our texteditor is #window.te
    graphicbox #window.gb, 800, 1, 10, 10
    open "kb" for window as #window           'The handle for our window is #window
    print #window.gb, "when characterInput [getChar]"   'When the user presses a key go to [getChar]
    print #window, "trapclose [quit]"    'When the user closes our terminal window, go to [quit]
    print #window.te, "!autoresize";   'Tell the texteditor to resize with the terminal window
    print #window, "font courier_new 9";

    'Set the size of the communications buffer to 16K
    Com = 8192 * 2

    'Open communications port 1.  It's handle is #comm.
    'If you need to change to com 1, this is the line to modify
    open "COM1:9600,n,8,1,ds0,cs0,rs" for random as #comm

    prompt "Type a phone # or Enter to skip dialing."; phone$
    if phone$="" then [loop]

    'Reset the modem, wait 3 seconds for OK
    'This next section of code sends a reset, then waits for a response
    print #comm, "ATZ"     'Send ATZ to reset the modem
    print #window.te, "Attempting to reset modem..."   'Display to screen
    counter = 0
    ok = 0
    okTime$ = time$()
    entireResponse$ = ""
    while counter < 3 and ok = 0
        if lof(#comm) > 0 then
            response$ = input$(#comm, lof(#comm))
            entireResponse$ = entireResponse$ + response$
            print #window.te, response$;
            if instr(entireResponse$, "OK") > 0 then ok = 1
        end if
        if okTime$ <> time$() then
            okTime$ = time$()
            counter = counter + 1
        end if
    wend
    if ok = 0 then
        print #window.te, "Modem is not responding.  Please check your configuration."
        print #comm, ""
        goto [loop]
    end if



    'Wait 20 seconds for CONNECT or BUSY
    'This section has similar timeout code to the reset modem section
    print #window.te, "Dialing phone.  Will wait 20 secs for CONNECT."
    print #comm, "ATDT"; phone$    'Send ATDT and phone number to dial modem
    counter = 0
    ok = 0
    okTime$ = time$()
    entireResponse$ = ""
    while counter < 20 and ok = 0
        if lof(#comm) > 0 then
            response$ = input$(#comm, lof(#comm))
            print #window.te, response$;
            entireResponse$ = entireResponse$ + response$
            if instr(entireResponse$, "CONNECT") > 0 then ok = 1
            if instr(entireResponse$, "BUSY") > 0 then ok = -1
        end if
        if okTime$ <> time$() then
            okTime$ = time$()
            counter = counter + 1
        end if
    wend
    if ok = 0 then
        print #window.te, "CONNECT TIMEOUT"
    end if
    if ok = -1 then
        print #window.te, "Phone # " + phone$ + " is busy."
    end if

    print #comm, ""


[loop]

    'This is where our program spends most of its time after a successful CONNECT

    'If we want to capture keystrokes from our graphicbox, then it always needs
    'to have the input focus.  The next line ensures that it always does.
    print #window.gb, "setfocus"

    t$ = input$(#comm, lof(#comm))    'Get com port data
    if t$ <> "" then print #window.te, t$;    'Display com port data

    scan    'Check for input events

    goto [loop]


[getChar]

    'Whenever the user presses a key, we go here to process it.

    c$ = Inkey$
    'Send the character to the com port only if it is not a special keycode
    if len(c$) = 1 then print #comm, c$;
    goto [loop]


[quit]

    close #window
    close #comm
    end

 

User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program testdate.bas
« Reply #85 on: Aug 19th, 2017, 05:30am »

testdate.bas


Tweaked a little


Code:
    print "Get the date in various formats"
    print "1) ";date$()
    print "2) ";date$("days")
    print "3) ";date$("mm/dd/yy")
    print "4) ";date$("mm/dd/yyyy")
    print "5) ";date$("yyyy/mm/dd")
    print
    print"Set the date in various formats"
    print "6) ";date$("04/21/02")
    print "7) ";date$("Apr 21, 2002")
    print "8) ";date$(3)
    print "9) ";date$(4)
    'dates older than 1/1/1901 are negative
    print "10)";date$("Feb 5, 1776")
    print "11)";date$(-45620)
    print
    print "Assign date to a variable"
    d$ = date$()
    print "12)";date$(d$)
    print "13)";date$(date$())
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program textCalendar.bas
« Reply #86 on: Aug 19th, 2017, 05:39am »

textCalendar.bas


Unchanged


Code:
'simple text calendar example
'courtesy Jay Shrimplin

    aDate$= date$("mm/dd/yyyy")
    'aDate$="02/19/2003"
    locate int((28-len(monthname$(aDate$)))/2),y
    print monthname$(aDate$)+" "+right$(aDate$,4)
1 FirstDay=date$(word$(aDate$,1,"/")+"/1/"+word$(aDate$,3,"/"))
2 LastDay$=date$(date$(word$(date$(FirstDay+32),1,"/")+"/1/"+word$(date$(FirstDay+32),3,"/"))-1)
3 dow=val(word$("3 4 5 x 6 7 x 1 2",int((FirstDay/7-int(FirstDay/7))*10)+1))
    print " Sun Mon Tue Wed Thu Fri Sat"
4 for i=1 to val(mid$(LastDay$,4,2))
    y=int((i+dow-2)/7)
    x=(i+dow-2)-y*7
    x=4*x+2
    locate x,y+3
    print using("###",i)
    next i
    print:print " Today is ";
5 i=date$(aDate$)
6 print word$("Tuesday Wednesday Thursday x Friday Saturday x Sunday Monday",int((i/7-int(i/7))*10)+1);
    print " ";aDate$
    wait

    function monthname$(aDate$)
    month=val(aDate$)
    monthname$=word$("January Febuary March April May June July August September October November December",month)
    end function

'--------------------------------------------------------------------------------------------------
'     JulianDay = days since 1901
' (1) Find first day of month - Take current and change day to 1 "02/12/2003" >> "02/1/2003"
' (2) Find last day of month - Take first day and add 32 days to julian makes date next month.
'     Then find first day of that month "03/4/2003" >> "03/1/2003" subtract 1 from julian and you
'     then change julian to mm/dd/yy and you find the last day of any month without leap year issues.
' (3) Find day of week of first day.
'     dow=val(word$("3 4 5 x 6 7 x 1 2",int((i/7-int(i/7))*10)+1))
'     Sun=1 Mon=2 and so on. Where (i) = JulianDay
' (4) (i) = 1 to last day of the month found.
' (5) Change "mm/dd/yyyy" to JulianDay.
' (6) dow$=word$("Tuesday Wednesday Thursday x Friday Saturday x Sunday Monday",int((i/7-int(i/7))*10)+1);
'     where (i) = JulianDay

 



User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program threePointCircle.bas
« Reply #87 on: Aug 19th, 2017, 05:41am »

threePointCircle.bas



Unchanged


Code:
'     Title: 3 Point Circle
'Programmer: Andy Amaya
'     Date: 2005.02.24

NoMainWin
Dim p(3,1)
WindowWidth = 800
WindowHeight = 600
UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
UpperLeftY = Int((DisplayHeight-WindowHeight)/2)
Open "3 Point Circle" For Graphics_nsb_nf As #g
#g "Down; TrapClose [ndit]"

[ThreePoints]
    #g,"Fill 0 32 96; Color white; BackColor 0 32 96; when rightButtonDown"
    Print text(500,565,"Left-click points on screen")
    #g,"Discard"
    numPoints = 3
    points = 0
[getPointsLoop]
    If points < numPoints Then
        #g,"when leftButtonDown [getCoords]"
        Wait
[returnHere]
        p(points,0)=mx
        p(points,1)=my
        points = points + 1
        #g,"Color white; BackColor 0 32 96"
        Print text(10,points*20," point"+Str$(points)+": ("+Str$(mx)+" , "+Str$(my)+")")
    Else
        #g,"Color white; BackColor 0 32 96"
        Print text(500,565,"(Left-click to draw the circle)")
        #g,"Discard; when leftButtonDown [drawCircle]"
        Wait
    End If
    Scan
    Goto [getPointsLoop]

[getCoords]
    mx = MouseX
    my = MouseY
    #g,"Color red; BackColor red; Place ";mx;" ";my
    #g,"CircleFilled 5"
    Goto [returnHere]

[drawCircle]
    x1 = p(0,0): y1 = p(0,1)
    x2 = p(1,0): y2 = p(1,1)
    x3 = p(2,0): y3 = p(2,1)
'===Begin parameter validation=================
    'If line segment x1,y1 to x2,y2 is vertical
    'will cause a divide by zero error when
    'calculating the slope, so swap the
    'points around to avoid the error.
    If x1 = x2 Then
        temp = x2
        x2 = x3
        x3 = temp
        temp = y2
        y2 = y3
        y3 = temp
    End If
    'Same goes for these points
    If x2 = x3 Then
        temp = x1
        x1 = x3
        x3 = temp
        temp = y1
        y1 = y3
        y3 = temp
    End If

    'ma and mb are the slopes of the lines for by x1,y1 to x2,y2
    'and x2,y2 to x3,y3 (respectively)
    ma = (y2-y1)/(x2-x1)
    mb = (y3-y2)/(x3-x2)

    If mb - ma = 0.0 Then
        'If all three points are on the same line, can't draw circle
        Print text(400,20,"Points are coincident, no circle exists!")
    Else
    'Local constants:
        pi2 = Atn(1)*8.0
        stepSize = pi2/128.0

        'Find center X coord using this formula
        cX = ( (ma*mb*(y1-y3)) + (mb*(x1+x2)) - (ma*(x2+x3)) ) / (2 * (mb-ma))
        'Show the value of center X on screen
        #g,"Color white; BackColor 0 32 96"
        Print text(10,80,"centerX = "+Str$(cX))

        'Find center Y coord using this formula
        cY = (-1.0/ma) * (cX-(x1+x2)/2.0) + ((y1+y2)/2.0)
        'Show the value of center Y on screen
        Print text(10,100,"centerY = "+Str$(cY))

        'Plot the center of the circle using green colored dot
        #g,"Color green;BackColor green;Place ";cX;" ";cY
        #g,"CircleFilled 5"

        'Since we now know the center coords just find the distance
        'from the center to any of the given coords (point x1,y1 here)
        'and this is the radius
        radius = Sqr( (cX-x1)*(cX-x1) + (cY-y1)*(cY-y1) )

        'Print radius value to the screen
        #g,"Color white; BackColor 0 32 96"
        Print text(10,120," radius = "+Str$(radius))

        'All of the necessary info is at hand so draw the circle
        #g,"Color yellow; Size 1; Place ";radius + cX;" ";cY
        For i = stepSize To pi2 Step stepSize
            nX = Cos(i)*radius + cX
            nY = Sin(i)*radius + cY
            #g,"Goto ";nX;" ";nY
        Next i
    End If

    'All done. Give user choice of repeating or exiting program
    #g,"Color 0 32 96; BackColor 0 32 96; Place 500 ";WindowHeight-55
    #g,"BoxFilled ";WindowWidth;" ";WindowHeight;"; Color white"
    Print text(500,565, "Left-click to [EXIT]     Right-click to [Repeat]")
    #g,"SetFocus; when leftButtonDown [ndit]; when rightButtonDown [ThreePoints]"
    Wait

[ndit]
Close #g
End

Function text(x,y,msg$)
    #g,"Place ";x;" ";y;";|";msg$
End Function

 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program timerexample.bas
« Reply #88 on: Aug 19th, 2017, 05:56am »

timerexample.bas

Still an example of a sub timer delay but more controls to show it works.


Code:
    nomainwin
    WindowWidth = 500
    WindowHeight = 300
    UpperLeftX = 0
    UpperLeftY = 0

    button #1.b1, "Press Me", buttonOneHandler, LR, 200, 10
    button #1.b2, "Press Me", buttonTwoHandler, LR, 50, 10
    textbox #1.tb, 20,20,200,20
    open "Demo" for window as #1
    #1 "trapclose quit"

    global count
    while 1
        scan
        call countUp
    wend

    sub countUp
        count=count+1
        #1.tb "Count is now ";count
        timer 1000,[delay]
        wait
        [delay]
        timer 0
    end sub

    Sub buttonOneHandler handle$
        #1.tb "You pressed button one"
    end sub

    sub buttonTwoHandler handle$
        #1.tb "You pressed button two"
    end sub

    sub quit handle$
        timer 0
        close #1
        end
    end sub
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5526
xx Re: Sample Program tiny basic.bas
« Reply #89 on: Aug 19th, 2017, 05:59am »

tiny basic.bas


unchanged


code too big to post
User IP Logged

Pages: 1 ... 4 5 6 7  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls