Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 482
» Latest member: zaalexijuniorz5256
» Forum threads: 2,792
» Forum posts: 26,341

Full Statistics

Latest Threads
Need help capturng unicod...
Forum: General Discussion
Last Post: SMcNeill
1 hour ago
» Replies: 20
» Views: 228
games or graphics for 3-D...
Forum: General Discussion
Last Post: madscijr
1 hour ago
» Replies: 26
» Views: 747
Text-centring subs
Forum: Utilities
Last Post: SierraKen
9 hours ago
» Replies: 2
» Views: 41
Video Renamer
Forum: Works in Progress
Last Post: Pete
9 hours ago
» Replies: 0
» Views: 15
QB64PE v4.0 is now live!!
Forum: Announcements
Last Post: bert22306
9 hours ago
» Replies: 32
» Views: 919
QB64-PE v4's new 4-voice ...
Forum: Learning Resources and Archives
Last Post: a740g
Today, 02:51 AM
» Replies: 6
» Views: 133
Sound Ball
Forum: Programs
Last Post: SierraKen
Yesterday, 11:34 PM
» Replies: 0
» Views: 24
InForm-PE
Forum: a740g
Last Post: a740g
Yesterday, 10:58 PM
» Replies: 78
» Views: 6,034
Spriggsy's API Collection
Forum: Utilities
Last Post: SpriggsySpriggs
Yesterday, 07:13 PM
» Replies: 8
» Views: 187
Split String to Array Usi...
Forum: Utilities
Last Post: SpriggsySpriggs
Yesterday, 06:37 PM
» Replies: 0
» Views: 29

 
  What the heck, it's Friday let's drive some people nuts.
Posted by: doppler - 10-18-2024, 10:41 AM - Forum: General Discussion - Replies (4)

I want to automate some commands in a CMD window.  I need to capture output and input "only from that window" (text only in this case).
I expect this would require a third party program to help me.

My problem:
   I need to repeatedly send commands to Raspberry PI's on my network.  I can use SSH to remotely send commands to each PI.  I can even automate some keystrokes using AUTOHOTKEY.  But all this is repetitive.  Very boring and time consuming.  I am by nature lazy as f*ck.  The torturous part it's not as simple to sending a one line ssh command.  I may want to do more than one thing in that window.  All requiring input and outputs, of various natures.

Why reinvent that wheel.  When I am almost 100% sure someone here already found that wheel and is using it.  Care to share ?

Thanks.

Print this item

  Broken Clock
Posted by: SMcNeill - 10-17-2024, 09:20 PM - Forum: Utilities - Replies (1)

As you guys can probably tell, bplus had me digging around in old drives and such looking for 2048 (Double Up) related code, and I've ran into a lot of old junk which I thought I'd share that someone might like. Here's an old gear-clock that used to connect to the internet and get the weather and temperature and such for Steve's Place, back in the day. Unfortunately the website I used to connect to to get that info no longer exists, so it can't tell you that anymore. Now, it's just a funny looking clock, missing out on the important bits that I liked the most with it. Tongue

Code: (Select All)
Screen _NewImage(640, 480, 32)
_ScreenMove _Middle

Dim Shared hourgear, minutegear, secondgear, center
Print "Initializing clock..."

hourgear = DrawHourGear(&HFFFF00FF)
minutegear = DrawMinuteGear(&HFFFFFF00)
secondgear = DrawSecondGear(&HFF00FF00)
center = CenterDisplay

Do
_Limit 60
Cls , 0
AssembleClock 80, 0, 560, _Height
ManualAdjustment
_Display
Loop


Sub ManualAdjustment
Shared Adjustment As _Float
A = 1
If _KeyDown(100306) Or _KeyDown(100305) Then A = 60
If _KeyDown(100304) Or _KeyDown(100303) Then A = 3600
k = _KeyHit
Select Case k
Case 32 'space
Adjustment = 0
Case 19200, 20480 'left / down
Adjustment = Adjustment - A
Case 18332, 19712 'up / right
Adjustment = Adjustment + A
Case 27 'escape to quite
System
End Select
End Sub

Sub AssembleClock (x1, y1, x2, y2)
Shared Adjustment As _Float
d = _Dest
tempimage = _NewImage(480, 480, 32)
_Dest tempimage

W = _Width \ 2: h = _Height \ 2
If W > h Then R = h Else R = W

t## = Adjustment + Timer
hour = t## \ 3600
minute = (t## - hour * 3600) \ 60
second = t## - hour * 3600 - minute * 60
DisplayImage hourgear, 240, 240, hour * 30, 0
DisplayImage minutegear, 240, 240, minute * 6, 0
DisplayImage secondgear, 240, 240, second * 6, 0
DisplayImage center, 240, 240, 0, 0
_Dest d
_PutImage (x1, y1)-(x2, y2), tempimage, d, (0, 0)-(479, 479)
_FreeImage tempimage
_Dest d
End Sub


Function CenterDisplay
Static oldmm
d = _Dest
OldFont = _Font

CenterDisplaytemp = _NewImage(175, 100, 32)
_Dest CenterDisplaytemp
F = _LoadFont("courbd.ttf", 24)
F1 = _LoadFont("courbd.ttf", 30)
If F > 0 Then _Font F Else _Font 16
Cls
d$ = Date$
Select Case Left$(d$, 2)
Case "01": month$ = "JAN"
Case "02": month$ = "FEB"
Case "03": month$ = "MAR"
Case "04": month$ = "APR"
Case "05": month$ = "MAY"
Case "06": month$ = "JUN"
Case "07": month$ = "JUL"
Case "08": month$ = "AUG"
Case "09": month$ = "SEP"
Case "10": month$ = "OCT"
Case "11": month$ = "NOV"
Case "12": month$ = "DEC"
End Select
mm = Val(Left$(d$, 2))
dd = Val(Mid$(d$, 4))
yy = Val(Right$(d$, 4))
Print month$; " "; Mid$(d$, 4, 2); ", "; Right$(d$, 4);
day$ = GetDay$(mm, dd, yy)

If F1 > 0 Then SafeLoadFont F1 Else SafeLoadFont 16
day$ = "Wednesday"
s$ = Space$((10 - Len(day$)) \ 2)
Print s$ + day$;
_Font 16
If F > 0 Then _FreeFont F
If F1 > 0 Then _FreeFont F1

If oldmm <> mm Then 'try to update the weather every minute
rss$ = DownloadRSS("http://rss.wunderground.com/q/zmw:24138.1.99999", 5)
'<meta property="og:title" content="Pilot, VA | 37.2&deg; | Overcast" />
t$ = "<meta property=" + Chr$(34) + "og:title" + Chr$(34) + " content=" + Chr$(34)
l = InStr(rss$, t$)
endl = InStr(l, rss$, "/>")
temp$ = Mid$(rss$, l + Len(t$), endl - l)
_Font 8
fs = InStr(temp$, "|")
ss = InStr(fs + 1, temp$, "|")
el = InStr(ss + 1, temp$, Chr$(34))
city$ = Left$(temp$, fs - 1)
temp = Val(Mid$(temp$, fs + 1))
condition$ = Mid$(temp$, ss + 1, el - ss - 1)
Locate 9, 1
Print city$; temp; condition$;
oldmm = mm
End If
_Font 16
_Dest d
CenterDisplay = CenterDisplaytemp
End Function

Function DrawHourGear (Kolor As _Unsigned Long)
D = _Dest
DrawHourGeartemp = _NewImage(640, 480, 32)
_Dest DrawHourGeartemp
OldFont = _Font
W = _Width \ 2: h = _Height \ 2
F = _LoadFont("OLDENGL.TTF", 48)
If F > 0 Then _Font F Else _Font 16
If W > h Then R = h - 1 Else R = W - 1
FH = _FontHeight \ 2
CircleFill W, h, R, Kolor
Color &HFF000000, 0
For i = 1 To 12
X = W + R * .9 * Cos(_D2R(i * 30 - 90))
Y = h + R * .9 * Sin(_D2R(i * 30 - 90))
t$ = _Trim$(Str$(i))
tempimage = TextToImage&(t$, F, &HFF000000, 0, 0)
DisplayImage tempimage, X, Y, -i * 30, 0
_FreeImage tempimage
Next
_Font OldFont
If F > 0 Then _FreeFont F
'CircleFill W, H, 10, &HFF000000
_Dest D
DrawHourGear = DrawHourGeartemp
End Function

Function DrawMinuteGear (Kolor As _Unsigned Long)
D = _Dest
DrawMinuteGeartemp = _NewImage(640, 480, 32)
_Dest DrawMinuteGeartemp
OldFont = _Font
W = _Width \ 2: h = _Height \ 2
F = _LoadFont("OLDENGL.TTF", 18)
If F > 0 Then _Font F Else _Font 16
If W > h Then R = h * .8 Else R = W * .8
FH = _FontHeight \ 2
CircleFill W, h, R, Kolor
Color &HFF000000, 0
For i = 0 To 59
X = W + R * .9 * Cos(_D2R(i * 6 - 90))
Y = h + R * .9 * Sin(_D2R(i * 6 - 90))
t$ = _Trim$(Str$(i \ 10))
tempimage = TextToImage&(t$, F, &HFF000000, 0, 0)
DisplayImage tempimage, X, Y, -i * 6, 0
_FreeImage tempimage
X = W + R * .8 * Cos(_D2R(i * 6 - 90))
Y = h + R * .8 * Sin(_D2R(i * 6 - 90))
t$ = _Trim$(Str$(i Mod 10))
tempimage = TextToImage&(t$, F, &HFF000000, 0, 0)
DisplayImage tempimage, X, Y, -i * 6, 0
_FreeImage tempimage
Next
_Font OldFont
If F > 0 Then _FreeFont F
'CircleFill W, H, 10, &HFF000000
_Dest D
DrawMinuteGear = DrawMinuteGeartemp
End Function


Function DrawSecondGear (Kolor As _Unsigned Long)
D = _Dest
DrawSecondGeartemp = _NewImage(640, 480, 32)
_Dest DrawSecondGeartemp
OldFont = _Font
W = _Width \ 2: h = _Height \ 2
F = _LoadFont("OLDENGL.TTF", 18)
If F > 0 Then _Font F Else _Font 16
If W > h Then R = h * .6 Else R = W * .6
FH = _FontHeight \ 2
CircleFill W, h, R, Kolor
Color &HFF000000, 0
For i = 0 To 59
X = W + R * .9 * Cos(_D2R(i * 6 - 90))
Y = h + R * .9 * Sin(_D2R(i * 6 - 90))
t$ = _Trim$(Str$(i \ 10))
tempimage = TextToImage&(t$, F, &HFF000000, 0, 0)
DisplayImage tempimage, X, Y, -i * 6, 0
_FreeImage tempimage
X = W + R * .8 * Cos(_D2R(i * 6 - 90))
Y = h + R * .8 * Sin(_D2R(i * 6 - 90))
t$ = _Trim$(Str$(i Mod 10))
tempimage = TextToImage&(t$, F, &HFF000000, 0, 0)
DisplayImage tempimage, X, Y, -i * 6, 0
_FreeImage tempimage
Next
_Font OldFont
'CircleFill W, H, 10, &HFF000000
_Dest D
DrawSecondGear = DrawSecondGeartemp
End Function

Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R)
RadiusError = -Radius
X = Radius
Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
Wend
End Sub

