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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 496
» Latest member: braveparrot
» Forum threads: 2,846
» Forum posts: 26,663

Full Statistics

Latest Threads
Cautionary tale of open, ...
Forum: General Discussion
Last Post: doppler
17 minutes ago
» Replies: 3
» Views: 63
Extended KotD #23 and #24...
Forum: Keyword of the Day!
Last Post: SMcNeill
50 minutes ago
» Replies: 0
» Views: 2
Big problem for me.
Forum: General Discussion
Last Post: JRace
5 hours ago
» Replies: 11
» Views: 169
Virtual Arrays
Forum: Site Suggestions
Last Post: hsiangch_ong
10 hours ago
» Replies: 8
» Views: 293
QBJS v0.9.0 - Release
Forum: QBJS, BAM, and Other BASICs
Last Post: hsiangch_ong
10 hours ago
» Replies: 17
» Views: 293
QBJS - ASCII Draw
Forum: QBJS, BAM, and Other BASICs
Last Post: hsiangch_ong
10 hours ago
» Replies: 1
» Views: 35
Very basic key mapping de...
Forum: SMcNeill
Last Post: SMcNeill
11 hours ago
» Replies: 0
» Views: 28
Fun with Ray Casting
Forum: a740g
Last Post: Petr
Yesterday, 08:02 PM
» Replies: 5
» Views: 91
1990's 3D Doom-Like Walls...
Forum: Programs
Last Post: a740g
Yesterday, 06:12 PM
» Replies: 10
» Views: 312
Editor WIP
Forum: bplus
Last Post: aadityap0901
Yesterday, 08:54 AM
» Replies: 12
» Views: 684

 
  Simple Mouse Wheel Scolling
Posted by: Pete - 11-12-2022, 03:52 AM - Forum: Utilities - Replies (9)

Building this as an addition to Sam-Clip

Code: (Select All)
FOR i = 1 TO 50
    REDIM _PRESERVE c$(i)
    c$(i) = LTRIM$(STR$(i))
NEXT
WIDTH 80, 25
idx = -1: GOSUB dsp

DO
    _LIMIT 60
    WHILE _MOUSEINPUT
        mw = mw + _MOUSEWHEEL
    WEND
    IF mw <> oldmw THEN
        adj = SGN(mw - oldmw): mw = 0
        IF idx > 0 AND adj < 0 OR idx <= UBOUND(c$) - (_HEIGHT - 1) AND adj > 0 THEN GOSUB dsp
    END IF
    oldmw = mw
LOOP

dsp:
CLS
IF idx < 0 THEN
    idx = UBOUND(c$) - (_HEIGHT - 2)
    IF idx <= 1 THEN idx = 0
ELSE
    idx = idx + adj
END IF
LOCATE 1, 1
i = idx: j = 0
DO
    i = i + 1
    j = j + 1: LOCATE j, 1
    PRINT c$(i)
LOOP UNTIL CSRLIN = _HEIGHT - 1 OR i = UBOUND(c$)
RETURN

Pete

Print this item

Bug QB64 IDE bug and an SNL moment...
Posted by: Pete - 11-12-2022, 03:09 AM - Forum: General Discussion - Replies (12)

So I start typing away at this itty bitty program when all of a sudden, bam! The crazy IDE eats a piece of my code. Well Jane, I look at the screen and say, "Hey! Why'd you eat a piece of my code?" Now the I-D-E, it can't talk back to me, especially with it's mouth all full of my code, but it just goes to show you, Jane, it's always something...

Try and type then press Enter...

Code: (Select All)
REDIM c$(1000): idx = UBOUND(c$) - _HEIGHT - 125

Sam Samannadanna

Print this item

  Radian Ferris Wheel
Posted by: james2464 - 11-11-2022, 11:58 PM - Forum: Programs - Replies (14)

I was messing around with radians and ended up making this.   Cheers.

