Hi All,
I hope this is an easy one for someone to point out my mistake. However I did find some reference to timer behaviour in windows that was different to Linux, so I tried this in Fedora, but both OSs ran the same. I found this example (I've modified it for QB64 timer only - didn't work as I expected with 'legacy' timer either). I expected that the clock would update at a rate of once per second, but that the A would be printed every 6 seconds (due to the sleep). However, if you run it the print A occurs every timer tick. What am I missing? Thanks!
Code: (Select All)
$Debug
timerhandle% = _FreeTimer
Timer(timerhandle%) On ' enable timer event trapping
Screen 0
Locate 4, 2 ' set the starting PRINT position
On Timer(timerhandle%, 1) GoSub Clock ' set procedure execution repeat time
Rem Sleep
Do While InKey$ = "": Print "A";: Sleep 6: Loop
Timer Off
System
Clock:
row = CsrLin ' Save current print cursor row.
col = Pos(0) ' Save current print cursor column.
Locate 2, 37: Print Time$; " "; Date$ ' print current time at top of screen.
Locate row, col ' return to last print cursor position
Return
Posted by: SierraKen - 08-15-2024, 05:52 AM - Forum: SierraKen
- No Replies
For awhile, I was doing a lot of graphical stuff. Here is one of them that makes a random scene of hills, trees, and a randomly placed creek. On this new version, I added file dialog to save the picture to JPG, PNG, GIF, or BMP. Press S to Save the picture if you wish, or the Space Bar to make a new picture.
Code: (Select All)
'Made on Dec. 21, 2019 by SierraKen
'Version 2: August 14, 2024 added file dialog box when saving.
_Title "Scene Generator 2 - by SierraKen - Space Bar for new scene, (S)ave Picture, Esc to quit."
start:
_Limit 500
Cls
picture& = _NewImage(800, 600, 32)
Screen picture&
'Draw sky.
Randomize Timer
sky = Int(Rnd * 154) + 100
For sk = 0 To 299
sky = sky + .25
If sky > 255 Then sky = 255
Line (0, sk)-(800, sk), _RGB32(0, 0, sky)
Next sk
'Draw ground.
Randomize Timer
cc2 = Int(Rnd * 50) + 20
For cc = 300 To 600
cc2 = cc2 + .5
Line (0, cc)-(800, cc), _RGB32(116, cc2, 0)
Next cc
y = 300
Randomize Timer
c1 = Int(Rnd * 100) + 20
c2 = Int(Rnd * 150) + 60
c4 = c2
c3 = Int(Rnd * 100) + 20
t = 0
tt = 0
si = 0
'Draw hills.
amount = Int(Rnd * 40) + 5
For t = 1 To amount
_Limit 100
Randomize Timer
x = (Rnd * 800) + 1
s = (Rnd * 250) + 1
aspect = Rnd * 2
For sz = .25 To s Step .25
c2 = c2 + .05
If c2 > 255 Then c2 = 255
Circle (x, y), sz, _RGB32(c1, c2, c3), 2 * _Pi, _Pi, aspect
Next sz
c2 = c4
l = .5
Next t
'Draw grass.
For grassy = 300 To 600 Step 2.5
For grassx = 0 To 800 Step 2
Randomize Timer
sst = Rnd * 2
sst2 = Rnd * 1
Line (grassx + sst, grassy + sst2)-(grassx + sst, (grassy + sst2) - l), _RGB32(50, 255, 127)
Next grassx
l = l + .025
If l > 4 Then l = 4
Next grassy
'Draw random river.
yy = 305
Randomize Timer
xx = (Rnd * 650) + 50
rw = 2
Do
If yy > 600 Then GoTo trees:
_Delay .1
tt = tt + 1
si = si + 1
yy = yy + (si * 2)
If tt = 1 Then
For sz = 1 To 5 Step .25
Circle (xx, yy), si + sz, _RGB32(6, 128, 255), _Pi / 2, (3 / 2) * _Pi
Next sz
End If
If tt = 2 Then
For sz = 1 To 5 Step .25
Circle (xx, yy), si - sz, _RGB32(6, 128, 255), (3 / 2) * _Pi, _Pi / 2
Next sz
tt = 0
End If
Loop
'Bare Trees
trees:
Randomize Timer
trees = Int(Rnd * 25) + 3
For tree = 1 To trees
Randomize Timer
xt = Rnd * 800
yt = (Rnd * 300) + 300
length = yt * 8 / 160
th = yt / 100
For thick = 1 To th
Line (xt + thick, yt)-(xt + thick, yt - length), _RGB32(211, 83, 6)
'left side
Line (xt + thick, yt - length)-((xt - length) + thick, yt - length * 2), _RGB32(211, 83, 6)
Line ((xt - length) + thick, yt - (length * 2))-((xt - (length * 2)) + thick, yt - (length * 3)), _RGB32(211, 83, 6)
Line ((xt - length) + thick, yt - (length * 2))-((xt - (length * 1.5) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
'right side
Line ((xt + thick), yt - length)-((xt + length) + thick, yt - (length * 2)), _RGB32(211, 83, 6)
Line ((xt + length) + thick, yt - (length * 2))-((xt + (length * 2) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
Line ((xt + length) + thick, yt - (length * 2))-((xt + (length * 1.5) + thick), yt - (length * 3)), _RGB32(211, 83, 6)
Next thick
Next tree
again:
ag$ = InKey$
If ag$ = "s" Or ag$ = "S" Then GoTo saving:
If ag$ = " " Then GoTo start:
If ag$ = Chr$(27) Then End
GoTo again:
saving:
picture2& = _CopyImage(picture&)
_Delay .2
saving2:
nm$ = _SaveFileDialog$("Save File", "", "*.jpg|*.png|*.gif|*.bmp", "Picture Files .jpg,.png,.gif,.bmp")
If nm$ = "" Then GoTo again:
_SaveImage nm$, picture&
For snd = 100 To 700 Step 100
Sound snd, 2
Next snd
GoTo again:
Posted by: SierraKen - 08-15-2024, 03:54 AM - Forum: SierraKen
- No Replies
Lots of goodies on this one.
Code: (Select All)
'Calculator
'By SierraKen on July 30, 2020.
'Updated on July 24, 2022 with Copy and Paste Buttons.
'Updated on July 26, 2022 with Back Space Button and RND (Random) Button
'Update on July 29, 2022 with math fix problem with Pete's help.
'-----------------------------------------------------------------------
'This is my very first regular calculator.
'Thank you to B+ and TempodiBasic for the help and everyone for the inspiration!
'Thanks Pete for the math help!
_Title "Calculator - Esc for help."
Dim num As Double
Screen _NewImage(400, 525, 32)
f& = _LoadFont("Arial.ttf", 18)
begin:
_Font f&
num$ = ""
c = 0
a = 0: s = 0: t = 0: d = 0
'Setup calculator
Line (50, 25)-(265, 50), _RGB32(255, 255, 255), B
Line (50, 75)-(350, 350), _RGB32(255, 255, 255), B
'Buttons
For buttony = 75 To 405 Step 55
For buttonx = 50 To 275 Step 75
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
Next buttonx
Next buttony
'Copy Button
buttonx = 50: buttony = 460
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Paste Button
buttonx = 125: buttony = 460
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Back Space Button
buttonx = 200: buttony = 460
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Random Number Button
buttonx = 275: buttony = 460
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(100 + c, 100 + c, 100 + c)
c = 0
'Green C Button
buttonx = 275: buttony = 20
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
Paint (buttonx + 12, buttony + 12), _RGB32(50, 100 + c, 50)
Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PrintString (50, 5), "Rad"
wer:
'Label Buttons
_PrintString (306, 47), "C"
Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PrintString (87, 102), Chr$(251) 'square root
_PrintString (152, 102), "sin"
_PrintString (227, 102), "cos"
_PrintString (302, 102), "tan"
_PrintString (87, 157), "7"
_PrintString (162, 157), "8"
_PrintString (237, 157), "9"
_PrintString (312, 157), "/"
_PrintString (87, 212), "4"
_PrintString (162, 212), "5"
_PrintString (237, 212), "6"
_PrintString (312, 212), "x"
_PrintString (87, 267), "1"
_PrintString (162, 267), "2"
_PrintString (237, 267), "3"
_PrintString (312, 267), "-"
_PrintString (87, 322), "0"
_PrintString (162, 322), "."
_PrintString (237, 322), "="
_PrintString (312, 322), "+"
_PrintString (79, 377), " "
_PrintString (79, 377), "deg"
_PrintString (162, 377), "x" + Chr$(253) 'second power
_PrintString (227, 377), "log"
_PrintString (307, 377), "Pi"
_PrintString (79, 432), "1/x"
_PrintString (152, 432), "x/2"
_PrintString (227, 432), "exp"
_PrintString (312, 432), Chr$(241) 'Postive or Negative
_PrintString (68, 487), "Copy"
_PrintString (141, 487), "Paste"
_PrintString (210, 487), "<Back"
_PrintString (293, 487), "RND"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
Do
_Limit 30
a$ = InKey$
If a$ <> "" Then mousex = 0: mousey = 0: mouseLeftButton = 0
If a$ = Chr$(27) Then GoTo help:
If a$ = Chr$(3) Then a$ = "": GoTo clip: 'Ctrl+C copies to clipboard.
If a$ = "C" Or a$ = "c" Then a$ = "": GoTo delete: 'Back Space deletes output.
If a$ = "p" Or a$ = "P" Or a$ = "n" Or a$ = "N" Then a$ = "": GoTo posneg: 'Positive or Negative
If a$ = "f" Or a$ = "F" Then a$ = "": GoTo fraction:
If a$ = "h" Or a$ = "H" Then a$ = "": GoTo half:
If a$ = "e" Or a$ = "E" Then a$ = "": GoTo expcommand:
If a$ = "r" Or a$ = "R" Or a$ = "d" Or a$ = "D" Then a$ = "": GoTo radanddeg:
If a$ = "u" Or a$ = "U" Then a$ = "": GoTo squared:
If a$ = "l" Or a$ = "L" Then a$ = "": GoTo logarithm:
If a$ = "i" Or a$ = "I" Then a$ = "": GoTo pi:
If a$ = "q" Or a$ = "Q" Then a$ = "": GoTo squareroot:
If a$ = "s" Or a$ = "S" Then a$ = "": GoTo sine:
If a$ = "o" Or a$ = "O" Then a$ = "": GoTo cosine:
If a$ = "t" Or a$ = "T" Then a$ = "": GoTo tangent:
If a$ = "1" Then a$ = "": GoTo one:
If a$ = "2" Then a$ = "": GoTo two:
If a$ = "3" Then a$ = "": GoTo three:
If a$ = "4" Then a$ = "": GoTo four:
If a$ = "5" Then a$ = "": GoTo five:
If a$ = "6" Then a$ = "": GoTo six:
If a$ = "7" Then a$ = "": GoTo seven:
If a$ = "8" Then a$ = "": GoTo eight:
If a$ = "9" Then a$ = "": GoTo nine:
If a$ = "0" Then a$ = "": GoTo zero2:
If a$ = "." Then a$ = "": GoTo decimal:
If a$ = "=" Then a$ = "": GoTo equals:
If a$ = "+" Then a$ = "": GoTo add:
If a$ = "-" Then a$ = "": GoTo subtract:
If a$ = "*" Or a$ = "x" Or a$ = "X" Then a$ = "": GoTo multiply:
If a$ = "/" Then a$ = "": GoTo divide:
If a$ = Chr$(8) Then a$ = "": GoTo backbutton:
If mouseLeftButton Then
Clear_MB 1
'Clipboard
If mousex > 50 And mousex < 265 And mousey > 25 And mousey < 50 Then
clip:
Color _RGB32(0, 255, 0), _RGB32(0, 0, 0)
_PrintString (55, 30), num$
_Delay .5
num2$ = _Trim$(num$)
_Clipboard$ = num2$
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PrintString (55, 30), num$
End If
'Clipboard Button
If mousex > 50 And mousex < 125 And mousey > 460 And mousey < 515 Then
clip2:
Color _RGB32(0, 255, 0), _RGB32(0, 0, 0)
_PrintString (55, 30), num$
buttonx = 50: buttony = 460
GoSub press:
_Delay .5
num2$ = _Trim$(num$)
_Clipboard$ = num2$
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PrintString (55, 30), num$
End If
'Paste Button
If mousex > 125 And mousex < 200 And mousey > 460 And mousey < 515 Then
paste:
buttonx = 125: buttony = 460
GoSub press:
num$ = _Clipboard$
If Len(num$) > 19 Then num$ = "0"
_PrintString (55, 30), num$
num = Val(num$)
GoSub number:
End If
'Back Space Button
If mousex > 200 And mousex < 275 And mousey > 460 And mousey < 515 Then
backbutton:
buttonx = 200: buttony = 460
GoSub press:
num$ = Left$(num$, Len(num$) - 1)
GoSub number2
End If
'Random Button
If mousex > 275 And mousex < 350 And mousey > 460 And mousey < 515 Then
timebutton:
buttonx = 275: buttony = 460
GoSub press:
num$ = Str$(Rnd)
_PrintString (55, 30), num$
num = Val(num$)
GoSub number:
End If
'Clear
If mousex > 275 And mousex < 350 And mousey > 20 And mousey < 75 Then
delete:
a = 0: s = 0: t = 0: d = 0: num$ = ""
_PrintString (55, 30), " "
buttonx = 275: buttony = 20
GoSub zero:
End If
'1/x
If mousex > 50 And mousex < 125 And mousey > 405 And mousey < 460 Then
fraction:
num = Val(num$)
If num = 0 Then GoTo skipthis:
num = 1 / num
num$ = Str$(num)
skipthis:
buttonx = 50: buttony = 405
GoSub press:
GoSub number:
End If
'x/2
If mousex > 126 And mousex < 200 And mousey > 405 And mousey < 460 Then
half:
num = Val(num$)
num = num / 2
num$ = Str$(num)
buttonx = 126: buttony = 405
GoSub press:
GoSub number2:
End If
'EXP
If mousex > 200 And mousex < 275 And mousey > 405 And mousey < 460 Then
expcommand:
_PrintString (55, 30), " "
num = Exp(Val(num$))
num$ = Str$(num)
buttonx = 200: buttony = 405
GoSub number2:
GoSub press:
End If
'Postive or Negative
If mousex > 275 And mousex < 350 And mousey > 405 And mousey < 460 Then
posneg:
If Val(num$) = 0 Then GoTo skipplusnegative:
If Val(num$) < 0 Then
num = -Val(num$)
num$ = Str$(num)
GoTo skipplusnegative:
End If
num$ = "-" + num$
skipplusnegative:
buttonx = 275: buttony = 405
GoSub press:
GoSub number:
End If
'Radians and Degrees
If mousex > 50 And mousex < 125 And mousey > 350 And mousey < 405 Then
radanddeg:
deg = deg + 1
If deg = 2 Then GoTo deg2rad:
Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PrintString (79, 377), " "
_PrintString (79, 377), "rad"
Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PrintString (50, 5), "Deg"
num = Val(num$)
num = _R2D(num)
num$ = Str$(num)
GoTo skipdeg2rad:
deg2rad:
deg = 0
Color _RGB32(0, 0, 0), _RGB32(210, 210, 210)
_PrintString (79, 377), " "
_PrintString (79, 377), "deg"
Color _RGB32(0, 0, 0), _RGB32(50, 100 + c, 50)
_PrintString (50, 5), "Rad"
num = Val(num$)
num = _D2R(num)
num$ = Str$(num)
skipdeg2rad:
buttonx = 50: buttony = 350
GoSub press:
GoSub number:
End If
'Second Power
If mousex > 126 And mousex < 200 And mousey > 350 And mousey < 405 Then
squared:
num = Val(num$)
num = num ^ 2
num$ = Str$(num)
buttonx = 126: buttony = 350
GoSub press:
GoSub number2:
End If
'logarithm
If mousex > 200 And mousex < 275 And mousey > 350 And mousey < 405 Then
logarithm:
num = Val(num$)
If num = 0 Then GoTo skiplog:
If num < 0 Then GoTo skiplog:
num = Log(num)
num$ = Str$(num)
skiplog:
buttonx = 200: buttony = 350
GoSub press:
GoSub number:
End If
'Pi
If mousex > 275 And mousex < 350 And mousey > 350 And mousey < 405 Then
pi:
'num = 3.14159265359
num = _Pi
num$ = Str$(num)
buttonx = 275: buttony = 350
GoSub press:
GoSub number:
End If
'Square Root
If mousex > 50 And mousex < 125 And mousey > 75 And mousey < 130 Then
squareroot:
If num < 0 Then GoTo skip1:
num = Val(num$)
num = Sqr(num)
num$ = Str$(num)
skip1:
buttonx = 50: buttony = 75
GoSub press:
GoSub number:
End If
'Sine
If mousex > 126 And mousex < 200 And mousey > 75 And mousey < 130 Then
sine:
If deg = 1 Then num = Sin(_D2R(Val(num$)))
If deg = 0 Then num = Sin(num)
num$ = Str$(num)
buttonx = 126: buttony = 75
GoSub press:
GoSub number:
End If
'Cosine
If mousex > 200 And mousex < 275 And mousey > 75 And mousey < 130 Then
cosine:
If deg = 1 Then num = Cos(_D2R(Val(num$)))
If deg = 0 Then num = Cos(num)
num$ = Str$(num)
buttonx = 200: buttony = 75
GoSub press:
GoSub number:
End If
'Tangent
If mousex > 275 And mousex < 350 And mousey > 75 And mousey < 130 Then
tangent:
If deg = 1 Then num = Tan(_D2R(Val(num$)))
If deg = 0 Then num = Tan(num)
num$ = Str$(num)
buttonx = 275: buttony = 75
GoSub press:
GoSub number:
End If
'Number Buttons
If mousex > 50 And mousex < 125 And mousey > 130 And mousey < 185 Then
seven:
num$ = num$ + "7"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 50: buttony = 130
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 130 And mousey < 185 Then
eight:
num$ = num$ + "8"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 126: buttony = 130
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 130 And mousey < 185 Then
nine:
num$ = num$ + "9"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 200: buttony = 130
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 185 And mousey < 240 Then
four:
num$ = num$ + "4"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 50: buttony = 185
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 185 And mousey < 240 Then
five:
num$ = num$ + "5"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 126: buttony = 185
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 185 And mousey < 240 Then
six:
num$ = num$ + "6"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 200: buttony = 185
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 240 And mousey < 295 Then
one:
num$ = num$ + "1"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 50: buttony = 240
GoSub press:
GoSub number:
End If
If mousex > 126 And mousex < 200 And mousey > 240 And mousey < 295 Then
two:
num$ = num$ + "2"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 126: buttony = 240
GoSub press:
GoSub number:
End If
If mousex > 200 And mousex < 275 And mousey > 240 And mousey < 295 Then
three:
num$ = num$ + "3"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 200: buttony = 240
GoSub press:
GoSub number:
End If
If mousex > 50 And mousex < 125 And mousey > 295 And mousey < 350 Then
zero2:
If num$ <> "0" Then ' Prevents more than one leading zero input.
num$ = num$ + "0"
If n = 1 Then num$ = "-" + num$: n = 0
buttonx = 50: buttony = 295
GoSub press:
GoSub number:
End If
End If
'Decimal
If mousex > 126 And mousex < 200 And mousey > 295 And mousey < 350 Then
decimal:
buttonx = 126: buttony = 295
For check = 1 To Len(num$)
If Mid$(num$, check, 1) = "." Then GoTo skipdec:
Next check
num$ = num$ + "."
_PrintString (55, 30), num$
skipdec:
GoSub press:
End If
'Equals
If mousex > 200 And mousex < 275 And mousey > 295 And mousey < 350 Then
equals:
If a = 1 Then num = Val(oldnum$) + Val(num$): a = 0
If s = 1 Then num = Val(oldnum$) - Val(num$): s = 0
If t = 1 Then num = Val(oldnum$) * Val(num$): t = 0
If d = 1 Then num = Val(oldnum$) / Val(num$): d = 0
buttonx = 200: buttony = 295
GoSub press:
GoSub number2:
num$ = ""
num = 0
oldnum$ = ""
End If
'Add
If mousex > 275 And mousex < 350 And mousey > 295 And mousey < 350 Then
add:
d = 0: a = 1: s = 0: t = 0
GoSub convert:
oldnum$ = num$
_PrintString (55, 30), " "
num$ = ""
buttonx = 275: buttony = 295
GoSub press:
End If
'Subtract
If mousex > 275 And mousex < 350 And mousey > 240 And mousey < 295 Then
subtract:
d = 0: a = 0: s = 1: t = 0
GoSub convert:
oldnum$ = num$
_PrintString (55, 30), " "
num$ = ""
buttonx = 275: buttony = 240
GoSub press:
End If
'Multiply
If mousex > 275 And mousex < 350 And mousey > 185 And mousey < 240 Then
multiply:
If t = 0 Then
d = 0: a = 0: s = 0: t = 1
GoSub convert:
oldnum$ = num$
_PrintString (55, 30), " "
num$ = ""
GoTo nex2:
End If
If t = 1 Then
num = Val(oldnum$) * Val(num$)
t = 0
End If
GoSub number2:
nex2:
buttonx = 275: buttony = 185
GoSub press:
End If
'Divide
If mousex > 275 And mousex < 350 And mousey > 130 And mousey < 185 Then
divide:
If d = 0 Then
d = 1: a = 0: s = 0: t = 0
GoSub convert:
oldnum$ = num$
_PrintString (55, 30), " "
num$ = ""
GoTo nex1:
End If
If d = 1 And num$ <> "" Then
num = Val(oldnum$) / Val(num$)
d = 0
End If
GoSub number2:
nex1:
buttonx = 275: buttony = 130
GoSub press:
End If
End If
Loop
'For Number Buttons.
convert:
If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
num$ = Left$(num$, 19)
End If
num = Val(num$)
Return
number:
If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
num$ = Left$(num$, 19)
End If
'For Math
number2:
Color _RGB32(0, 0, 0), _RGB32(0, 0, 0)
_PrintString (55, 30), Space$(40)
If Val(num$) > 9999999999999999 Or Len(num$) > 19 Then
num$ = Left$(num$, 19)
End If
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
_PrintString (55, 30), num$
Return
'Pressing Each Button
press:
c = 110
For bb = 0 To 10
c = c - 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
_Delay .03
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(100 + c, 100 + c, 100 + c), B
Next bb
Return
'Pressing the Green C Button.
zero:
c = 110
For bb = 0 To 10
c = c - 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
_Delay .25
For bb = 0 To 10
c = c + 10
Line (buttonx + bb, buttony + bb)-(buttonx + 75 - bb, buttony + 55 - bb), _RGB32(50, 100 + c, 50), B
Next bb
Return
help:
_Font 14
Cls
_Title "Calculator Help"
Print "Esc = Keyboard Help"
Print "CTRL+C = Copies To Clipboard"
Print "Left Mouse Click Copies To Clipboard."
Print "Copy Button Copies To Clipboard"
Print "Paste Button Pastes Clipboard To Screen"
Print "Backspace = Deletes Last Output Digit"
Print "RND = Makes a random number from 0 to 1."
Print "Letters can be upper or lower-case."
Print "P or N = Positve and Negative Switch."
Print "F = 1 / x"
Print "H = x / 2"
Print "E = EXP"
Print "R or D = Radian and Degree Switch."
Print "U = X ^ 2"
Print "L = Logarithm"
Print "I = Pi"
Print "Q = Square Root"
Print "s = Sine"
Print "o = Cosine"
Print "t = Tangent"
Print
Print "Below can be either Number Pad or the others."
Print "1-9 = Number Keys"
Print ". = Decimal"
Print "= = Equals"
Print "+ = Add"
Print "- = Subtract"
Print "* or X = Multiply"
Print "/ = Divide"
Print
Print "Press Esc to go back to calculator."
Do: Loop Until InKey$ = Chr$(27)
Cls
_Title "Calculator - Esc for help."
GoTo begin:
Sub Clear_MB (var As Integer)
Do Until Not _MouseButton(var)
While _MouseInput: Wend
Loop
This was an ongoing project started many years ago. It first started as a plotting program making data files for the picture. Then as it progressed I got help from B+, Steve, and Dav to make what it is today, thanks guys! It has regular brush painting, lines, boxes, circles, fill-in, erasing (using lines), text (including 3D text) and can open and save using windows file dialog. It uses a pop-up menu that comes up when you right click the mouse. It can open and save JPG, PNG, and BMP pictures. If you don't add one of these endings to a filename when you save it, it automatically saves as JPG. It can also print on a printer.
It starts out with a brief explanation of the program and then it asks what size you would like your picture, then it goes to a color wheel to choose your background color, and then color sliders to choose your paint color which was made by B+. And then you paint!
Unzip "Paint Pixels 8.zip" to its own folder. Have fun!
Newest update with some bug fixes at 10:42 AM Pacific Time, Aug. 15, 2024.
This is a painting program with a few different features.
It is a large QB64 app I made years ago, but for some reason the .bm files aren't working. If I removed them, the code in the program isn't recognized. One is for saving pictures and the other one is for making a File drop-down menu. Here is the zip file of all the needed files. Here is version 8. I'll also post the one Bplus made as well, which is version 7, so 2 .zip files. Any help is appreciated, thanks. I want to get one finished up so I can put it in my apps area.
Edit: I have removed the files on this first post because I have fixed the issues a couple posts below by not needing library files.
I don't want to seem picky, but... even ROBOCOPY from versions later than 3.12 doesn't work.
The program replicates itself infinitely, and if you are not quick to force it to close with CTRL+ALT+DELETE, the system freezes and then crashes.
To be honest... even in version 3.12, the command behaves strangely: it doesn't work 20 times (just to say it seems random) and then it works once.
ROBOCOPY is an important command; I will try to compile the executable with version 1.5... I have nothing left: I've tried everything!
Perhaps the problem encountered with the manipulation of the system dates is just the tip of the iceberg. Maybe it has to do with how QB64 connects, through SHELL, with the operating system commands.
In c:\robocopy there are some files that I would like to copy to c:\robocopy new while preserving the attributes.
The syntax is designed to allow for the handling of paths with empty spaces.
note: There are no spaces between COPY : DAT: I have to write it this way because the editor that formats the code writes COPYAT !!
Posted by: SierraKen - 08-14-2024, 04:48 AM - Forum: SierraKen
- No Replies
This is the classic artillery-style game where you select an angle and power, with different winds, and try to hit the other cannon on the other side of the random mountain, before the computer cannon hits yours first. There is a tiny bit of "A.I." to this game in the fact that the computer slowly learns from its mistakes on every turn. The entire game is ran by your Mouse, using 2 different sliders for angle and power and a button to fire. Have fun!
Thanks to B+, OldMoses, and Steve for helping me a lot with this game.
Code: (Select All)
'I've always wanted to make this game ever since I started programming in the 80's.
'This was created by SierraKen with much help from others below.
'Thank you to B+ for much of the math code, Mouse and click bar help on https://qb64phoenix.com/forum/index.php
'It takes the computer a little time to learn how to hit your base.
'Created on June 26, 2019.
'Version 2 made on May 2, 2022.
'Added: Levels, random colored mountains, and better looking cannons.
'Added: Click Bars and Fire! button. Simpler Instructions. Changed 5 to 4 times needed to hit enemy and enemy to hit you.
'Added: Better mouse control thanks to B+, OldMoses, and Steve.
'Added: Delete click bars when it's not your turn.
'Added: Click mouse button to start game.
'Added: Set click bars remain the same per turn on each level.
_Title "Ken's Artillery 2"
_Limit 200
Cls
Screen _NewImage(1200, 700, 32)
Print " Ken's Artillery 2"
Print: Print: Print
Print " By SierraKen"
Print " with some help from B+, OldMoses, and Steve"
Print: Print: Print
Print " Instructions: Red Click Bar = Power"
Print " Green Click Bar = Angle"
Print " Fire! Button = Fire Cannonball"
Print
Print " Hit enemy 4 times you advance to next level."
Print " Get hit 4 times in a level and you lose."
Print: Print: Print
Print " Press Mouse Button To Start!"
Do
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1) ' this update the mouse x, y and button status save to variable because they change
If mb Then Clear_MB 1: GoTo continue:
Loop
continue:
Cls
level = 1
oldVelocityX = 100
oldAngleX = 100
vel = 40
a = 45
start:
c = 0
mountain = 0
win = 0
compoints = 0
points = 0
ground = 590 'up is negative in direction
'Your Cannon
cbx = 10 ' cannon butt end x, y
cby = ground - 20
cmx = 50 ' cannon mouth end
cmy = ground - 70
go:
_Limit 200
_Display ' update screen !!! sure like to know if my turn or not after computer
a2$ = InKey$
If a2$ = Chr$(27) Then End
fired = 0
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1) ' this update the mouse x, y and button status save to variable because they change
If mb Then
If mx > 60 And mx < 260 Then
If my >= 40 And my < 70 Then
If mx > 259 Then mx = 260
vel = (mx - 60) / 200 * 100 ' converts place in box to 0 to 100
drawVelocityBar mx
oldVelocityX = mx
vel3 = mx
Color _RGB32(0, 0, 0), _RGB32(255, 0, 0)
_PrintString (265, 50), Str$(vel)
Clear_MB 1
GoTo go
ElseIf my >= 70 And my < 100 Then
If mx > 259 Then mx = 260
a = (mx - 60) / 200 * 90 ' converts place in box to 0 to 90
drawAngleBar mx
oldAngleX = mx
a3 = mx
Color _RGB32(0, 0, 0), _RGB32(0, 255, 0)
_PrintString (265, 80), Str$(a)
Clear_MB 1
GoTo go
ElseIf my >= 100 And my < 130 And mx <= 120 Then
fired = 1
For pressed = 1 To 10
Line (60 + pressed, 100 + pressed)-(120 - pressed, 130 - pressed), _RGB32(200 - (pressed * 10), 10, 5), BF
Next pressed
Color _RGB32(0, 0, 0), _RGB32(100, 10, 5)
_PrintString (70, 110), "Fire!"
Clear_MB 1
GoTo going
End If
End If
End If
If fired = 0 Then GoTo go
going:
Color _RGB32(0, 0, 0), _RGB32(156, 210, 237)
If a > 90 Then a = 90
If a < 0 Then a = 0
If vel < 0 Then vel = 0
If vel > 80 Then vel = 80
vel = Int(vel / 4)
a = 360 - a
ca = _D2R(a)
cmx = cbx + (100 * Cos(_D2R(a)))
cmy = cby + (100 * Sin(_D2R(a)))
'initialize
bx = cmx 'ball x, y same as cannon mouth at start of shot
by = cmy
dx = vel * Cos(ca) 'start at cannon mouth
dy = vel * Sin(ca)
'shot
Do
_Limit 200
GoSub Wind:
a$ = InKey$
If a$ = Chr$(27) Then End
Circle (bx, by), 5, _RGB32(0, 0, 0)
Paint (bx, by), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
For ccc = 0 To 7 Step .1
Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(150, 50, 0) 'cannon line
Next ccc
oldbx = bx: oldby = by
dx = dx + airX
dy = dy + g
bx = bx + dx
by = by + dy
_Display
_Limit 30
Circle (oldbx, oldby), 5, _RGB(156, 210, 237)
Paint (oldbx, oldby), _RGB(156, 210, 237)
If Point(bx, by) = _RGB32(cl1, cl2, cl3) Then
mountain = 1
For explosion = 0 To 20 Step .5
Circle (bx, by), explosion, _RGB32(156, 210, 237)
Sound 100 + explosion, .25
Next explosion
End If
If bx > cbx2 - 120 And bx < cbx2 + 20 And by >= ground - 2 Then
points = points + 1
win = 0
Locate 3, 64: Print "You: "; points; " Computer: "; compoints
For explosion = 0 To 20 Step .5
Circle (bx, by), explosion, _RGB32(156, 210, 237)
Sound 100 + explosion, .25
Next explosion
For sndd = 500 To 700 Step 50
Sound sndd, 1
Next sndd
mountain = 1
If points = 4 And win = 0 Then win = 1: level = level + 1: GoTo start:
End If
Loop Until mountain = 1 Or by > 700
For ccc = 0 To 7 Step .1
Line (cbx, cby)-(cmx + ccc, cmy), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
'The Computer's Turn
comp:
'Clear Click Bars and Fire! Button
Line (4, 39)-(330, 131), _RGB32(156, 210, 237), BF
If c = 0 Then GoTo nex:
'Last shot was too far away.
If oldbx2 < cbx Then
vel2 = oldvel2 - 1
If vel2 < 8 Then vel2 = 8
End If
'Last shot wasn't far enough.
If oldbx2 > cbx Then
vel2 = oldvel2 + 1
If vel2 > 15 Then vel2 = 15
End If
nex:
c = 1
ca2 = _D2R(a2)
cmx2 = cbx2 - (100 * Cos(_D2R(a2)))
cmy2 = cby2 + (100 * Sin(_D2R(a2)))
'initialize
bx2 = cmx2 'ball x, y same as cannon mouth at start of shot
by2 = cmy2
dx2 = vel2 * Cos(ca2) 'start at cannon mouth
dy2 = vel2 * Sin(ca2)
'shot
Do
_Limit 200
a$ = InKey$
If a$ = Chr$(27) Then End
Circle (bx2, by2), 5, _RGB32(0, 0, 0)
Paint (bx2, by2), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
For ccc = 0 To 7 Step .1
Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(150, 50, 0) 'cannon line
Next ccc
oldbx2 = bx2: oldby2 = by2
dx2 = dx2 + airX
dy2 = dy2 + g
bx2 = bx2 - dx2
by2 = by2 + dy2
_Display
_Limit 30
Circle (oldbx2, oldby2), 5, _RGB(156, 210, 237)
Paint (oldbx2, oldby2), _RGB(156, 210, 237)
If Point(bx2, by2) = _RGB32(cl1, cl2, cl3) Then
mountain = 1
For explosion = 0 To 20 Step .5
Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
Sound 100 + explosion, .25
Next explosion
End If
If bx2 > cbx - 20 And bx2 < cbx + 120 And by2 >= ground - 2 Then
compoints = compoints + 1
Locate 3, 64: Print "You: "; points; " Computer: "; compoints
For explosion = 0 To 20 Step .5
Circle (bx2, by2), explosion, _RGB32(156, 210, 237)
Sound 100 + explosion, .25
Next explosion
For sndd = 500 To 700 Step 50
Sound sndd, 1
Next sndd
mountain = 1
If compoints = 4 Then Color _RGB(0, 0, 0): Locate 20, 65: Print "COMPUTER WINS!": GoTo asking:
End If
Loop Until mountain = 1 Or by2 > 700
For ccc = 0 To 7 Step .1
Line (cbx2, cby2)-(cmx2 - ccc, cmy2), _RGB32(156, 210, 237) 'delete cannon line
Next ccc
mountain = 0
GoTo again:
'This code is used in a few different places in the program.
Wind:
Color _RGB(0, 0, 0)
Locate 1, 73: Print "Wind"
If winddir$ = "West" Then
Locate 2, 82: Print " "
Locate 2, 59: Print airx2; " mph "
End If
If winddir$ = "East" Then
Locate 2, 59: Print " "
Locate 2, 82: Print airx2; " mph "
End If
Locate 2, 68: Print "West <-> East"
Locate 3, 64: Print "You: "; points; " Computer: "; compoints
Locate 4, 71: Print "Level: "; level
Return
asking:
Locate 22, 65: Input "Again? (Yes/No):", ag$
If ag$ = "y" Or ag$ = "Y" Or ag$ = "yes" Or ag$ = "Yes" Or ag$ = "YES" Or ag$ = "yES" Or ag$ = "yeS" Then points = 0: level = 1: GoTo start:
End
Sub Clear_MB (var As Integer)
Do Until Not _MouseButton(var)
While _MouseInput: Wend
Loop
End Sub 'Clear_MB
Sub drawVelocityBar (x) ' x is mouse x
Line (61, 41)-(259, 69), _RGB32(156, 210, 237), BF
Line (61, 41)-(x, 69), _RGB32(255, 0, 1), BF
End Sub
Sub drawAngleBar (x) ' x is mouse x
Line (61, 71)-(259, 99), _RGB32(156, 210, 237), BF
Line (61, 71)-(x, 99), _RGB32(0, 255, 1), BF
End Sub