As I see, QB64 only knows the logarithm function LOG() to the base e.
The following small program calculates the binary logarithm ( logarithm to the base of 2) and the logarithms to the base 10 and n
Code: (Select All)
DIM AS _FLOAT a, n
a = 22
PRINT log2##(a)
PRINT logn##(22, 2)
PRINT logn##(22, 10)
PRINT log10##(22)
'Function log2: logarithm to the base of 2 (binary logarithm)
FUNCTION log2## (a)
log2## = (LOG(a) / LOG(2))
END FUNCTION
'Function log10: logarithm of a to the base of n
FUNCTION log10## (a)
log10## = (log2##(a) / log2##(10))
END FUNCTION
'Function logn: logarithm of a to the base of n
FUNCTION logn## (a, n)
logn## = (log2##(a) / log2(n))
END FUNCTION
LOG10 is often called LG and
LOG is often LN (for natural logarithm).
Could these functions be implemented as standard QB64PE functions: _LOG2(), _LOG10(), LOGn(,)?
I have an update to the cellular automata demo I did a long time ago. I've done some optimizations and I have more to go, but its in a 'playable' state.
I'm planning on adding it as a game mechanic to my rouge-like 'Panacea'. There are several materials for you to choose from and they have different interactions with other materials (especially acid). Eventually there will many materials your character will have to collect and mix to make medicine for the village.
As of now it is a stand alone program so I'll upload it here so you can mess with it.
The controls are simple. Use the mouse to select the material and draw it on the canvas.
'c' clears the canvas, 'l' loads a canvas from 'cellauto.ca', 's' saves the canvas to 'cellauto.ca', and 'space' pauses the simulation.
A while back I found some TI-84 code for a random number generator. Played with it for a while, adapting it to QB64. Messed with the calcs. Gave it more randomness (I think) by feeding it the starting x/y position of the QB84 windows that seems to be placed randomly, and threw in TIMER for good luck. I don't really understand it, but here it is for anyone interested in such a function.
- Dav
Code: (Select All)
'========
'RAND.BAS
'========
'Get a random number, without using RND
'Adapted for QB64 from TI-84 source found online.
'Thrown together By Dav, SEP/2023
'Since the QB64 window x/y position always starts at a
'random position, I'm using that as the seed starter.
_Delay .25
DIM SHARED seed: seed = _SCREENX * _SCREENY * TIMER
SCREEN _NEWIMAGE(800, 600, 32)
'Blocks of random size of random colors at random positions.
DO
x = Rand(_WIDTH)
y = Rand(_HEIGHT)
s = Rand(100)
r = Rand(255): g = Rand(255): b = Rand(255)
LINE (x, y)-STEP(s, s), _RGB(r, g, b), BF
_LIMIT 1000
LOOP
FUNCTION Rand (num)
DIM z AS _INTEGER64, k AS _INTEGER64
seed2 = seed * TIMER
k = seed / 53668
seed = 40014 * (seed - k * 53668) - k * 12211
IF seed < 0 THEN seed = seed + 2147483563
k = seed2 / 52774
seed2 = 40692 * (seed2 - k * 52774) - k * 3791
IF seed2 < 0 THEN seed2 = seed2 + 2147483563
z = seed - seed2
IF z < 1 THEN z = z + 2147483563
Rand = z * 4.656613E-10 * 190000000 MOD num
END FUNCTION
I'm making a utility program that doesn't use a main SCREEN at all, but instead relies on dialogs for interaction. A couple questions, about the message dialog & input box.
1) Is the message dialogs display behavior the same on all OS's? Will a CHR$(10) start a new line for everyone?
2) Is there a way to center the input box on the screen?
Here's an example of what I'm doing with those. Giving away what I'm working on again - since _LOADIMAGE/_SNDOPEN has a "memory" option now, I had to reawaken the old QBV project.
- Dav
Code: (Select All)
_ScreenHide
lf$ = Chr$(10)
a$ = "QBV Video Builder v1.0." + lf$ + lf$
a$ = a$ + "This app builds an .QBV Audio/Video file from a" + lf$
a$ = a$ + "numeric sequence of images (ex: 000001.JPG, etc)" + lf$
a$ = a$ + "and an optional .OGG file. You will be allowed" + lf$
a$ = a$ + "to specify a frame rate." + lf$ + lf$
a$ = a$ + "Please select a starting image file..."
_MessageBox "QB64 Video Builder", a$, "info"
result$ = _InputBox$("QBV Video Builder", "Frame rate p/s:", "15")
Posted by: eoredson - 09-30-2023, 01:06 AM - Forum: Programs
- No Replies
I have been using FindFirst for awhile and found FindFirstVolume in MSDN which is here:
Code: (Select All)
Const MAX_PATH = 260
Const INVALID_HANDLE_VALUE = -1
Declare Dynamic Library "kernel32"
Function FindFirstVolumeW~%& (ByVal lpFileName~%&, MAX_PATH)
Function FindNextVolumeW& (ByVal hFindFile~%&, Byval hFindPoint~%&, MAX_PATH)
Function FindVolumeClose& (ByVal hFindFile~%&)
End Declare
Dim ASCIIZ As String * 260
Dim Wfile.Handle As _Unsigned _Offset
' find first long filename
Wfile.Handle = FindFirstVolumeW(_Offset(ASCIIZ), MAX_PATH)
' check findirst error
If Wfile.Handle <> INVALID_HANDLE_VALUE Then
' filename/directory loop
Do
X$ = ASCIIZ
Do
X = InStr(X$, Chr$(0))
If X Then
X$ = Left$(X$, X - 1) + Mid$(X$, X + 1)
Else
Exit Do
End If
Loop
Print X$
Loop While FindNextVolumeW(Wfile.Handle, _Offset(ASCIIZ), MAX_PATH)
X = FindVolumeClose(Wfile.Handle)
End If
End
When I initially set a color to a transparency level with _SETALPHA I can't change it to another transparency level later on.
I'm certain I've done this in the past.
I've found a work-around using a temporary image but I'm sure this is not needed ... or is it? See my code below and please explain to me why the first block of code is not working. A bug? Brain-fart on my part?
Code: (Select All)
'|
'| Fade in a red box test
'|
DIM RedBox AS LONG
DIM TempBox AS LONG
DIM c AS INTEGER
'c = 0 ' |
'DO ' | This block of code does not work?
' CLS ' |
' _LIMIT 30 ' | The Wiki shows however this should be acceptable
' _SETALPHA c, _RGB32(255, 0, 0), RedBox ' |
' _PUTIMAGE (159, 119), RedBox ' |
' _DISPLAY ' |
' c = c + 1 ' |
'LOOP UNTIL c = 256 ' |
c = 0 ' |
DO ' | This block of code does work.
CLS ' |
_LIMIT 30 ' | Why do I need to copy the original RedBox to
TempBox = _COPYIMAGE(RedBox) ' | to another image for every iteration of the loop?
_SETALPHA c, _RGB32(255, 0, 0), TempBox ' |
_PUTIMAGE (159, 119), TempBox ' |
_DISPLAY ' |
_FREEIMAGE TempBox ' |
c = c + 1 ' |
LOOP UNTIL c = 256 ' |