Code: (Select All)
'radian ferris wheel
'james2464 - Nov 11 2022 - Radian Ferris Wheel

Screen _NewImage(800, 600, 32)
Const PI = 3.141592654#

Dim c(2) As Long
c(1) = _RGB(50, 255, 100)
c(2) = _RGB(0, 100, 0)

'origin
xx = 400
yy = 300
w = 120 'wheel radius
p = 10 'number of positions
'=====================================================
h = _Hypot(w, 0)
h1 = _Atan2(0, w)
'=====================================================
Do
    _Limit 30
    Cls
    Circle (xx, yy), w, c(2)
    Line (xx, yy)-(xx - 50, yy + w + 40), c(1)
    Line (xx, yy)-(xx + 50, yy + w + 40), c(1)
    Line (xx - 50, yy + w + 40)-(xx + 50, yy + w + 40), c(1)
    h1 = h1 + .002
    If h1 >= PI * 2 Then h1 = 0
    '-------------------------------------------------
    For t = 1 To p
        h2 = h1 + ((PI * 2) / p) * t
        x = Cos(h2) * h: y = Sin(h2) * h
        x2 = Cos(h2) * (h * 1.5): y2 = Sin(h2) * (h * 1.5)
        Line (xx, yy)-(xx + x, yy + y), c(2)
        Line (xx + x - 7, yy + y)-(xx + x + 7, yy + y), c(1)
        Line (xx + x, yy + y)-(xx + x, yy + y + 15), c(1)
        Line (xx + x - 7, yy + y + 15)-(xx + x + 7, yy + y + 25), c(1), B
        Locate 35 * ((yy + y2 + 50) / 600), 99 * ((xx + x2) / 800)
        If h2 >= PI * 2 Then h2 = h2 - PI * 2
        Print Using "#.##"; h2
    Next t
    _Display
Loop

Print this item

  Determing FPS within another FPS .. How?
Posted by: TerryRitchie - 11-11-2022, 10:46 PM - Forum: Help Me! - Replies (21)

I'm finishing up a Pac-Man clone. The game runs at 60 frames per second just like the original. During game play the speed of both Pac-Man and the ghosts are modified by level events and by advancing to higher levels. The speed of these objects is adjusted in 5% increments resulting in a loss of 3 frames per second per 5% loss:

100% = 60FPS (the fastest any object travels)
95%  = 57FPS (60 * .95)
90% = 54FPS (60 * .9)
85% = 51FPS (60 * .85)
...
...
40% = 24FPS (60 * .4) (the slowest any object travels - ghost in the tunnel on level 1)

The usual way I adjust speeds in games is to use MOD and skip frames when the outcome is 0 (zero):

IF Frames MOD 20 THEN ... (every 20th frame will be skipped resulting in 95% or 57FPS)
IF Frames MOD 10 THEN ... (every 10th frame will be skipped resulting in 90% or 54FPS)
IF Frames MOD 5 THEN ... (every 5th frame will be skipped resulting in 80% or 48FPS)
..
.. Etc.

This can also be done in reverse for lower frame rates:

IF Frames MOD 20 = 0 THEN ... (all but three frames will be skipped resulting in 3FPS)
IF Frames MOD 10 = 0 THEN ... (all but six frames will be skipped resulting in 6FPS)
..
.. And so on

My problem is that neither of these methods will yield 85%(51FPS), 60%(36FPS), 55%(33FPS), 45% (27FPS), and 40%(24FPS) all of which I need.

There must be a simple formula I am overlooking to use within a 60FPS loop:

Object.FPS = 24
Frame = 0
DO
    _LIMIT 60
    Frame = Frame + 1
    ( If Object.FPS multiplied by some magical number= current frame then draw it ... formula here)
LOOP

I know I could set up individual frame counters for every object and skip, say, every 9th frame to achieve 85%. However, the original Pac-Man arcade machine had 16K of ROM and 2K of RAM and I can't imagine this was the procedure used with such limited space.

