Welcome, Guest |
You have to register before you can post on our site.
|
Latest Threads |
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 764
|
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
|
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
|
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,034
|
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,262
|
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 316
|
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
|
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
|
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
|
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155
|
|
|
DAY 005: ERDEV$ |
Posted by: SMcNeill - 11-10-2022, 06:04 AM - Forum: Keyword of the Day!
- Replies (7)
|
|
Umm...
Our first mystery command! I honestly have no idea what it is, where it came from, who added it to the keyword list or in the IDE, or what the heck it's supposed to do for us. Checking the wiki, I found no entry for it..
Our word of the day is based off the syntax highlighter in the IDE, and for some reason there's both an ERDEV and a ERDEV$ which get highlighted as a keyword.
Anyone with any idea of what this is, where it comes from, and when/how we'd make use of it, kindly feel free to speak up on it. As it is, I'm afraid that this time even the mighty Steve has to hang his head in shame -- I have no idea what the heck this beast is!!
Code: (Select All) Print erdev$
Print erdev
The above works. I don't see where it does anything but print a blank line and then a zero, but it *does* highlight both of those as keywords.
Let's see who can solve the mystery of this one for us!
|
|
|
Scientific Notation |
Posted by: james2464 - 11-10-2022, 04:27 AM - Forum: Help Me!
- Replies (13)
|
|
I'm curious about why this shows up so often as the answer for a number that is nearly zero.
For example,
a = 1 / 256
Print a
(I get 3.90625E-03)
Is this just a matter of using an appropriate variable type?
|
|
|
For Pete -- Keeping a window topmost and active |
Posted by: SMcNeill - 11-10-2022, 02:15 AM - Forum: Help Me!
- Replies (3)
|
|
So this is what I've came up with, and it works...
Code: (Select All) 'public domain
Const SWP_NOSIZE = &H0001 'ignores cx and cy size parameters
Const SWP_NOMOVE = &H0002 'ignores x and y position parameters
Const SWP_NOZORDER = &H0004 'keeps z order and ignores hWndInsertAfter parameter
Const SWP_NOREDRAW = &H0008 'does not redraw window changes
Const SWP_NOACTIVATE = &H0010 'does not activate window
Const SWP_FRAMECHANGED = &H0020
Const SWP_SHOWWINDOW = &H0040
Const SWP_HIDEWINDOW = &H0080
Const SWP_NOCOPYBITS = &H0100
Const SWP_NOOWNERZORDER = &H0200
Const SWP_NOSENDCHANGING = &H0400
Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Const SWP_DEFERERASE = &H2000
Const SWP_ASYNCWINDOWPOS = &H4000
Const HWND_TOP = 0 'window at top of z order no focus
Const HWND_BOTTOM = 1 'window at bottom of z order no focus
Const HWND_TOPMOST = -1 'window above all others no focus unless active
Const HWND_NOTOPMOST = -2 'window below active no focus
Declare Dynamic Library "user32"
' Function FindWindowA%& (ByVal lpClassName%&, Byval lpWindowName%&)
Function SetWindowPos& (ByVal hWnd%&, Byval hWndInsertAfter%&, Byval X&, Byval Y&, Byval cx&, Byval cy&, Byval uFlags~&)
Function GetForegroundWindow%&
Function SetForegroundWindow%& (ByVal hwnd As _Offset) 'set foreground window process(focus)
End Declare
Declare Dynamic Library "kernel32"
Function GetLastError~& ()
End Declare
Dim hWnd As _Offset
_Title "This Window will always be on Top" 'any title
_Delay .5 'delay allows user to click focus on other windows
hWnd = _WindowHandle 'FindWindowA(0, _OFFSET(t))
If 0 = SetWindowPos(hWnd, HWND_TOPMOST, 200, 200, 0, 0, SWP_NOSIZE Or SWP_NOACTIVATE) Then
Print "SetWindowPos failed. 0x" + LCase$(Hex$(GetLastError))
End If
Do
Cls
x%& = GetForegroundWindow%& 'find currently focused process handle
Locate 3, 1
Print "Program handle:"; hWnd; "Focus handle:"; x%&
If x%& <> hWnd Then
Print "Not Active"
junk%& = SetForegroundWindow(hWnd)
Else
Print "Active"
End If
_Limit 30
Loop Until _KeyDown(27)
Now, the problem that I'm having is that this works -- but it only works *ONCE*. Start it up, click off to a different window, it jerks focus back to itself as expected. Click to a different window again, and... it detects it's not active, but it won't jerk focus back to itself like it's supposed to.
Any of you windows API gurus out there see something obvious that I'm missing here? (@Spriggsy) Why's this work once and then decide, "Nah! I don't wanna do that again??" Any ideas at all on this one would be appreciated.
|
|
|
BAM _Trees! |
Posted by: James D Jarvis - 11-09-2022, 11:57 PM - Forum: Programs
- No Replies
|
|
Just some digital doodling. Generate a simple forest landscape of leafy trees.
Code: (Select All) 'BAM_Trees
'quick random leafy random trees
'why is it called BAM-Trees? Because the draw_leaves routine is a variant from a sample at:
' https://sites.google.com/view/basicanywheremachine
'
'press any key to generate a new image
'press <esc> to quit
'
Randomize Timer
Screen _NewImage(1100, 600, 32)
_Title "BAM_Trees!"
Do
Cls
hrz = Int(Rnd * 30 + 120)
Line (0, 0)-(_Width, hrz), _RGB32(Rnd * 10, Rnd * 10, Rnd * 200 + 40), BF
Line (0, hrz)-(_Width, _Height), _RGB32(Rnd * 200 + 40, Rnd * 200 + 40, Rnd * 10), BF
For r = 1 To 4
treetopx = 10: treetopy = r * 120
numtinrow = Int(Rnd * 13 + 6)
For b = 1 To numtinrow
treetopx = treetopx + Int(Rnd * 5 + 5) * (10 * 25 / numtinrow): treetopy = Int(Rnd * 100 + r * 100)
draw_trunk treetopx, treetopy
draw_leaves treetopx, treetopy, Int(Rnd * 20) + 20, Rnd * 5 + 6, Int(Rnd * 360)
Next b
Next r
Do
_Limit 30
kk$ = InKey$
Loop Until kk$ <> ""
Loop Until kk$ = Chr$(27)
Sub draw_leaves (x%, y%, length%, line_count%, start_angle%)
angle_increment% = 360 / line_count%
my_color~& = _RGB32(40, Rnd * (256 - (y% / 6)), 60)
For i% = 0 To (line_count% - 1)
_Limit 40000
Draw "bm " + Str$(x%) + "," + Str$(y%)
Draw "C" + Str$(my_color~&) + " TA" + Str$(start_angle% + angle_increment% * i%) + " r" + Str$(length%)
If length% > (Rnd * 11.4 + 3.5) Then
Call draw_leaves(Point(0), Point(1), Int(length% / (1.125 + Rnd * 2.25)), line_count%, start_angle% + angle_increment% * (i% + 1))
End If
Next
End Sub
Sub draw_trunk (tx, ty)
tw = Int(Rnd * 25 + 10)
For t = 1 To tw
trunk~& = _RGB32(Rnd * 50 + 20, Rnd * 50 + 50, Rnd * 20)
Line (tx, ty)-(tx + Rnd * (8 * tw / 30), ty + 60 + Rnd * 30), trunk~&, BF
Next t
End Sub
|
|
|
What are your best and worst coding traits? |
Posted by: Pete - 11-09-2022, 06:29 PM - Forum: General Discussion
- Replies (11)
|
|
Well let's say maybe list 3 to 5, or a few, whatever. No order needed, unless ranking is one of your positive traits!
For me, it would be tenacity, interest in the projects I'm involved with, drive, mechanics, and somewhat creativity. What I consider to be negative traits would be typing speed, about half that of a pro, being impatient with documentation, organizing works in folders, variable naming, and consistency (I like to do projects differently.) One that I used to love but have been missing over the years, the ability to keep a program straight in my head, as well as on the screen. That was cool.
Pete
|
|
|
BAM Features Set: "Powerwash", "BAM System Update", "TW System Update" |
Posted by: CharlieJV - 11-09-2022, 06:23 PM - Forum: QBJS, BAM, and Other BASICs
- Replies (1)
|
|
Although there's no install, BASIC Anywhere Machine is intended to be "download and make it your own", store it where you want, use it as you want, etc.
There is a bunch of stuff in BAM that makes it what it is and makes it work.
But there is a bunch of stuff in BAM that is content created in it (BASIC programs, tasks, and whatever else that is created as part of using BAM.)
As part of making BAM your own (any version of it that exists), you ought to have a way to remove the fluff and be left with nothing else but the stuff that makes BAM work.
Enter the pending "Powerwash" feature.
Whatever version of BAM you nab that has that feature, click the "Factory Refresh" (or Factory Reset?) "Powerwash", and all of the fluff is purged. You are left with nothing but a clean BASIC Anywhere Machine, ready to go for your new project(s).
But once you've made it your own (i.e. powerwashed and have your programs and tasks/etc. in there), you need to be able to upgrade it when I've rolled out a new version of BAM with some cool new stuff and fixes.
Enter the pending "BAM System Update" process.
Just open up the new version of BAM, and open your BAM instance, then drag and drop the package of "architectural stuff" from the new version of BAM to your BAM instance, and you are upgraded.
Now, what if BASIC Anywhere Machine has not kept to date with the latest version of TW (TiddlyWiki), so BAM has fallen a bit behind, but you for whatever reason want your BAM version to be on the latest version of TW?
Enter the already existing "TW System Update" service.
As per the existing Upgrading process, we just drag a BAM instance into the online upgrader and download the result of the process: everything that makes BAM work is now in a new version of TW. Well, as long as the latest version of TW has done something to break backward compatibility ...
Something like that ...
|
|
|
_NEWIMAGE() should be fixed to always take 3 parms |
Posted by: mnrvovrfc - 11-09-2022, 02:05 PM - Forum: General Discussion
- Replies (10)
|
|
If two parameters are given to "_NEWIMAGE()" and any graphics command is called (in the program below "PSET") the program gives an error box which, if not taken seriously, the program hangs for a moment then terminates, writing on the terminal "killed". The source code was something I found from the "dot-com" forum that was meant for "QBJS" and not on Linux.
Code: (Select All) ''by "mikesharpe" from qb64-dot-com forum
dim shared pi, p, q, d, z0, t, f, sw, sh
sw = 800
sh = 600
d = 700
z0 = 1500
pi = 4*atn(1)
screen _newimage(sw, sh, 12)
sv = 2*pi/30
su = 2*pi/10
for t = 0 to 2*pi step 0.01
cls
u = 0
for v=0 to 2*pi+sv step sv
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
pset (p, q)
for u=0 to 2*pi+su step su
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line -(p, q)
next
next
for u=0 to 2*pi+su step su
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
pset (p, q), _rgb(255,0,0)
for v=0 to 2*pi+sv step sv
x = cos(u)
y = sin(u)
z = cos(v)
w = sin(v)
proj x, y, z, w
line -(p, q), _rgb(255,0,0)
next
next
_display
_limit 50
next
_autodisplay
system
sub proj(x, y, z, w)
xx = x
yy = y*cos(t) - w*sin(t)
zz = z
ww = y*sin(t) + w*cos(t)
d2 = 3
w0 = 3
xx = xx*d2/(w0 + ww)
yy = yy*d2/(w0 + ww)
zz = zz*d2/(w0 + ww)
xxx = xx*cos(t) - zz*sin(t)
zzz = xx*sin(t) + zz*cos(t)
xx = xxx
zz = zzz
a = pi/12
b = pi/3
xxx = xx*cos(a) - yy*sin(a)
yyy = xx*sin(a) + yy*cos(a)
xx = xxx
yy = yyy
yyy = yy*cos(b) - zz*sin(b)
zzz = yy*sin(b) + zz*cos(b)
yy = yyy
zz = zzz
xx = 200*xx
yy = 200*yy
zz = 200*zz
p = sw/2 + 2*xx*d/(yy + z0)
q = sh/2 - 2*zz*d/(yy + z0)
end sub
My other addition to the original program was "_DISPLAY" just above "_LIMIT" so this was more tolerable.
|
|
|
Googly Eyes looking around screen |
Posted by: Dav - 11-09-2022, 01:52 PM - Forum: Programs
- Replies (13)
|
|
Small demo of Googly eyes drifting around the screen. The eyes look toward the direction they are moving. Just a small demo that may help some learn to use _PUTIMAGE and move images around the screen in different ways. I tried to comment more than usual.
- Dav
Code: (Select All) '==============
'GOOGLYEYES.BAS
'==============
'Eyes drift around space, looking in direction they go.
'Shows how to create images off screen and use _PUTIMAGE.
'Demo also shows how to move images in interesting ways.
'Coded by Dav, NOV/2022
'=== First, create 4 eye images to use....
'=== Create image of eyes looking left
eyeleft& = _NEWIMAGE(230, 200, 32)
_DEST eyeleft& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255 'left eye
ball 30, 50, 20, 0, 0, 32 'left pupil
ball 150, 50, 50, 255, 255, 255 'right eye
ball 130, 50, 20, 0, 0, 32 'right pupil
'=== Create image of eyes looking right
eyeright& = _NEWIMAGE(230, 200, 32)
_DEST eyeright& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 70, 50, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 170, 50, 20, 0, 0, 32
'=== Create an image of eyes looking up
eyeup& = _NEWIMAGE(230, 200, 32)
_DEST eyeup& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 30, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 30, 20, 0, 0, 32
'=== Create an image of eyes looking down
eyedown& = _NEWIMAGE(230, 200, 32)
_DEST eyedown& 'point to above image so we can draw to it
ball 50, 50, 50, 255, 255, 255
ball 50, 70, 20, 0, 0, 32
ball 150, 50, 50, 255, 255, 255
ball 150, 70, 20, 0, 0, 32
'=== Now we point to main screen
_DEST 0 'set destination to draw to main screen
SCREEN _NEWIMAGE(800, 600, 32) 'main screen size
RANDOMIZE TIMER 'do this so the RND call is different everytime
Eyes = 100 'the number of eyes on screen
EyeSizeMax = 225 'largest size eyes can be
DIM EyeX(Eyes), EyeY(Eyes) 'x/y position of the eye
DIM EyeSize(Eyes) ' size of eye
DIM EyeGrowth(Eyes) 'eye growing or shrinking on screen
DIM EyeDrift(Eyes) 'direction eye drifts across screen
DIM EyeDriftSpeed(Eyes) 'speed for the drift
'generate eye values
FOR d = 1 TO Eyes
EyeX(d) = RND * _WIDTH 'make random x position
EyeY(d) = RND * _HEIGHT 'make random y position
EyeSize(d) = (RND * EyeSizeMax) 'random eye size, up to EyeSizeMax
EyeGrowth(d) = INT(RND * 2) 'make way eye size is changing, 0=shrinking, 1=growing
EyeDrift(d) = INT(RND * 4) 'make random direction a eye can drift (4 different ways)
EyeDriftSpeed(d) = INT(RND * 3) + 2 'speed eyes will be drifting
NEXT
DO
CLS , _RGB(0, 0, 32) 'clear screen to dark blue
'step through each eye
FOR d = 1 TO Eyes
'if eye is shrinking, subtract eyesize, else add to it
IF EyeGrowth(d) = 0 THEN
EyeSize(d) = EyeSize(d) - 1
ELSE
EyeSize(d) = EyeSize(d) + 1
END IF
'if eyesize reaches max size, switch growth to 0 start shrinking instead
IF EyeSize(d) >= EyeSizeMax THEN EyeGrowth(d) = 0
'if if reaches smallest eyesize, switch growth to 1 to start growing now
IF EyeSize(d) <= 20 THEN EyeGrowth(d) = 1
'drift eye in 1 of 4 directions we generated, and do +x,-x,+y,-y to it.
IF EyeDrift(d) = 0 THEN EyeX(d) = EyeX(d) + EyeDriftSpeed(d) 'drift right
IF EyeDrift(d) = 1 THEN EyeX(d) = EyeX(d) - EyeDriftSpeed(d) 'drift left
IF EyeDrift(d) = 2 THEN EyeY(d) = EyeY(d) + EyeDriftSpeed(d) 'drift down
IF EyeDrift(d) = 3 THEN EyeY(d) = EyeY(d) - EyeDriftSpeed(d) 'drift up
'this creates the shakiness. randomly adjust x/y positions by +/-2 each step
IF INT(RND * 2) = 0 THEN EyeX(d) = EyeX(d) + 2 ELSE EyeX(d) = EyeX(d) - 2
IF INT(RND * 2) = 0 THEN EyeY(d) = EyeY(d) + 2 ELSE EyeY(d) = EyeY(d) - 2
'below handles if eye goes off screen, let it dissapear completely
IF EyeX(d) > _WIDTH + EyeSize(d) THEN EyeX(d) = -EyeSize(d)
IF EyeX(d) < -EyeSize(d) THEN EyeX(d) = _WIDTH + EyeSize(d)
IF EyeY(d) > _HEIGHT + EyeSize(d) THEN EyeY(d) = -EyeSize(d)
IF EyeY(d) < -EyeSize(d) THEN EyeY(d) = _HEIGHT + EyeSize(d)
'drift eye in 1 of 4 directions we generated, and +x,-x,+y,-y to it.
IF EyeDrift(d) = 0 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeright& 'drift right
IF EyeDrift(d) = 1 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeleft& 'drift left
IF EyeDrift(d) = 2 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyedown& 'drift down
IF EyeDrift(d) = 3 THEN _PUTIMAGE (EyeX(d), EyeY(d))-(EyeX(d) + EyeSize(d), EyeY(d) + EyeSize(d)), eyeup& 'drift up
'get new random direction change
SELECT CASE INT(RND * 300)
CASE 1: EyeDrift(d) = 0: EyeDriftSpeed(d) = INT(RND * 3) + 2
CASE 2: EyeDrift(d) = 1: EyeDriftSpeed(d) = INT(RND * 3) + 2
CASE 3: EyeDrift(d) = 2: EyeDriftSpeed(d) = INT(RND * 3) + 2
CASE 4: EyeDrift(d) = 3: EyeDriftSpeed(d) = INT(RND * 3) + 2
END SELECT
NEXT
_DISPLAY
_LIMIT 30
LOOP
SUB ball (x, y, size, r&, g&, b&)
'small sub that draws a filled ball with given color.
FOR s = 1 TO size STEP .4
CIRCLE (x, y), s, _RGB(r&, g&, b&)
r& = r& - 1: g& = g& - 1: b& = b& - 1
NEXT
END SUB
|
|
|
DAY 004: _WINDOWHASFOCUS |
Posted by: SMcNeill - 11-09-2022, 01:26 PM - Forum: Keyword of the Day!
- Replies (9)
|
|
A keyword which simply tells you if your program is topmost and has focus in your OS. For those who don't understand what I'm talking about with topmost, let me give you a simple example:
1) Open your file explorer and click the qb64pe icon and start up a fresh instance of the IDE. It'll pop up on your screen on top of any other windows which you may have open -- your browser, the file explorer, and whatever else was open on your desktop. At this point, it's the *topmost* program on your screen, and it has focus. When you hit keys on the keyboard, you'll be typing into the IDE and not your web browser.
2) Now, click on your file explorer once more and open notepad. Start typing with the keyboard and watch as the letters appear in the notepad text area, rather than in QB64's IDE. Notepad is now the topmost program and has focus, so QB64 has lost it.
Now let's say you have a program that you might want to respond differently, regarding whether it has focus or not. How do you detect whether your program is the focus of the user, or not?
With _WINDOWHASFOCUS. (Well, at least for Windows and Linux users. The keyword is not yet supported on MAC, according to our wiki currently.)
Example from the wiki:
DO
IF _WINDOWHASFOCUS THEN
COLOR 15, 6
CLS
PRINT "*** Hi there! ***"
ELSE
COLOR 0, 7
CLS
PRINT "(ain't nobody looking...)"
END IF
_DISPLAY
_LIMIT 30
LOOP
A simple example, where the program will PRINT "*** Hi there! ***" on the screen if the window has focus, and will print "(ain't nobody looking...)" when it doesn't.
QB64 Wiki Entry: _WINDOWHASFOCUS - QB64 Phoenix Edition Wiki
|
|
|
|