Sub DisplayImage (Image As Long, x As Integer, y As Integer, angle As Single, mode As _Byte)
'Image is the image handle which we use to reference our image.
'x,y is the X/Y coordinates where we want the image to be at on the screen.
'angle is the angle which we wish to rotate the image.
'mode determines HOW we place the image at point X,Y.
'Mode 0 we center the image at point X,Y
'Mode 1 we place the Top Left corner of oour image at point X,Y
'Mode 2 is Bottom Left
'Mode 3 is Top Right
'Mode 4 is Bottom Right


Dim px(3) As Integer, py(3) As Integer, w As Integer, h As Integer
Dim sinr As Single, cosr As Single, i As _Byte
w = _Width(Image): h = _Height(Image)
Select Case mode
Case 0 'center
px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
Case 1 'top left
px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
px(1) = 0: py(1) = h: px(2) = w: py(2) = h
Case 2 'bottom left
px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
Case 3 'top right
px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
Case 4 'bottom right
px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
End Select
sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
For i = 0 To 3
x2 = (px(i) * cosr + sinr * py(i)) + x: y2 = (py(i) * cosr - px(i) * sinr) + y
px(i) = x2: py(i) = y2
Next
_MapTriangle (0, 0)-(0, h - 1)-(w - 1, h - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MapTriangle (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub

Function TextToImage& (text$, font&, fc&, bfc&, mode As _Byte)
'text$ is the text that we wish to transform into an image.
'font& is the handle of the font we want to use.
'fc& is the color of the font we want to use.
'bfc& is the background color of the font.

'Mode 1 is print forwards
'Mode 2 is print backwards
'Mode 3 is print from top to bottom
'Mode 4 is print from bottom up
'Mode 0 got lost somewhere, but it's OK. We check to see if our mode is < 1 or > 4 and compensate automatically if it is to make it one (default).

If mode < 1 Or mode > 4 Then mode = 1
dc& = _DefaultColor: bgc& = _BackgroundColor
D = _Dest
F = _Font
If font& <> 0 Then _Font font&
If mode < 3 Then
'print the text lengthwise
w& = _PrintWidth(text$): h& = _FontHeight
Else
'print the text vertically
For i = 1 To Len(text$)
If w& < _PrintWidth(Mid$(text$, i, 1)) Then w& = _PrintWidth(Mid$(text$, i, 1))
Next
h& = _FontHeight * (Len(text$))
End If

tempTextToImage& = _NewImage(w&, h&, 32)
_Dest tempTextToImage&
If font& <> 0 Then _Font font&
Color fc&, bfc&

Select Case mode
Case 1
'Print text forward
_PrintString (0, 0), text$
Case 2
'Print text backwards
temp$ = ""
For i = 0 To Len(text$) - 1
temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
Next
_PrintString (0, 0), temp$
Case 3
'Print text upwards
'first lets reverse the text, so it's easy to place
temp$ = ""
For i = 0 To Len(text$) - 1
temp$ = temp$ + Mid$(text$, Len(text$) - i, 1)
Next
'then put it where it belongs
For i = 1 To Len(text$)
fx = (w& - _PrintWidth(Mid$(temp$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PrintString (fx, _FontHeight * (i - 1)), Mid$(temp$, i, 1)
Next
Case 4
'Print text downwards
For i = 1 To Len(text$)
fx = (w& - _PrintWidth(Mid$(text$, i, 1))) / 2 + .99 'This is to center any non-monospaced letters so they look better
_PrintString (fx, _FontHeight * (i - 1)), Mid$(text$, i, 1)
Next
End Select
_Dest D
Color dc&, bgc&
_Font F
TextToImage& = tempTextToImage&
End Function

Function GetDay$ (mm, dd, yyyy) 'use 4 digit year
'From Zeller's congruence: https://en.wikipedia.org/wiki/Zeller%27s_congruence
If mm < 3 Then mm = mm + 12: yyyy = yyyy - 1
century = yyyy Mod 100
zerocentury = yyyy \ 100
result = (dd + Int(13 * (mm + 1) / 5) + century + Int(century / 4) + Int(zerocentury / 4) + 5 * zerocentury) Mod 7
Select Case result
Case 0: GetDay$ = "Saturday"
Case 1: GetDay$ = "Sunday"
Case 2: GetDay$ = "Monday"
Case 3: GetDay$ = "Tuesday"
Case 4: GetDay$ = "Wednesday"
Case 5: GetDay$ = "Thursday"
Case 6: GetDay$ = "Friday"
End Select
End Function

Sub SafeLoadFont (font#)
'Safely loads a font without destroying our current print location and making it revert to the top left corner.

down = CsrLin: right = Pos(0)
down = (down - 1) * _FontHeight
If _FontWidth <> 0 Then 'weed start with a monospace font
right = (right - 1) * _PrintWidth(" ") 'convert the monospace LOC to a graphic X coordinate
End If
_Font font#
If _FontWidth <> 0 Then 'we swapped to a monospace font
right = (right / _PrintWidth(" ")) + 1 'convert the graphic X coordinate back to a monospace LOC column
End If
down = (down / _FontHeight) + 1
If right < 1 Then right = 1
Locate down, right
End Sub

Function DownloadRSS$ (url$, timelimit)
link$ = url$
url2$ = RTrim$(LTrim$(link$))
url4$ = RTrim$(LTrim$(link$))
If Left$(UCase$(url2$), 7) = "HTTP://" Then url4$ = Mid$(url2$, 8)
x = InStr(url4$, "/")
If x Then url2$ = Left$(url4$, x - 1)
NewsClient = _OpenClient("TCP/IP:80:" + url2$)
If NewsClient = 0 Then Exit Function
e$ = Chr$(13) + Chr$(10) ' end of line characters
url3$ = Right$(url4$, Len(url4$) - x + 1)
x$ = "GET " + url3$ + " HTTP/1.1" + e$
x$ = x$ + "Host: " + url2$ + e$ + e$
Put #NewsClient, , x$

t! = Timer ' start time
head$ = ""
cont_type$ = ""
Do
_Limit 20
Get #NewsClient, , a$
If LTrim$(a$) > "" Then final$ = final$ + a$
If InStr(a$, "</html>") Then Exit Do 'we hit the end of the file
Loop Until Timer > t! + timelimit And timelimit > 0 ' (in seconds)

DownloadRSS$ = final$
End Function


Maybe I'll hunt down another site with a RSS feed for local weather according to lat/long. There's bound to be one out there on the web somewhere! Wink

Print this item

  Twirly Whirly Math Stuff
Posted by: SMcNeill - 10-17-2024, 08:46 PM - Forum: Utilities - Replies (2)

Code: (Select All)
DefLng A-Z
Screen _NewImage(640, 480, 32)
Dim C(-1 To 0): C(-1) = &HFFFF0000: C(0) = &HFF0000FF

Do
variance = variance + 1
If variance > 640 Then variance = 0
Cls

For i = 0 To 8
k = Not k
x = 25 * Sin(_D2R(30 * i)) + variance
y = 25 * Cos(_D2R(30 * i)) + 50
Circle (x, y), 25, C(k)
Paint (x, y), C(k)
Next

h = _NewImage(50, 100, 32)
_PutImage , 0, h, (variance, 0)-(100, 100)
f = _NewImage(100, 100, 32)
_Dest f
D h, 50, 0, 0, 1: D h, 0, 0, 180, 4
_Dest 0

Cls
a = 0
Do
a = a + 3
For y = -50 To 530 Step 82
Z = Not Z
dir = 1: If Z Then dir = -1
For x = -50 To 690 Step 100
D f, x + Z * 50, y, dir * a, 0
Next x, y
Loop Until a >= 180

Loop

Sub D (Im, x, y, a, m)
Dim px(3), py(3)
w = _Width(Im) - 1: h = 99
Select Case m
Case 0: px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2: px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
Case 1: px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0: px(1) = 0: py(1) = h: px(2) = w: py(2) = h
Case 4: px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h: px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
End Select
s! = Sin(_D2R(a)): c! = Cos(_D2R(a))
For i = 0 To 3
x2 = (px(i) * c! + s! * py(i)) + x: y2 = (py(i) * c! - px(i) * s!) + y
px(i) = x2: py(i) = y2
Next
_MapTriangle (0, 0)-(0, h)-(w, h), Im To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MapTriangle (0, 0)-(w, 0)-(w, h), Im To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub

Code: (Select All)
Screen _NewImage(600, 600, 32)
Do: _Limit 30: Loop
Sub drawPattern (a, s, c As _Byte, N)
If s < 0.001 Then Exit Sub
If c = 1 Then _glColor3f 1, 1, 1 Else _glColor3f 0, 0, 0
_glBegin _GL_POLYGON
For i = a To _Pi(2) + a Step _Pi(2 / N): _glVertex2f s * Cos(i), s * Sin(i): Next
_glEnd
If c = 1 Then drawPattern a + 0.1, s - 0.01, 0, N Else drawPattern a + 0.1, s - 0.01, 1, N
End Sub
Sub _GL ()
Static c
drawPattern c, 1.5, 1, 8
c = c + 0.01
End Sub

Code: (Select All)
Screen _NewImage(600, 600, 32)
Do: _Limit 30: Loop
Sub drawPattern (a, s, c As _Byte, N)
If s < 0.001 Then Exit Sub
If c = 1 Then _glColor3f 1, 1, 1 Else _glColor3f Rnd, Rnd, Rnd
_glBegin _GL_POLYGON
For i = a To _Pi(2) + a Step _Pi(2 / N): _glVertex2f s * Cos(i), s * Sin(i): Next
_glEnd
If c = 1 Then drawPattern a + 0.1, s - 0.01, 0, N Else drawPattern a + 0.1, s - 0.01, 1, N
End Sub
Sub _GL ()
Static c
drawPattern c, 2, 1, 8
c = c + 0.01
End Sub

Print this item

  Flip It!
Posted by: SMcNeill - 10-17-2024, 05:59 PM - Forum: SMcNeill - No Replies

A little card game where the goal is to remove all the cards from the screen.

Game play is simple, click on a card with an open face to remove it, but doing so will FLIP the cards beside it.  You can pick and choose which cards to flip (as long as they're face up), and the goal is to flip them all until you can remove them all from the screen.

Code: (Select All)
$Color:32
DefLng A-Z
Randomize Timer
Screen _NewImage(1024, 720, 32) '720p screen
_Title "Flip It"
Dim Shared CardImage As Long: CardImage = _LoadImage("Cards.bmp", 32)
Dim Shared CardWide, CardHigh: CardWide = 72: CardHigh = 96
Dim Shared Deck(51) As Integer 'an array to hold the cards
ReDim Shared Visible(0) As Integer 'an array to see if the cards are visible or hidden
Dim Shared Result
Dim Shared OldEnglish, NumOfCards
OldEnglish = _LoadFont("OLDENGL.TTF", 32)
_PrintMode _KeepBackground

Do
NumOfCards = ChooseDifficulty
Shuffle
For i = 1 To NumOfCards
DisplayCards
If Result = 0 Then Exit For
Next
If i = NumOfCards + 1 Then DisplayCards: Result = -1 'flip the last card and win
WinOrLose
Loop

Sub WinOrLose
_Font OldEnglish
If Result Then
Print "YOU WIN!!!"
Else
Print "YOU LOSE!!!"
End If
_Delay 3
End Sub

Sub DisplayCards
Cls
_Font 16
xstep = _Width / NumOfCards
scale = xstep / CardWide
ystart = _Height / 2 - CardHigh * scale / 2

For i = 0 To NumOfCards - 1
If Visible(i) = -1 Then
suit = Deck(i) \ 13: value = Deck(i) Mod 13
_PutImage (xstep * i, ystart)-Step(xstep, CardHigh * scale), CardImage, 0, (value * CardWide, suit * CardHigh)-Step(CardWide, CardHigh)
ElseIf Visible(i) = 0 Then
Line (xstep * i, ystart)-Step(xstep, CardHigh * scale), White, BF
Line (xstep * i + 2, ystart + 2)-Step(xstep - 4, CardHigh * scale - 4), Blue, BF
Else
'We don't draw squat. The card has been removed from play
End If
Next

Result = 0
For i = 0 To NumOfCards - 1
If Visible(i) < 0 Then Result = -1: Exit For 'there's still visible cards to play with
Next
If Result = 0 Then Exit Sub



oldmouse = -1 'cycle one to make certain mouse is up before we count a down event
Do
While _MouseInput: Wend
mb = _MouseButton(1)
If oldmouse = 0 And mb Then
If _MouseY >= ystart And _MouseY <= ystart + CardHigh * scale Then 'we're in the right rows for a valid mouse click
choice = _MouseX \ xstep
If choice >= 0 And choice <= NumOfCards And Visible(choice) = -1 Then finished = -1
End If
End If
oldmouse = mb
_Limit 30
Loop Until finished
Visible(choice) = 1
If choice > 0 Then
If Visible(choice - 1) < 1 Then Visible(choice - 1) = Not Visible(choice - 1)
End If
If choice < NumOfCards Then
If Visible(choice + 1) < 1 Then Visible(choice + 1) = Not Visible(choice + 1)
End If
End Sub



Function ChooseDifficulty
Cls
_Font OldEnglish
Color White
CenterText 0, 200, _Width, 300, "Choose Difficulty"
Color Black

For i = 0 To 9
x = 5 + 102 * i
y = 300
Line (x, y)-Step(100, 100), Yellow, BF
CenterText x, y, x + 100, y + 100, _Trim$(Str$(i + 6))
Next

oldmouse = -1 'cycle one to make certain mouse is up before we count a down event
Do
While _MouseInput: Wend
mb = _MouseButton(1)
If oldmouse = 0 And mb Then
If _MouseY >= 300 And _MouseY <= 400 Then 'we're in the right rows for a valid mouse clice
choice = (_MouseX - 5) \ 102
If choice >= 0 And choice <= 9 Then finished = -1
End If
End If
oldmouse = mb
_Limit 30
Loop Until finished
Color White
ChooseDifficulty = choice + 6
End Function

Sub CenterText (x1, y1, x2, y2, text$)
pw = _PrintWidth(text$)
px = x1 + (x2 - x1) / 2 - pw / 2
py = y1 + (y2 - y1) / 2 - _FontHeight / 2
_PrintString (px, py), text$
End Sub

Sub Shuffle
Static InitDeck
If Not InitDeck Then
InitDeck = -1
For i = 0 To 51: Deck(i) = i: Next 'put the cards in the deck
End If
For i = 0 To 51
Swap Deck(i), Deck(Int(Rnd * 52)) 'shuffle the deck
Next
ReDim Visible(NumOfCards) As Integer
For i = 0 To NumOfCards - 1
Visible(i) = -Int(Rnd * 2)
Next
End Sub



Attached Files
.bmp   Cards.bmp (Size: 1.03 MB / Downloads: 60)
Print this item

  Tool Tips
Posted by: SMcNeill - 10-17-2024, 05:37 PM - Forum: SMcNeill - Replies (1)

Code: (Select All)
Type ToolTipInfo
text As String
x As Integer
y As Integer
End Type

Dim Shared RegisteredTips(100) As ToolTipInfo

Screen _NewImage(800, 600, 32)

RegisterToolTip "Cheese is tasty and made from moo moo cows!", 245, 100
RegisterToolTip "A fridge is the cold thing which folks hold their cheeses in!", 380, 100
Do
Cls
_PrintString (100, 100), "People like cheese in their fridge ."
While _MouseInput: Wend
DisplayToolTips
_Limit 30 'don't melt my damn CPU
_Display
Loop Until _KeyDown(27)





Sub RegisterToolTip (what$, x, y)
If what$ = "" Then Exit Sub 'can't register nothing
If x < 0 Or y < 0 Then Exit Sub 'don't put your tooltip off the damn screen!
If x > _Width - _FontWidth Or y > _Height - _FontHeight Then Exit Sub 'honestly, I say, don't put your tooltip off the damn screen!
For i = 1 To 100
If RegisteredTips(i).text = "" Then 'it's a free tooltip spot
RegisteredTips(i).text = what$
RegisteredTips(i).x = x
RegisteredTips(i).y = y
Exit Sub 'We're done. We've registered!
End If
Next
'If we make it to here, we failed. Some dummy probably has more than 100 tooltips, or else they registered them inside a loop, or such.
'(Note, this dummy could be your's truly...)
End Sub

Sub FreeToolTip (x, y)
For i = 1 To 100
If RegisteredTips(i).x = x And RegisteredTips(i).y = y Then 'it's a free tooltip spot
RegisteredTips(i).text = ""
RegisteredTips(i).x = -1
RegisteredTips(i).y = -1
Exit Sub 'We're done. We've registered!
End If
Next
End Sub

Sub DisplayToolTips
Static Qbox As Long
d = _Dest

If Qbox = 0 Then
Qbox = _NewImage(_FontWidth, _FontHeight, 32)
_Dest Qbox
Color _RGB32(255, 255, 0), _RGB32(0, 0, 128) 'Yellow on blue
_PrintString (0, 0), "?"
End If
For i = 1 To 100
If RegisteredTips(i).text <> "" Then
_PutImage (RegisteredTips(i).x, RegisteredTips(i).y), Qbox
If _MouseX >= RegisteredTips(i).x And _MouseX < RegisteredTips(i).x + _FontWidth Then 'in right spot
If _MouseY >= RegisteredTips(i).y And _MouseY < RegisteredTips(i).y + _FontHeight Then 'we're REALLY in the right spot
'show that damn tool tip

temp = _PrintWidth(RegisteredTips(i).text)
h = (temp \ (_Width \ 2) + 3) * _FontHeight
temp = _NewImage(_Width \ 2, h, 32)
_Dest temp
Cls , _RGB32(255, 255, 255) 'white background
Color _RGB32(0, 0, 0), 0
Locate 2, 1: Print RegisteredTips(i).text;
_Dest d
_PutImage (RegisteredTips(i).x, RegisteredTips(i).y - h), temp
_FreeImage temp
End If
End If
End If
Next
_Dest d
End Sub


Scroll over the Question Marks (?) to activate the tool tips. Wink

Print this item

  Christmas Info (Windows Users)
Posted by: SMcNeill - 10-17-2024, 05:32 PM - Forum: SMcNeill - Replies (9)

Code: (Select All)
$Console:Only
_Dest _Console

ip$ = GetPublicIP$
Print "Your IP Address is:"; ip$
Print
Lat_Long ip$, lat, lon
Print "Your Latitude and Longitude is: "; lat, lon
Print
Print "For your location, the following is true for Xmas day:"
SunStuff lat, lon, 12, 25, 2020


Function GetPublicIP$
f = FreeFile
Open "tempPIP.txt" For Output As #f: Close f
Shell _Hide "cmd /c nslookup myip.opendns.com resolver1.opendns.com>tempPIP.txt"

Open "tempPIP.txt" For Input As #f
If LOF(f) Then
Do
Line Input #f, temp$
If temp$ <> "" Then last$ = temp$ 'there's a blank line after the data we need.
' Ignore it. What we want is the last line of info generated here.
Loop Until EOF(1)
End If
Close f
l = _InStrRev(last$, "Address:")
If l Then GetPublicIP$ = Mid$(last$, l + 10)
Kill "tempPIP.txt"
End Function

Sub Lat_Long (ip$, lat, lon)
out$ = "powershell.exe -c " + Chr$(34) + "Invoke-Webrequest 'ip-api.com/line/"
out$ = out$ + ip$
out$ = out$ + "?fields=lat,lon' -OutFile '.\temp.txt'" + Chr$(34)
Shell _Hide out$
Open "temp.txt" For Input As #1
Input #1, lat
Input #1, lon
Close 1
End Sub

Sub SunStuff (lat, lon, month, day, year)
out$ = "powershell.exe -c " + Chr$(34) + "Invoke-Webrequest 'https://api.sunrise-sunset.org/json?lat="
out$ = out$ + _Trim$(Str$(lat)) + "&lng="
out$ = out$ + _Trim$(Str$(lon)) + "&date="
d$ = _Trim$(Str$(year)) + _Trim$(Str$(month)) + _Trim$(Str$(day))
out$ = out$ + d$ + "' -OutFile '.\temp.txt'"
Shell out$
Open "temp.txt" For Binary As #1
t$ = Space$(LOF(1))
Get #1, 1, t$
'strip off unwanted stuff
l = InStr(t$, ":{"): t$ = Mid$(t$, l + 2)
Do
l = InStr(t$, Chr$(34))
t$ = Left$(t$, l - 1) + Mid$(t$, l + 1)
Loop Until l = 0
Do
l = InStr(t$, "_")
t$ = Left$(t$, l - 1) + " " + Mid$(t$, l + 1)
Loop Until l = 0
t$ = _Trim$(t$)
t$ = Left$(t$, Len(t$) - 1)

Do
l = InStr(t$, ",")
If l = 0 Then Exit Do
whole$ = Left$(t$, l)
l$ = Left$(whole$, InStr(whole$, ":") - 1)
r$ = Mid$(whole$, InStr(whole$, ":") + 1)
r$ = Left$(r$, Len(r$) - 1)
Print l$; " is "; r$
t$ = Mid$(t$, l + 1)
Loop
Close 1
End Sub

Print this item

  Help?
Posted by: SMcNeill - 10-17-2024, 05:26 PM - Forum: Help Me! - Replies (7)

Can someone help me count the dots that this little program makes on the screen?

Code: (Select All)
Screen _NewImage(400, 400, 32)

Data 789CEDDD4B8E22391405D0DE0BD3DE10FBE2D34D4B8C611F3067CA1C58018CDDBA295142A8A02A89944DBA8EA5A72209FBD53DA3504418F8EBAFBFCA5F5F507FFFFD77F9E79F7FCA7FFFFD57FEFDF7DFA79539999B355FF17F7F6571B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707C76347FEBE2D0E0E0E8E77288EF6D97FE6582C16653A9D96C96452E6F3F98FEC799DF7722C73383838383838AE8ED96CF69177B55A95ED765BF6FB7D391C0E1F95D7792FC732277339383838383846A351592E9765B7DB95F3F95C1E8D1CCB9CCCCD9AD6B939383838385EAB9C8B8656F28CC7E3723A9D1EE6BF1F999B3559FB15193838383838EA3AEE9FB57CB6723D9473DAF178FC6DC375644DD6A6C7D01C1C1C1C1C1C751D79263FA4724F2DD745AF8EAC4D8FA1393838383838EA3A7EB567F859E599FE7ABD2E97CBE56547D6A6477A0DC9C2C1C1C1C1F17D1CD917B6D96C5E365C477AA4170707070747FF8EDCFBCAF54FF6870D1DE9915EE9C9C1C1C1C1D1BF23FF668FF1D0911EB73D393838383838383838383838EE1DBD5C477170707070D4AD1E9EE37070707070D4AF5EF69171707070707CBE7AF91C0B07070707475D472F9FA3E7E0E0E0E0A8EBE8E57BBC3838383838EA3A7AF91E610E0E0E0E8EEFE9C8B9A887DF31E1689F9D8383E3CF73E47E580FBFA3C8F13EC5D13E3B07472D479EC95FB3DF3F6BB9DDF3C5C1C1C1C1C1F1C8F16CCF3007070707070707070707070707C73B1547FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1D1C291BF6F8B838383E31D8AA37DF69F39168B45994EA765329994F97CFE237B5EE7BD1CCB1C0E0E0E0E0E8EAB63369B7DE45DAD5665BBDD96FD7E5F0E87C347E575DECBB1CCC95C0E0E0E0E0E8ED1685496CB65D9ED76E57C3E974723C7322773B3A6756E0E0E0E0E8ED72AE7A2A1953CE3F1B89C4EA787F9EF47E6664DD67E45060E0E0E0E8EBA8EFB672D9FAD5C0FE59C763C1E7FDB701D5993B5E931340707070707475D479EC90FA9DC53CB75D1AB236BD363680E0E0E0E0E8EBA8E5FED197E5679A6BF5EAFCBE57279D991B5E9915E43B270707070707C1F47F6856D369B970DD7911EE9C5C1C1C1C1D1BF23F7BE72FD93FD6143477AA4577A7270707070F4EFC8BFD9633C74A4C76D4F0E0E0E0E0E0E0E0E0E0E0E8E7B472FD7511C1C1C1C1C75AB87E7381C1C1C1C1CF5AB977D641C1C1C1C1C9FAF5E3EC7C2C1C1C1C151D7D1CBE7E83938383838EA3A7AF91E2F0E0E0E0E8EBA8E5EBE479883838383E37B3A722EEAE1774C38DA67E7E0E0F8F31CB91FD6C3EF2872BC4F71B4CFCEC151CB9167F2D7ECF7CF5A6EF77C7170707070703C723CDB33CCC1C1C1C1C1C1C1C1C1C1C1C1C1F14EC5D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB37370B470E4EFDBE2E0E0E07887E2689FFD678EC56251A6D369994C26653E9FFFC89ED7792FC732878383838383E3EA98CD661F7957AB55D96EB765BFDF97C3E1F051799DF7722C733297838383838363341A95E5725976BB5D399FCFE5D1C8B1CCC9DCAC699D9B83838383E3B5CAB9686825CF783C2EA7D3E961FEFB91B95993B55F918183838383A3AEE3FE59CB672BD74339A71D8FC7DF365C47D6646D7A0CCDC1C1C1C1C151D79167F2432AF7D4725DF4EAC8DAF4189A8383838383A3AEE3577B869F559EE9AFD7EB72B95C5E76646D7AA4D7902C1C1C1C1C1CDFC7917D619BCDE665C375A4477A7170707070F4EFC8BDAF5CFF647FD8D0911EE9959E1C1C1C1C1CFD3BF26FF6180F1DE971DB938383838383838383838383E3DED1CB75140707070747DDEAE1390E0707070747FDEA651F1907070707C7E7AB97CFB17070707070D475F4F2397A0E0E0E0E8EBA8E5EBEC78B83838383A3AEA397EF11E6E0E0E0E0F89E8E9C8B7AF81D138EF6D9393838FE3C47EE87F5F03B8A1CEF531CEDB37370D472E499FC35FBFDB396DB3D5F1C1C1C1C1C1C8F1CCFF60C7370707070707070707070707070BC5371B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C2D1CF9FBB638383838DEA138DA67FF9963B15894E9745A26934999CFE73FB2E775DECBB1CCE1E0E0E0E0E0B83A66B3D947DED56A55B6DB6DD9EFF7E570387C545EE7BD1CCB9CCCE5E0E0E0E0E0188D4665B95C96DD6E57CEE7737934722C7332376B5AE7E6E0E0E0E078AD722E1A5AC9331E8FCBE9747A98FF7E646ED664ED5764E0E0E0E0E0A8EBB87FD6F2D9CAF550CE69C7E3F1B70DD79135599B1E43737070707070D475E499FC90CA3DB55C17BD3AB2363D86E6E0E0E0E0E0A8EBF8D59EE1679567FAEBF5BA5C2E97971D599B1EE935240B07070707C7F771645FD866B379D9701DE9915E1C1C1C1C1CFD3B72EF2BD73FD91F3674A4477AA5270707070747FF8EFC9B3DC643477ADCF6E4E0E0E0E0E0E0E0E0E0E0E0B877F4721DC5C1C1C1C151B77A788EC3C1C1C1C151BF7AD947C6C1C1C1C1F1F9EAE5732C1C1C1C1C1C751DBD7C8E9E83838383A3AEA397EFF1E2E0E0E0E0A8EBE8E57B843938383838BEA723E7A21E7EC784A37D760E0E8E3FCF91FB613DFC8E22C7FB1447FBEC1C1CB51C79267FCD7EFFACE576CF170707070707C723C7B33DC31C1C1C1C1C1C1C1C1C1C1C1C1C1CEF541CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B07470B47FEBE2D0E0E0E8E77288EF6D97FE6582C16653A9D96C96452E6F3F98FEC799DF7722C73383838383838AE8ED96CF69177B55A95ED765BF6FB7D391C0E1F95D7792FC732277339383838383846A351592E9765B7DB95F3F95C1E8D1CCB9CCCCD9AD6B939383838385EAB9C8B8656F28CC7E3723A9D1EE6BF1F999B3559FB15193838383838EA3AEE9FB57CB6723D9473DAF178FC6DC375644DD6A6C7D01C1C1C1C1C1C751D79263FA4724F2DD745AF8EAC4D8FA1393838383838EA3A7EB567F859E599FE7ABD2E97CBE56547D6A6477A0DC9C2C1C1C1C1F17D1CD917B6D96C5E365C477AA4170707070747FF8EDCFBCAF54FF6870D1DE9915EE9C9C1C1C1C1D1BF23FF668FF1D0911EB73D393838383838383838383838EE1DBD5C477170707070D4AD1E9EE37070707070D4AF5EF69171707070707CBE7AF91C0B07070707475D472F9FA3E7E0E0E0E0A8EBE8E57BBC3838383838EA3A7AF91E610E0E0E0E8EEFE9C8B9A887DF31E1689F9D8383E3CF73E47E580FBFA3C8F13EC5D13E3B07472D479EC95FB3DF3F6BB9DDF3C5C1C1C1C1C1F1C8F16CCF3007070707070707070707070707C73B1547FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1D1C291BF6F8B838383E31D8AA37DF69F39168B45994EA765329994F97CFE237B5EE7BD1CCB1C0E0E0E0E0E8EAB63369B7DE45DAD5665BBDD96FD7E5F0E87C347E575DECBB1CCC95C0E0E0E0E0E8ED1685496CB65D9ED76E57C3E974723C7322773B3A6756E0E0E0E0E8ED72AE7A2A1953CE3F1B89C4EA787F9EF47E6664DD67E45060E0E0E0E8EBA8EFB672D9FAD5C0FE59C763C1E7FDB701D5993B5E931340707070707475D479EC90FA9DC53CB75D1AB236BD363680E0E0E0E0E8EBA8E5FED197E5679A6BF5EAFCBE57279D991B5E9915E43B270707070707C1F47F6856D369B970DD7911EE9C5C1C1C1C1D1BF23F7BE72FD93FD6143477AA4577A7270707070F4EFC8BFD9633C74A4C76D4F0E0E0E0E0E0E0E0E0E0E0E8E7B472FD7511C1C1C1C1C75AB87E7381C1C1C1C1CF5AB977D641C1C1C1C1C9FAF5E3EC7C2C1C1C1C151D7D1CBE7E83938383838EA3A7AF91E2F0E0E0E0E8EBA8E5EBE479883838383E37B3A722EEAE1774C38DA67E7E0E0F8F31CB91FD6C3EF2872BC4F71B4CFCEC151CB9167F2D7ECF7CF5A6EF77C7170707070703C723CDB33CCC1C1C1C1C1C1C1C1C1C1C1C1C1F14EC5D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB37370B470E4EFDBE2E0E0E07887E2689FFD678EC56251A6D369994C26653E9FFFC89ED7792FC732878383838383E3EA98CD661F7957AB55D96EB765BFDF97C3E1F051799DF7722C733297838383838363341A95E5725976BB5D399FCFE5D1C8B1CCC9DCAC699D9B83838383E3B5CAB9686825CF783C2EA7D3E961FEFB91B95993B55F918183838383A3AEE3FE59CB672BD74339A71D8FC7DF365C47D6646D7A0CCDC1C1C1C1C151D79167F2432AF7D4725DF4EAC8DAF4189A8383838383A3AEE3577B869F559EE9AFD7EB72B95C5E76646D7AA4D7902C1C1C1C1C1CDFC7917D619BCDE665C375A4477A7170707070F4EFC8BDAF5CFF647FD8D0911EE9959E1C1C1C1C1CFD3BF26FF6180F1DE971DB938383838383838383838383E3DED1CB75140707070747DDEAE1390E0707070747FDEA651F1907070707C7E7AB97CFB17070707070D475F4F2397A0E0E0E0E8EBA8E5EBEC78B83838383A3AEA397EF11E6E0E0E0E0F89E8E9C8B7AF81D138EF6D9393838FE3C47EE87F5F03B8A1CEF531CEDB37370D472E499FC35FBFDB396DB3D5F1C1C1C1C1C1C8F1CCFF60C7370707070707070707070707070BC5371B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C2D1CF9FBB638383838DEA138DA67FF9963B15894E9745A26934999CFE73FB2E775DECBB1CCE1E0E0E0E0E0B83A66B3D947DED56A55B6DB6DD9EFF7E570387C545EE7BD1CCB9CCCE5E0E0E0E0E0188D4665B95C96DD6E57CEE7737934722C7332376B5AE7E6E0E0E0E078AD722E1A5AC9331E8FCBE9747A98FF7E646ED664ED5764E0E0E0E0E0A8EBB87FD6F2D9CAF550CE69C7E3F1B70DD79135599B1E43737070707070D475E499FC90CA3DB55C17BD3AB2363D86E6E0E0E0E0E0A8EBF8D59EE1679567FAEBF5BA5C2E97971D599B1EE935240B07070707C7F771645FD866B379D9701DE9915E1C1C1C1C1CFD3B72EF2BD73FD91F3674A4477AA5270707070747FF8EFC9B3DC643477ADCF6E4E0E0E0E0E0E0E0E0E0E0E0B877F4721DC5C1C1C1C151B77A788EC3C1C1C1C151BF7AD947C6C1C1C1C1F1F9EAE5732C1C1C1C1C1C751DBD7C8E9E83838383A3AEA397EFF1E2E0E0E0E0A8EBE8E57B843938383838BEA723E7A21E7EC784A37D760E0E8E3FCF91FB613DFC8E22C7FB1447FBEC1C1CB51C79267FCD7EFFACE576CF170707070707C723C7B33DC31C1C1C1C1C1C1C1C1C1C1C1C1C1CEF541CEDB3737070707070707070707070707070B4CFCEC1C1C1C1C1C1C1C1C1C1C1C1C1C1D13E3B070707070707070707070707070747FBEC1C1C1C1C1C1C1C1C1C1C1C1C1C1C1CEDB373707070707070707CA5E37F2784A68E
Read temp1$

Dim m As _MEM, m1 As _MEM
m = _MemImage(0) 'a memblock pointing to our screen
m1 = _MemNew(Len(temp1$) / 2) 'a memblock to hold the data
HexToMem temp1$, m1 'unhex it back to a memblock
temp$ = Space$(m1.SIZE)
_MemGet m1, m1.OFFSET, temp$ 'get the unhexed data into a string to hold the unhexed, but still compressed data
_MemPut m, m.OFFSET, _Inflate$(temp$) 'put that uncompressed image onto the screen.
Sleep

Sub HexToMem (hx$, m As _MEM)
Dim i As _Integer64
Dim h As _Unsigned _Byte
For i = 1 To Len(hx$) Step 2
h = Val("&H" + Mid$(hx$, i, 2))
_MemPut m, m.OFFSET + i \ 2, h
Next
End Sub

Print this item

  Huge array of variable length strings
Posted by: mdijkens - 10-17-2024, 11:06 AM - Forum: General Discussion - Replies (9)

For a project I need to store an array of variable length strings.
Let's say

Code: (Select All)
Dim Shared as String s(100000)
But the issue is that the string lengths could vary from several bytes up to 2 GB
Code: (Select All)
For i% = 1 To 100
  s(i%) = String$(100000000, 42) ' 100MB
Next i%
As soon as the arrays total size is above a couple of GB it aborts the program...

I'd like to find a way to make max use of internal memory (>=32GB) 
What would be the best approach to define this?
I think _Mem is not very suitable for variable length strings

I could do one big _Mem and keep track of indexes/blocks but that's complicating the code quite a bit
Any better suggestions?

Print this item

  Variable characters
Posted by: eoredson - 10-17-2024, 05:47 AM - Forum: Utilities - Replies (7)

Did you ever notice there are 32 symbols on the standard 102-key natural keyboard and only 1 can be used in a variable name!?

Code: (Select All)
Rem all 32 symbolic characters.
'dim x~.a as inetegr
'dim x.a` as intrger
'dim x!.a as integer
'dim x@.a as integer
'dim x#.a as integer
'dim x$.a as integer
'dim x%.a as integer
'dim x^.a as integer
'dim x&.a as integer
'dim x*.a as integer
'dim x(.a as integer
'dim x).a as integer
'dim x_.a as integer
'dim x-.a as integer
'dim x+.a as integer
'dim x=.a as integer
'dim x|.a as integer
'dim x\.a as integer
'dim x{.a as integer
'dim x[.a as integer
'dim x}.a as integer
'dim x].a as integer
'dim x:.a as integer
'dim x;.a as integer
'dim x".a as integer
'dim x<.a as integer
'dim x,.a as integer
'dim x>.a as integer
'dim x'.a as integer
Dim x.a As Integer
'dim x?.a as integer
'dim x/.a as integer

Print this item

  2048 Puzzle
Posted by: Dav - 10-17-2024, 02:19 AM - Forum: Games - Replies (42)

Classic 2048 game.  Use arrows to move numbers.  Goal is to combine same numbers until a 2048 number is made.

Still working on this, but it's fully playable already. Lots of code bloat.  I need to rethink how I'm handling/drawing the board.  I didn't want to post this version now, but my wrist is starting to bother me a little from too much coding and piano gigs lately, so I'm going to rest from coding for a while and post this as is.  Will pick it up a later time.

- Dav

Code: (Select All)
'========
'2048.BAS
'========
'Classic 2048 puzzle for QB64.
'by Dav, OCT/2024

'Use arrow keys to move numbers on board.
'Score is shown in title bar.
'ESC quits

Screen _NewImage(800, 800, 32)

ReDim Shared board(3, 3), flash(3, 3), score

GetNewNumber
GetNewNumber

Do
    DrawBoard

    If MovesLeft = 0 Then
        Rbox 150, 150, 650, 450, 30, _RGBA(0, 0, 0, 150), 1
        Rbox 150, 150, 650, 450, 30, _RGBA(255, 255, 255, 255), 0
        Text 200 + 2, 200 + 2, 60, _RGB(0, 0, 0), "NO MORE MOVES!"
        Text 200, 200, 60, _RGB(255, 255, 255), "NO MORE MOVES!"
        Text 200 + 2, 300 + 2, 60, _RGB(0, 0, 0), "SCORE:" + _Trim$(Str$(score))
        Text 200, 300, 60, _RGB(255, 255, 255), "SCORE:" + _Trim$(Str$(score))
        _Display: Beep: _Delay 3: Exit Do
    End If

    Do
        key$ = InKey$
        _Limit 30
    Loop Until key$ <> ""

    Select Case key$
        Case Chr$(0) + "K": DoLeft 'left arrow
        Case Chr$(0) + "M": DoRight 'right arrow
        Case Chr$(0) + "H": DoUp 'up arrow
        Case Chr$(0) + "P": DoDown 'down arrow
    End Select
    _KeyClear

    GetNewNumber

Loop Until key$ = Chr$(27)
Sleep
End

Sub GetNewNumber

    '=== get a list of places to make a number
    ReDim temp(15)
    c = 0
    For x = 0 To 3
        For y = 0 To 3
            If board(x, y) = 0 Then
                temp(c) = x * 4 + y
                c = c + 1
            End If
        Next
    Next
    '=== choose one place to make a number
    If c > 0 Then
        i = Int(Rnd * c)
        If Rnd < .8 Then
            DrawBoard
            x1 = Int(temp(i) / 4): y1 = temp(i) Mod 4
            For s = 100 To 0 Step -20
                Rbox (x1 * 200) + s, (y1 * 200) + s, ((x1 * 200) + 200) - s, ((y1 * 200) + 200) - s, 30, _RGB(239, 229, 218), 1
                _Display
                _Delay .025
            Next
            board(x1, y1) = 2
        Else
            DrawBoard
            x1 = Int(temp(i) / 4): y1 = temp(i) Mod 4
            For s = 100 To 0 Step -20
                Rbox (x1 * 200) + s, (y1 * 200) + s, ((x1 * 200) + 200) - s, ((y1 * 200) + 200) - s, 30, _RGB(239, 229, 218), 1
                _Display
                _Delay .025
            Next
            board(x1, y1) = 4
        End If
    End If
End Sub

Sub DrawBoard
    Cls , _RGB(187, 173, 160)
    Color _RGB(255, 255, 255)

    For x = 0 To 3
        For y = 0 To 3
            Select Case board(x, y)
                Case 2: bg& = _RGB(239, 229, 218)
                Case 4: bg& = _RGB(236, 224, 198)
                Case 8: bg& = _RGB(241, 177, 121)
                Case 16: bg& = _RGB(236, 141, 84)
                Case 32: bg& = _RGB(247, 124, 95)
                Case 64: bg& = _RGB(233, 89, 55)
                Case 128: bg& = _RGB(242, 217, 107)
                Case 256: bg& = _RGB(238, 205, 96)
                Case 512: bg& = _RGB(238, 205, 96)
                Case 1024: bg& = _RGB(238, 205, 96)
                Case 2048: bg& = _RGB(238, 205, 96)
                Case 4096: bg& = _RGB(121, 184, 226)
                Case 8192: bg& = _RGB(121, 184, 226)
                Case 16384: bg& = _RGB(121, 184, 226)
                Case 32768: bg& = _RGB(60, 64, 64)
                Case Else: bg& = _RGB(204, 192, 180)
            End Select

            If flash(x, y) <> 0 Then
                'skip for now
            Else
                Rbox x * 200 + 5, y * 200 + 5, (x * 200) + 200 - 5, (y * 200) + 200 - 5, 30, bg&, 1
                Rbox x * 200 + 5, y * 200 + 5, (x * 200) + 200 - 5, (y * 200) + 200 - 5, 30, _RGB(255, 255, 255), 0
                If board(x, y) > 0 Then
                    num$ = _Trim$(Str$(board(x, y)))
                    If Val(num$) < 8 Then fg& = _RGB(128, 128, 128) Else fg& = _RGB(255, 255, 255)
                    size = 200 / 2: ts = size: tx = size / 2 + (size / 4): ty = size / 2
                    Select Case Len(num$)
                        Case 2: tx = size / 2: ty = size / 2
                        Case 3: ts = 200 / 2.5: tx = size / 2.5: ty = size / 1.75
                        Case 4: ts = 200 / 3: tx = size / 3: ty = size / 1.50
                        Case 5: ts = 200 / 3.5: tx = size / 3.5: ty = size / 1.36
                    End Select
                    Text x * 200 + tx + 2, y * 200 + ty + 2, ts, _RGB(0, 0, 0), num$
                    Text x * 200 + tx, y * 200 + ty, ts, fg&, num$
                End If
            End If

        Next
    Next


    'do flash board
    For s = 100 To 0 Step -20
        For x = 0 To 3
            For y = 0 To 3
                If flash(x, y) <> 0 Then
                    Select Case flash(x, y)
                        Case 2: bg& = _RGB(239, 229, 218)
                        Case 4: bg& = _RGB(236, 224, 198)
                        Case 8: bg& = _RGB(241, 177, 121)
                        Case 16: bg& = _RGB(236, 141, 84)
                        Case 32: bg& = _RGB(247, 124, 95)
                        Case 64: bg& = _RGB(233, 89, 55)
                        Case 128: bg& = _RGB(242, 217, 107)
                        Case 256: bg& = _RGB(238, 205, 96)
                        Case 512: bg& = _RGB(238, 205, 96)
                        Case 1024: bg& = _RGB(238, 205, 96)
                        Case 2048: bg& = _RGB(238, 205, 96)
                        Case 4096: bg& = _RGB(121, 184, 226)
                        Case 8192: bg& = _RGB(121, 184, 226)
                        Case 16384: bg& = _RGB(121, 184, 226)
                        Case 32768: bg& = _RGB(60, 64, 64)
                        Case Else: bg& = _RGB(204, 192, 180)
                    End Select
                    Rbox (x * 200) + s, (y * 200) + s, ((x * 200) + 200) - s, ((y * 200) + 200) - s, 30, bg&, 1
                End If
            Next
        Next

        _Display
        _Delay .025

    Next

    'do regular board next
    For x = 0 To 3
        For y = 0 To 3
            Select Case board(x, y)
                Case 2: bg& = _RGB(239, 229, 218)
                Case 4: bg& = _RGB(236, 224, 198)
                Case 8: bg& = _RGB(241, 177, 121)
                Case 16: bg& = _RGB(236, 141, 84)
                Case 32: bg& = _RGB(247, 124, 95)
                Case 64: bg& = _RGB(233, 89, 55)
                Case 128: bg& = _RGB(242, 217, 107)
                Case 256: bg& = _RGB(238, 205, 96)
                Case 512: bg& = _RGB(238, 205, 96)
                Case 1024: bg& = _RGB(238, 205, 96)
                Case 2048: bg& = _RGB(238, 205, 96)
                Case 4096: bg& = _RGB(121, 184, 226)
                Case 8192: bg& = _RGB(121, 184, 226)
                Case 16384: bg& = _RGB(121, 184, 226)
                Case 32768: bg& = _RGB(60, 64, 64)
                Case Else: bg& = _RGB(204, 192, 180)
            End Select
            Rbox x * 200 + 5, y * 200 + 5, (x * 200) + 200 - 5, (y * 200) + 200 - 5, 30, bg&, 1
            Rbox x * 200 + 5, y * 200 + 5, (x * 200) + 200 - 5, (y * 200) + 200 - 5, 30, _RGB(255, 255, 255), 0
            If board(x, y) > 0 Then
                num$ = _Trim$(Str$(board(x, y)))
                If Val(num$) < 8 Then fg& = _RGB(128, 128, 128) Else fg& = _RGB(255, 255, 255)
                size = 200 / 2: ts = size: tx = size / 2 + (size / 4): ty = size / 2
                Select Case Len(num$)
                    Case 2: tx = size / 2: ty = size / 2
                    Case 3: ts = 200 / 2.5: tx = size / 2.5: ty = size / 1.75
                    Case 4: ts = 200 / 3: tx = size / 3: ty = size / 1.50
                    Case 5: ts = 200 / 3.5: tx = size / 3.5: ty = size / 1.36
                End Select
                Text x * 200 + tx + 2, y * 200 + ty + 2, ts, _RGB(0, 0, 0), num$
                Text x * 200 + tx, y * 200 + ty, ts, fg&, num$
            End If
        Next
    Next

    ReDim flash(3, 3)


    _Title "2048 - " + "Score: " + Str$(score)
    _Display

End Sub

Sub DoLeft

    ReDim flash(3, 3)

    For y = 0 To 3
        ReDim row(3)
        p = 0
        For x = 0 To 3
            If board(x, y) <> 0 Then
                If row(p) = board(x, y) Then
                    row(p) = row(p) + board(x, y)
                    score = score + row(p)
                    flash(p, y) = row(p) '+ board(x, y)
                    p = p + 1
                ElseIf row(p) = 0 Then
                    row(p) = board(x, y)
                Else
                    p = p + 1
                    If p < 4 Then row(p) = board(x, y)
                End If
            End If
        Next

        For x = 0 To 3
            board(x, y) = row(x)
        Next

    Next

End Sub

Sub DoRight
    ReDim flash(3, 3)

    For y = 0 To 3
        ReDim row(3)
        p = 3
        For x = 3 To 0 Step -1
            If board(x, y) <> 0 Then
                If row(p) = board(x, y) Then
                    row(p) = row(p) + board(x, y)
                    score = score + row(p)
                    flash(p, y) = row(p)
                    p = p - 1
                ElseIf row(p) = 0 Then
                    row(p) = board(x, y)
                Else
                    p = p - 1
                    If p >= 0 Then
                        row(p) = board(x, y)
                    End If
                End If
            End If
        Next

        For x = 0 To 3
            board(x, y) = row(x)
        Next
    Next

End Sub

Sub DoUp

    ReDim flash(3, 3)

    For x = 0 To 3
        ReDim col(3)
        p = 0
        For y = 0 To 3
            If board(x, y) <> 0 Then
                If col(p) = board(x, y) Then
                    col(p) = col(p) + board(x, y)
                    score = score + col(p)
                    flash(x, p) = col(p)
                    p = p + 1
                ElseIf col(p) = 0 Then
                    col(p) = board(x, y)
                Else
                    p = p + 1
                    If p < 4 Then col(p) = board(x, y)
                End If
            End If
        Next

        For y = 0 To 3
            board(x, y) = col(y)
        Next
    Next

End Sub

Sub DoDown

    ReDim flash(3, 3)

    For x = 0 To 3
        ReDim col(3)
        p = 3
        For y = 3 To 0 Step -1
            If board(x, y) <> 0 Then
                If col(p) = board(x, y) Then
                    col(p) = col(p) + board(x, y)
                    score = score + col(p)
                    flash(x, p) = col(p)
                    p = p - 1
                ElseIf col(p) = 0 Then
                    col(p) = board(x, y)
                Else
                    p = p - 1
                    If p >= 0 Then col(p) = board(x, y)
                End If
            End If
        Next

        For y = 3 To 0 Step -1
            board(x, y) = col(y)
        Next
    Next

End Sub

Function MovesLeft
    MovesLeft = 0
    For x = 0 To 3
        For y = 0 To 3
            If board(x, y) = 0 Then
                MovesLeft = 1
            End If
            If y < 3 Then
                If board(x, y) = board(x, y + 1) Then
                    MovesLeft = 1
                End If
            End If
            If x < 3 Then
                If board(x, y) = board(x + 1, y) Then
                    MovesLeft = 1
                End If
            End If
        Next
    Next
End Function

Sub Text (x, y, textHeight, K As _Unsigned Long, txt$)
    'Text SUB by bplus.
    Dim fg As _Unsigned Long, cur&, I&, multi, xlen
    fg = _DefaultColor
    cur& = _Dest
    I& = _NewImage(8 * Len(txt$), 16, 32)
    _Dest I&
    Color K, _RGBA32(0, 0, 0, 0)
    _PrintString (0, 0), txt$
    multi = textHeight / 16
    xlen = Len(txt$) * 8 * multi
    _PutImage (x, y)-Step(xlen, textHeight), I&, cur&
    Color fg
    _FreeImage I&
    _Dest cur&
End Sub


Sub Rbox (x1, y1, x2, y2, r, clr~&, fill)
    'x1/y1, y2/y2 = placement of box
    'r = radius of rounded corner
    'clr~& = color of box
    'fill =  1 for filled, 0 for just an edge

    ReDim filled(_Width + x2, _Height + y2) As Integer

    If fill = 1 Then
        Line (x1 + r + 1, y1)-(x2 - r - 1, y1 + r), clr~&, BF 'top
        Line (x1 + r + 1, y2 - r)-(x2 - r - 1, y2), clr~&, BF 'bottom
        Line (x1, y1 + r + 1)-(x1 + r, y2 - r - 1), clr~&, BF 'left
        Line (x2 - r, y1 + r + 1)-(x2, y2 - r - 1), clr~&, BF 'right
        Line (x1 + r + 1, y1 + r + 1)-(x2 - r - 1, y2 - r - 1), clr~&, BF 'middle
    Else
        Line (x1 + r, y1)-(x2 - r, y1), clr~& 'top
        Line (x1 + r, y2)-(x2 - r, y2), clr~& 'bottom
        Line (x1, y1 + r)-(x1, y2 - r), clr~& 'left
        Line (x2, y1 + r)-(x2, y2 - r), clr~& 'right
    End If

    'top left corner
    For angle = 180 To 270
        If fill = 1 Then
            For radius = 0 To r
                x3 = (x1 + r) + radius * Cos(_D2R(angle))
                y3 = (y1 + r) + radius * Sin(_D2R(angle))
                If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
            Next
        Else
            x3 = (x1 + r) + r * Cos(_D2R(angle))
            y3 = (y1 + r) + r * Sin(_D2R(angle))
            If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
        End If
    Next

    'top right corner
    For angle = 270 To 360
        If fill = 1 Then
            For radius = 0 To r
                x3 = (x2 - r) + radius * Cos(_D2R(angle))
                y3 = (y1 + r) + radius * Sin(_D2R(angle))
                If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
            Next
        Else
            x3 = (x2 - r) + r * Cos(_D2R(angle))
            y3 = (y1 + r) + r * Sin(_D2R(angle))
            If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
        End If
    Next

    'bottom left corner
    For angle = 90 To 180
        If fill = 1 Then
            For radius = 0 To r
                x3 = (x1 + r) + radius * Cos(_D2R(angle))
                y3 = (y2 - r) + radius * Sin(_D2R(angle))
                If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
            Next
        Else
            x3 = (x1 + r) + r * Cos(_D2R(angle))
            y3 = (y2 - r) + r * Sin(_D2R(angle))
            If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
        End If
    Next

    'bottom right corner
    For angle = 0 To 90
        If fill = 1 Then
            For radius = 0 To r
                x3 = (x2 - r) + radius * Cos(_D2R(angle))
                y3 = (y2 - r) + radius * Sin(_D2R(angle))
                If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
            Next
        Else
            x3 = (x2 - r) + r * Cos(_D2R(angle))
            y3 = (y2 - r) + r * Sin(_D2R(angle))
            If filled(x3, y3) = 0 Then PSet (x3, y3), clr~&: filled(x3, y3) = 1
        End If
    Next

End Sub

Print this item