I also realize that I could simply use single precision numbers for x,y and add the percentage ( x! = x! + .85  : 85% for instance ) to get the desired outcome, but again, using single precision values in that era would have been a no-no given the speed over head.

How did those early programmers do this with Integers? Is there a formula I'm overlooking? Help me Obi-Wan math wizards, you are my only hope. I've stared at this for far too long now. My brain hurts.

Print this item

  Calculator in the works (vintage look?)
Posted by: CharlieJV - 11-11-2022, 08:15 PM - Forum: Works in Progress - No Replies

Just for the giggles.  BAM-first version that I'll tweak later, if any tweaks needed, to get working in QB64PE.

I've got the buttons setup (including button color change on hover) and a little sound effect when pressing and depressing a button.

A few hours of work left, so sneak peek:


A much prettier program can be created with QB64PE, but I'm interested in the retro/vintage look.

Print this item

  DAY 006: _KEYCLEAR
Posted by: SMcNeill - 11-11-2022, 04:33 PM - Forum: Keyword of the Day! - Replies (2)

This is, in my opinion, one of those essential keywords that everyone should know and make use of.

What is it?  Keyclear is the simple command which clears the keyboard buffers for us.

How does one use it?  Just call _KEYCLEAR where your program would need to clear the buffers at.

Example of the command:

Code: (Select All)
Print "Kindly play around with your keyboard some, and just press a few random keys for the next few seconds."
_Delay 5
Print "The keys you pressed were:"
Do
    k = _KeyHit
    If k > 0 Then i$ = InKey$: Print k, i$
Loop Until k = 0

Print
Print
Print "Well now, isn't that something?  Your keystrokes were recorded and reported several seconds AFTER you typed them into the keyboard, and affected your program even after your _DELAY!"
Print
Print "So how to prevent that type of issue?"
Print
Print "Captain _KEYCLEAR to the rescue!!!"
Print
Print "Press <ANY KEY> to see the solution in action."
Sleep
_KeyClear
Cls
Print "Kindly play around with your keyboard some, and just press a few random keys for the next few seconds."
_Delay 5
Print "The keys you pressed were:"
_KeyClear: Print "<<Captian _KEYCLEAR to the rescue here!!!>>"
Do
    k = _KeyHit
    If k > 0 Then i$ = InKey$: Print k, i$
Loop Until k = 0


As you can see from the simple example above, _DELAY doesn't stop our program from recording keypresses and adding them into our internal keyboard buffers.   (Neither does SLEEP, or several other "pause" type commands.)  Even though our program appears inactive, it's actually running the keyboard handlers in the background and collecting our last several keystrokes and saving those in a buffer for us.

How could that be bad for us?

Imagine you have a game which pauses execution with a series of set _DELAYs so it can shell out to a video player to play a cutscene for that game.  The user doesn't want to watch the cutscene, so they hit ESC, CTRL-F4, ALT-F4, and multiple other things to try and close the video early, only to find out the video doesn't support those keystrokes...  They watch the cutscene.  Control moves past the delays and back to your program.. Which now tries to process all those keystrokes in the buffer and...  BAM!!  Game closes without saving!!

