Welcome, Guest |
You have to register before you can post on our site.
|
|
|
QB64_GJ_LIB ARRay Library |
Posted by: grymmjack - 08-21-2023, 12:07 AM - Forum: Programs
- Replies (3)
|
|
Hi.
I've added some handy stuff to my library for dealing with arrays:
https://github.com/grymmjack/QB64_GJ_LIB/tree/main/ARR
What is in the library? Read the README.md, but:
TYPES SUPPORTED: - _BYTE
- _UNSIGNED _BYTE
- INTEGER
- _UNSIGNED INTEGER
- _INTEGER64
- _UNSIGNED _INTEGER64
- LONG
- _UNSIGNED LONG
- SINGLE
- DOUBLE
- _FLOAT
- STRING
Every numeric type contains the following SUBs/FUNCTIONs e.g. ARR_INT.slice for the slice SUB for INTEGER type.
SUBS AND FUNCTIONS FOR NUMERIC TYPES:
Code: (Select All) .slice Slice an array from source to destination starting at index and count slices
.push Push a element onto the end of the array
.pop Pop a element off the end of the array
.shift Pop a element off the beginning of the array
.unshift Push a element on the beginning of the array
.copy Copy an array
.join Return array contents as comma delimited string
.new Create new array using comma delimited string
.longest Return the longest element of an array
.shortest Return the shortest element of an array
.math Do math on every element of an array
.min Return minimum element of an array
.max Return maximum element of an array
.first Return 1st element of an array
.last Return last element of an array
.nth Return every nth element of an array
.in Determine if a value exists in an array
.find Find a value in an array and return it's index
.count Return the number of elements in an array
.size Return the size in bytes of all elements in an array
.reverse Reverse the index of elements in an array
.random Return a random element from the array
.sum Return the sum of all elements in an array
.avg Return the average of all elements in an array
.shuffle Randomize the indexes of all elements in an array
.unique Return unique elements in an array
.gt Return elements greater than (>) value in an array
.gte Return elements greater than or equal (>=) value in an array
.lt Return elements less than (<>=) value in an array
.lte Return elements less than or equal (<>=) value in an array
.replace Replace elements in array with replacement value
.insert Insert element in an array at index
.remove Remove element in an array at index
.odd Return odd numbered indexed elements in an array
.even Return even numbered indexed elements in an array
.mod Return evenly divisible by n numbered indexed elements in an array
.between Return elements between a start and end index in an array
.sort Sort elements of an array in ascending order
.rsort Sort elements of an array in desscending order
SUBS AND FUNCTIONS FOR STRING TYPE:
Code: (Select All) .slice Slice an array from source to destination starting at index and count slices
.push Push a element onto the end of the array
.pop Pop a element off the end of the array
.shift Pop a element off the beginning of the array
.unshift Push a element on the beginning of the array
.copy Copy an array
.join Return array contents as comma delimited string
.new Create new array using comma delimited string
.longest Return the longest element of an array
.shortest Return the shortest element of an array
.first Return 1st element of an array
.last Return last element of an array
.nth Return every nth element of an array
.in Determine if a value exists in an array
.find Find a value in an array and return it's index
.count Return the number of elements in an array
.size Return the size in bytes of all elements in an array
.reverse Reverse the index of elements in an array
.random Return a random element from the array
.shuffle Randomize the indexes of all elements in an array
.unique Return unique elements in an array
.replace Replace elements in array with replacement value
.insert Insert element in an array at index
.remove Remove element in an array at index
.odd Return odd numbered indexed elements in an array
.even Return even numbered indexed elements in an array
.mod Return evenly divisible by n numbered indexed elements in an array
.between Return elements between a start and end index in an array
.sort Sort elements of an array in ascending order
.rsort Sort elements of an array in desscending order
|
|
|
polyFT - draw filled polygons |
Posted by: James D Jarvis - 08-20-2023, 09:55 PM - Forum: Utilities
- Replies (5)
|
|
an update of an older sub to draw filled polygons using _maptriangle . This one is faster than the earlier version (polyT) and includes options for rotation, horizontal and vertical scaling, and a border.
Code: (Select All)
'draw_polyFT
' by James D. Jarvis , August 20,2023
'draw filled polygons
'
'HEADER
Dim Shared xmax, ymax
xmax = 800: ymax = 500
Screen _NewImage(xmax, ymax, 32)
Dim Shared pk& 'must be included in a program that uses polyFT
pk& = _NewImage(3, 3, 32) 'must be included in a program that uses polyFT
'======================================
' demo
'======================================
' This demo draws 64000 random polygons, and then clears the screen and draws a handful of polygons rotating
Randomize Timer
t1 = Timer
For reps = 1 To 64000
polyFT Int(Rnd * xmax), Int(Rnd * ymax), Int(3 + Rnd * 20), Int(3 + Rnd * 12), Int(Rnd * 60), Int(1 + Rnd * 3), Int(1 + Rnd * 3), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256)), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
Next reps
t2 = Timer
Print "That took "; t2 - t1; " seconds to draw 64000 polygons"
Sleep
rtn = 0
Do
_Limit 60
Cls
Print "Press <ESC> to quit>"
polyFT 100, 100, 40, 3, rtn, 1, 1, _RGB32(100, 200, 50), 0
polyFT 200, 100, 40, 4, 45 + rtn, 1, 1, _RGB32(100, 200, 250), 0
polyFT 300, 100, 40, 5, rtn, 1, 1, _RGB32(200, 100, 250), 0
polyFT 400, 100, 40, 6, rtn, 1, 1, _RGB32(100, 250, 150), 0
polyFT 500, 100, 40, 7, rtn, 1, 1, _RGB32(150, 200, 200), 0
polyFT 600, 100, 40, 8, 22.5 + rtn, 1, 1, _RGB32(200, 200, 0), 0
_PrintString (100 - (_PrintWidth("Triangle")) / 2, 160), "Triangle"
_PrintString (200 - (_PrintWidth("Square")) / 2, 160), "Square"
_PrintString (300 - (_PrintWidth("Pentagon")) / 2, 160), "Pentagon"
_PrintString (400 - (_PrintWidth("Hexagon")) / 2, 160), "Hexagon"
_PrintString (500 - (_PrintWidth("Heptagon")) / 2, 160), "Heptagon"
_PrintString (600 - (_PrintWidth("Octagon")) / 2, 160), "Octagon"
rtn = rtn + 1: If rtn > 360 Then rtn = 0
_Display 'for smooth display
Loop Until InKey$ = Chr$(27)
'==========================================================================
'subroutines
'
' polyFT draw a filled polygon
'
' setklr is a sub to build the color image used by triangles in polyFT
'====================================== ==================================
Sub polyFT (cx As Long, cy As Long, rad As Long, sides As Integer, rang As Long, ww, vv, klr As _Unsigned Long, lineyes As _Unsigned Long)
'draw an equilateral polygon using filled triangle for each segment
'centered at cx,cy to radius rad of sides # of face rotated to angle rang scaled to ww and vv of color klr and lineyes if there is an outline, a value 0 would create no outline
setklr klr
Dim px(sides)
Dim py(sides)
pang = 360 / sides
ang = 0
For p = 1 To sides
px(p) = cx + (rad * Cos(0.01745329 * (ang + rang))) * ww
py(p) = cy + (rad * Sin(0.01745329 * (ang + rang))) * vv
ang = ang + pang
Next p
For p = 1 To sides - 1
_MapTriangle (0, 0)-(0, 2)-(2, 0), pk& To(cx, cy)-(px(p), py(p))-(px(p + 1), py(p + 1))
If lineyes > 0 Then Line (px(p), py(p))-(px(p + 1), py(p + 1)), lineyes
Next p
_MapTriangle (0, 0)-(0, 2)-(2, 0), pk& To(cx, cy)-(px(sides), py(sides))-(px(1), py(1))
If lineyes > 0 Then Line (px(sides), py(sides))-(px(1), py(1)), lineyes
End Sub
Sub setklr (klr As Long)
'internal routine to setup an image to copy a colored triangle from in the color klr
'called by polyT
_Dest pk&
Line (0, 0)-(2, 2), klr, BF
_Dest 0
End Sub
|
|
|
fhex ... a Filled Hex |
Posted by: James D Jarvis - 08-19-2023, 06:52 PM - Forum: Utilities
- Replies (2)
|
|
a little routine and associated demo for drawing a filled hex.
Code: (Select All)
'Fhex
'by James D. Jarvis August 19,2023
'draw a filled hex
'demo code
Screen _NewImage(500, 500, 32)
rr = 200
For d = 1 To 10
fcirc 250, 250, rr, _RGB32(200, 200, 0)
fhex 250, 250, rr, _RGB32(200, 100, 100)
rr = rr * .86
Next d
For a = 60 To 360 Step 60
ang_line 250, 250, 200, a, _RGB32(250, 0, 0)
Next a
hx = 60: hy = 60: hl = 12
fhex hx, hy, hl, _RGB32(100, 100, 100)
For ha = 30 To 390 Step 60
hx = 60 + (hl * 1.9) * Cos(0.01745329 * ha)
hy = 60 + (hl * 1.9) * Sin(0.01745329 * ha)
fhex hx, hy, hl, _RGB32(ha / 2, ha / 2, ha / 20)
Next ha
Sub fhex (cx As Long, cy As Long, r, klr As _Unsigned Long)
'draw a hex to radius r filled with color klr centeted on cx,cy
rcheck = ((r * .867) * (r * .867))
For dY = -r To r
If dY * dY < rcheck Then
dx = r - Abs(dY / _Pi * 1.81)
Line (cx - dx, dY + cy)-(cx + dx, dY + cy), klr, BF
End If
Next dY
End Sub
'ang_line and fcirc included for demo not needed for fhex itself
Sub ang_line (sx, sy, lnth, ang, klr As _Unsigned Long)
'draw a line lnth units long from sx,sy at anlge ang measures in degrees, 0 deg is out along X axis
nx = sx + lnth * Cos(0.01745329 * ang)
ny = sy + lnth * Sin(0.01745329 * ang)
Line (sx, sy)-(nx, ny), klr
End Sub
Sub fcirc (CX As Long, CY As Long, R, klr As _Unsigned Long)
'draw a filled circle with the quickest filled circle routine in qb64, not my development
Dim subRadius As Long, RadiusError As Long
Dim X As Long, Y As Long
subRadius = Abs(R)
RadiusError = -subRadius
X = subRadius
Y = 0
If subRadius = 0 Then PSet (CX, CY): Exit Sub
Line (CX - X, CY)-(CX + X, CY), klr, 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), klr, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), klr, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), klr, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), klr, BF
Wend
End Sub
|
|
|
API Questions |
Posted by: TerryRitchie - 08-18-2023, 07:35 PM - Forum: Help Me!
- Replies (24)
|
|
Since I've started diving into API calls I figured a dedicated thread for API related questions would be better.
Here is my first question.
In the Wiki here: https://qb64phoenix.com/qb64wiki/index.p...ndow_Focus
It's shown how to determine the foreground window (the one in focus).
The Microsoft docs for GetForegroundWindow are located here: https://learn.microsoft.com/en-us/window...oundwindow
I noticed in the Wiki example that GetForegroundWindow is declared as an _OFFSET (%&). How was this determined? Looking at the Microsoft docs there is no indication of the type of variable returned. With other window handle (hWnd) related functions I've noticed a variable type of LONG is used. Why was _OFFSET needed here instead of LONG?
This has me confused. Any clarification would be greatly appreciated.
|
|
|
|