Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 472
» Latest member: JonnyWi
» Forum threads: 2,754
» Forum posts: 26,111
Full Statistics
|
|
|
random numbers |
Posted by: badger - 11-06-2024, 11:15 PM - Forum: General Discussion
- Replies (8)
|
|
Hello
can someone tell me why this little program will not work i dont really understand why.
badger
thanks in advance
Code: (Select All)
DECLARE SUB GenerateUniqueNumbers()
DIM numbers(5) AS INTEGER
DIM count AS INTEGER
DIM i AS INTEGER
DIM newNumber AS INTEGER
DIM isDuplicate AS INTEGER
SUB GenerateUniqueNumbers
count = 0
DO
' Generate a random number between -1 and 71
newNumber = INT(RND * 73) - 1
isDuplicate = 0
' Check if the number is already in the array
FOR i = 1 TO count
IF numbers(i) = newNumber THEN
isDuplicate = 1
EXIT FOR
END IF
NEXT i
' If it's not a duplicate, add it to the array
IF isDuplicate = 0 THEN
count = count + 1
numbers(count) = newNumber
END IF
LOOP UNTIL count = 5
' Print the selected numbers
PRINT "The 5 unique numbers are:"
FOR i = 1 TO 5
PRINT numbers(i)
NEXT i
END SUB
' Seed the random number generator
RANDOMIZE TIMER
' Call the subroutine to generate and display the numbers
GenerateUniqueNumbers
|
|
|
Cursor is showing low in graphics screen |
Posted by: PhilOfPerth - 11-06-2024, 02:06 AM - Forum: Help Me!
- Replies (2)
|
|
I'm trying to use mouse functions to identify points on the screen, but noticed the corsor is displaying about 5 pixels below its actual point. Is this something unique to my system? I know I can compensate with my zone positions, but just curious. Try this:
Code: (Select All) Screen _NewImage(1040, 768, 32)
PSet (175, 175)
For a = 1 To 7: Draw "d28r26u28l26r26": Next
GetMouse:
While _MouseInput
X = _MouseX: Y = _MouseY
Locate 2, 2: Print X, Y
Wend
GoTo GetMouse
I want to select each cell accurately by mouse pointer, but the pointer is about 5 pixels low.
|
|
|
The greatest common divisor of two numbers |
Posted by: Petr - 11-04-2024, 07:16 PM - Forum: Petr
- Replies (3)
|
|
Hi. I think this might be a useful feature for someone.
inspired by: https://demonstrations.wolfram.com/Findi...Factoring/
Code: (Select All)
NumA = 1000
NumB = 552
E = GreatestCommonDivisor(NumA, NumB)
Print "Greatest Common Divisor for"; NumA; "and"; NumB; " is:"; E
End
Function GreatestCommonDivisor& (A As Long, B As Long)
If A = 0 And Abs(B) > 0 Then GreatestCommonDivisor& = B: Exit Function
If B = 0 And Abs(A) > 0 Then GreatestCommonDivisor& = A: Exit Function
If A = 0 And B = 0 Then GreatestCommonDivisor& = 0: Exit Function
Dim As Long NrA(0)
Dim As Long NrB(0)
Dim As Long i, NrAI, NrBI, NumA, NumB
NumA = A
i = 1
Do Until i >= NumA
i = i + 1
If NumA Mod i = 0 Then
NumA = NumA \ i
NrA(NrAI) = i
NrAI = NrAI + 1
ReDim _Preserve NrA(NrAI) As Long
i = 1
End If
Loop
NumB = B
i = 1
Do Until i >= NumB
i = i + 1
If NumB Mod i = 0 Then
NumB = NumB \ i
NrB(NrBI) = i
NrBI = NrBI + 1
ReDim _Preserve NrB(NrBI) As Long
i = 1
End If
Loop
Dim Outs(0) As Long
Do Until ArrA = UBound(NrA)
If ArrA > UBound(NrA) Then Exit Do
NumA = NrA(ArrA)
ArrB = 0
Do Until ArrB = UBound(NrB)
If ArrB > UBound(NrB) Then Exit Do
NumB = NrB(ArrB)
If NumA > 0 And NumB > 0 Then
If NumA = NumB Then
Pass = 1
Outs(outI) = NumA
outI = outI + 1
ReDim _Preserve Outs(outI) As Long
NrA(ArrA) = -1 'just rewrite used numbers to wrong values (so the same valid is not used twice)
NrB(ArrB) = -1
Exit Do
End If
End If
ArrB = ArrB + 1
Loop
ArrA = ArrA + 1
Loop
If UBound(Outs) > 0 Then
ReDim _Preserve Outs(UBound(Outs) - 1) As Long
End If
Erase NrA
Erase NrB
If Pass = 0 Then
GreatestCommonDivisor& = 1
Erase Outs
Exit Function
End If
'calculate greatest common divisor
GCD& = Outs(0)
For o = 1 To UBound(Outs)
GCD& = GCD& * Outs(o)
Next
Erase Outs
GreatestCommonDivisor& = GCD&
End Function
|
|
|
Setting Line _RGB colours |
Posted by: PhilOfPerth - 11-03-2024, 12:46 AM - Forum: Help Me!
- Replies (10)
|
|
How can I convert this line:
Line (H, V)-(H+ 37, V+ 38), _RGB(200, 200, 200), BF
to set the _RGB colour to a colour in a sub, instead of this fixed colour? (I'm using a _NewImage 32-bit screen)
Sub Red might contain Color: _RGB(255,0,0)
|
|
|
Ok, sound experts need a couple of answers |
Posted by: doppler - 11-02-2024, 04:13 PM - Forum: General Discussion
- Replies (3)
|
|
First off _sndplayfile doesn't wait for completion before moving on to next program line. Or did I miss something ? ie: two plays directs only plays the second sound.
Must use open, play handle, do/loop until sndplaying isn't.
Second with all the sound bugs fixed and a flurry of forum message about it. (didn't follow all the threads) Is there a way to compile sound (wav) files into the program EXE result? Much like ICON ico files can being included inside exe.
Third is it possible to pre-load wav files into a memory array (different files at different indexes) and run from the array instead of playing files on disk?
Four converting all the wav files to mp3 would make them smaller. But would than be better for playing them ? IMHO no difference.
Thanks
There is a method and purpose to my madness.
|
|
|
SquarePrint |
Posted by: SMcNeill - 11-01-2024, 03:23 AM - Forum: SMcNeill
- No Replies
|
|
A simple routine to print a square text of any size font to the screen, as per Phil's request here: https://qb64phoenix.com/forum/showthread.php?tid=3182
Code: (Select All)
$Color:32
Screen _NewImage(640, 480, 32)
Color Orange, Blue
SquarePrint 0, 0, 8, "Hello World"
Color Red, Green
Sleep
SquarePrint 8, 8, 32, "Hello World"
Color Blue, Yellow
Sleep
SquarePrint 100, 100, 32, "Testing the code!"
Sleep
System
Sub SquarePrint (x, y, size As Single, text$)
Dim As _Unsigned Long dc, bg
If size < 4 Or size > 256 Then Exit Sub
sz = size / 8
tempscreen = _NewImage(_Width / size * 8, _Height / size * 8, 32)
d = _Dest: dc = _DefaultColor: bg = _BackgroundColor
_Dest tempscreen
Color dc, bg: _Font 8
_PrintString (x * 8 / size, y * 8 / size), text$
_Dest d
_PutImage , tempscreen
_FreeImage tempscreen
End Sub
|
|
|
|