AAARRRGGHHH!!!   (Who else just threw their controller through the monitor??  Fess up and admit it!  We've all been there. Tongue )

So, what's the easiest way to fix that type of issue?

Simply _KEYCLEAR after playing your cutscene and be done with it.  

Lots of programs have issues by reading unintended keystrokes from the buffers after a pause or delay.  The easiest way to fix those issues is with _KEYCLEAR.  It's your friend -- get to know him well.  Wink

Print this item

  Screen Filler Zakraska
Posted by: DANILIN - 11-11-2022, 01:55 PM - Forum: Programs - Replies (3)

Screen Filler Zakraska

Zakraska.bas program fills screen with dots
by dividing field into a 4x4 section or arbitrarily
and better sides of field of multiples of small sections

Row under label 3:
rotating row checks condition and repeats itself

Dot is placed strictly in an empty place and field is filled in 100%
and there are also counters of points not set and a time counter

Results:
2x2 = 2 seconds & 27ooo repetitions for 25ooo points
4x4 = 5 seconds & 65ooo repetitions for 25ooo points
8x8 = 15 seconds & 95ooo repetitions for 25ooo points
16x16 = 55 seconds & 135ooo repetitions for 25ooo points
32x32 many seconds & many repetitions for 25ooo points

Field is filled in by 100%

[Image: zakraska.gif]

Conclusion: random control is real

Code: (Select All)
w = 640: h = 400: p = w * h: Screen 12 ' zakraska.bas by Danilin
s = 8: a = w / s: b = h / s: Randomize Timer: n = 0: t = Timer

For k = 1 To s ^ 2
    For i = 0 To a - 1
        For j = 0 To b - 1
3 c = Int(Rnd * s) + 1: d = Int(Rnd * s) + 1: If Point(i * s + c, j * s + d) = 4 Then n = n + 1: GoTo 3
            PSet (i * s + c, j * s + d), 4 '+ k Mod 3
        Next: Locate h / 16 + 2, 1: Print n; "points repetition from"; p
        _Title "3akpacka: points repetition " + Str$(n)
Next: _Delay .205: Next: _Delay 1:
Print Timer - t; "seconds for"; s; "x"; s ': GoTo 5

For k = 1 To 2 ' quick
    For i = 0 To w
        For j = 0 To h
            c = Int(Rnd * w) + 1: d = Int(Rnd * h) + 1
            PSet (c, d), 0 '1: '_Delay .00005
Next: Next: Next
_Delay 1':End

5 For k = 1 To s ^ 2 * 2 ' variant
    For i = 0 To a - 1
        For j = 0 To b - 1
            c = Int(Rnd * s) + 1: d = Int(Rnd * s) + 1
            PSet (i * s + c, j * s + d), 0 '+ k Mod 3
Next: Next: _Delay .205: Next: _Delay 1
End


At end dark dots are sprayed without checking for repetitions
in number of points of product of length and width
shaded points remain

Option of canceling shading by increasing number of cycles
all one leaves shaded points

Conclusion: random without control unmanaged

This shading algorithm can show state flags from stripes

Plus there is an idea: exe reads from beginning of basic program parameters
width and height and size of square
and it is possible to paint text screen sign
and colorable quadrats possibly multicolored like a chessboard

TOTAL: absolutely random quickly fill the screen by 100%

[Image: danZELen.gif]

Print this item

  Change font size / Maintain screen size.
Posted by: Pete - 11-11-2022, 01:22 PM - Forum: Utilities - Replies (14)

This is a simple demo for SCREEN 0, but someone could work up a graphics counterpart easily enough...

Code: (Select All)
SCREEN 0
fontsize% = 16
style$ = "monospace"
fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf"
font& = _LOADFONT(fontpath$, fontsize%, style$)
_FONT font&
ww = 600: wh = 350
WIDTH ww \ _FONTWIDTH, wh \ _FONTHEIGHT
PALETTE 7, 63: COLOR 0, 7: CLS
_FONT font&
_SCREENMOVE 0, 0
PRINT "Press ctrl + to increase font size or ctrl - to decrease."
DO
    _LIMIT 30
    c = _KEYHIT
    IF c THEN
        SELECT CASE c
            CASE -189
                IF fontsize% > 9 THEN fontsize% = fontsize% - 2
            CASE -187
                IF fontsize% < 31 THEN fontsize% = fontsize% + 2
        END SELECT
    END IF
    IF oldf% AND fontsize% <> oldf% THEN
        _SCREENHIDE: _FONT 8
        _FREEFONT font&
        font& = _LOADFONT(fontpath$, fontsize%, style$)
        _FONT font&
        _SCREENSHOW
        fw% = _FONTWIDTH: fh% = _FONTHEIGHT
        WIDTH ww / fw%, wh / fh%
        PALETTE 7, 63: COLOR 0, 7: CLS
        _FONT font&
        _SCREENMOVE 0, 0
        PRINT "Font size changed to:"; fontsize%, "width ="; _WIDTH
        _KEYCLEAR
    END IF
    oldf% = fontsize%
LOOP

It's a bit of a trick to capture ctrl combos with some keys like + and -. I used inp(96) as it is one of the easiest. The actual trigger happens when the + or - key is released, and nothing registers when either is pressed.

The routine can be expanded to use $RESIZE:ON but the user would need to decide what changes as the screen size changes. Probably the most popular use would be a fixed number of characters across the screen, so when resize increases the widt, the width statement adjusts to the size, and the font size adjusts to as close to the same number of characters across the screen. To do a perfect operation would also require the development of a margin system.

EDIT: Addressed memory leak, thanks Steve!

Pete

Print this item

Information I have issues with Github
Posted by: mnrvovrfc - 11-10-2022, 11:35 PM - Forum: General Discussion - No Replies

I cannot create an account with Github because it goes against my pride, and some web browsers cannot handle well content of that site. Therefore this very bored user will bore you further with creating a thread just to offer even more opinions that might not be wanted...

If you want to "visit" the issue just drop into the address blank of your web browser:

s://github.com/QB64-Phoenix-Edition/QB64pe/issues/NUMBER

Purposely beheaded so it's not "clickable," and "NUMBER" should be the number shown after pound-sign below.

#233
I support this; just make release (middle) number padded with zero but not make it obvious to the programmer because some code exists that would test for "0.5.0", for "3.2.0" and it's only the beginning. For "3.2.0" case "internally" test for "3.02.0". In fact do it for "03.02.00" in case this programming system could reach version 10!

#219
One fault is that some users like "small" terminal windows, while a typical dialog could require at least 100 characters across. It would be impossible to predict when an user maliciously resizes that window to smaller size to see if the user program crashes. Would have to stick to low-bit characters to draw the dialog. I've discovered "ANSI" codes for coloring not reliable on some "terminal emulators" of Linux distros. This was from using a library called "Lua-term" which allowed simple output to the terminal with coloring and positioning, by using Lua code.

#212
Have "_RESULT" keyword, a lot like Pascal/Delphi, as alternative to "_RETVAL". I resist "EXIT FUNCTION" more than "EXIT SUB", I think it's a retarded way to break out of a function early, and there is too much code already which keeps using function name on LHS which is bad form. This new keyword should put an end to it at least for new programs.

#211
I support this. However, instead of lame-ass keywords from Visual Basic, as alternative how about a compiler option for it? I would like the short-circuit evaluation to be absolute if I choose.

#206
(To the one who opened this issue: ) You would have to change your way of thinking about this. If the concept of MAK file is insisted on you must rearrange your "project" so there is only one main program, and the other BAS files then become BI to be included into the main program. Each "main program" in "slave" BAS files should be put into their own "SUB's" to be called in a desired order by the only true main program. Otherwise each BAS file is destined to be compiled into a separate executable file, without relation to one another. This could be a pain because "CHAIN" and "COMMON SHARED" weren't meant to be used in 32-bit and 64-bit environment where security has some emphasis.

#187
On the Linux side you guys might want to talk to "angros47" that Italian guy who did an audio/MIDI playback library for Freebasic.

#30
This is one of my longest requests.

Print this item

  Karnaugh maps?
Posted by: madscijr - 11-10-2022, 10:02 PM - Forum: General Discussion - No Replies

"A Karnaugh map reduces the need for extensive calculations by taking advantage of humans' pattern-recognition capability. It also permits the rapid identification and elimination of potential race conditions."

I was not familiar with this, I only happened to see a news article about its inventor, who died just this week. 

But it looks like just the kind of thing the folks here might find interesting!

Print this item