foo = CreateToggle(100, 100) 'create a name for the toggle and decide where to place it on the screen
fred = CreateToggle(300, 300) 'a second toggle to make certain we work with multiples well Do Cls
MBS = MouseButtonStatus'get the mouse status once here, to be used anywhere else in our processes ProcessToggles MBS 'check to see if we've clicked on the active toggles DisplayToggles'display them after any change Print"Toggle foo's value:"; GetToggleValue(foo) 'we can get the value back here Print"Toggle fred's value:"; GetToggleValue(fred) 'we can get the value back here _Limit30 _Display Loop Until_KeyDown(27) FreeToggle0'free all toggles for use later System
SubDisplayToggles DimAsLong i, x, y, state, w, t, cx, cy DimAsLong DC, BGC
DC = _DefaultColor: BGC = _BackgroundColor
w = 25: t = 12 Color White, 0 For i = 1To TogglesInUse If Toggles(i).active Then
x = Toggles(i).x
y = Toggles(i).y
state = Toggles(i).state 'draw the whole toggle
cx = x + 2 * w: cy = y + t Line (x, y)-Step(100, 24), DarkGray, BF If state Then'the toggle has been clicked to the right (ON by default) EllipseFill cx + w, cy, w, t, Green _PrintString (cx + w - 8, cy - 8), "ON" Else EllipseFill cx - w, cy, w, t, Red _PrintString (cx - w - 12, cy - 8), "OFF" End If End If Next Color DC, BGC End Sub
FunctionCreateToggle (x AsLong, y AsLong) DimAsLong i For i = 1To TogglesInUse If Toggles(i).active = 0Then
Toggles(i).active = -1
Toggles(i).x = x
Toggles(i).y = y CreateToggle = i Exit Function End If Next
TogglesInUse = i
Toggles(i).active = -1
Toggles(i).x = x
Toggles(i).y = y CreateToggle = i End Function
FunctionMouseButtonStatus%'Mouse Button Status Static StartTimer As_Float Static ButtonDown AsInteger Const ClickLimit## = 0.2'Less than 1/4th of a second to down, up a key to count as a CLICK. ' Down longer counts as a HOLD event. 'Shared Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY DimAsLong tempMBS, BD While_MouseInput'Remark out this block, if mouse main input/clear is going to be handled manually in main program. Select CaseSgn(_MouseWheel) Case1: tempMBS = tempMBS Or512 Case-1: tempMBS = tempMBS Or1024 End Select Wend
For a program which I'm working on which has several settings which the user can toggle on and off, and which I thought I'd share in case anyone needed or was interested in this.
Note that the above is perfectly valid. In fact, Option _Explict won't even toss us an error saying "Undeclared Variable" here. It passes the IDE inspection, compiles just peachy fine, and is about the best example of "How NOT to Program" that I can think of.
Why the heck does BASIC allow this type of junk to ever pass muster to even begin with?!
And it that doesn't boggle your brain any, take a look at the extended version of this mess:
At no point did we declare a variable as x!, yet parameter x defaults to SINGLE, so Option Explicit happily accepts it as being declared as SINGLE, which makes x! valid -- except we can't reference it as X as X is now a local LONG, which is not to be confused with parameterX, which is SINGLE and can be referenced by x! but not x......
Line drawing using Rotoline a routine made possible by RotoZoom
Code: (Select All)
'RotoLine Demo
'by James D, Jarvis October 11,2023
'a program that demonstrates how to use rotozoom and related commands to draw lines thicker than one pixel
Sub rpoly (cx As Single, cy As Single, rad As Single, sides As Integer, rtn As Single, thk As Single, klr As _Unsigned Long)
'use build and draw an equilateral polygon of radius rad from cx,cy with sides # os sides
'start with a rotation of rtn , draw theshape with a line of thickness thk in color klr
Dim a(sides + 1, 2)
rstep = 360 / sides
pmax = sides + 1
r = rtn
'build the points gor polygon perimieter an store in array a()
For p = 1 To pmax
a(p, 1) = cx + (rad * Cos(0.01745329 * (r)))
a(p, 2) = cy + (rad * Sin(0.01745329 * (r)))
r = r + rstep
Next p
rline a(), thk, _RGB32(0, 100, 200)
End Sub
Sub rpolyFT (cx As Single, cy As Single, rad As Single, sides As Integer, rtn As Single, thk As Single, lklr As _Unsigned Long, fklr As _Unsigned Long)
'use build and draw an equilateral polygon of radius rad from cx,cy with sides # os sides
'start with a rotation of rtn , draw theshape with a line of thickness thk in color klr
Dim a(sides + 1, 2)
rstep = 360 / sides
pmax = sides + 1
r = rtn
'build the points gor polygon perimieter an store in array a()
For p = 1 To pmax
a(p, 1) = cx + (rad * Cos(0.01745329 * (r)))
a(p, 2) = cy + (rad * Sin(0.01745329 * (r)))
r = r + rstep
Next p
'draw the fill triangles
For p = 1 To sides - 1
ftri cx, cy, a(p, 1), a(p, 2), a(p + 1, 1), a(p + 1, 2), fklr
Next p
ftri cx, cy, a(sides, 1), a(sides, 2), a(1, 1), a(1, 2), fklr
'draw the perimeter if lklr <> 0
If lklr <> 0 Then rline a(), thk, _RGB32(0, 100, 200)
End Sub
Sub rline (la(), thk As Single, klr As _Unsigned Long)
'draw a line described in an array
p = UBound(la)
For n = 1 To p - 1
RotoLineEC la(n, 1), la(n, 2), la(n + 1, 1), la(n + 1, 2), thk, klr
Next n
End Sub
Sub RotoLineEC (x1 As Single, y1 As Single, x2 As Single, y2 As Single, thk As Single, klr As _Unsigned Long)
'use rotozoom to draw a line of thickness thk of color klr from x1,y1 to x2,y2
'uses filled circles to make endcaps for the lines
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
o& = _Dest
_Dest dot&
PSet (0, 0), klr
_Dest o&
rtn = DegTo!(x1, y1, x2, y2)
lnth = Sqr(Abs(x2 - x1) * Abs(x2 - x1) + Abs(y2 - y1) * Abs(y2 - y1))
RotoZoom23d cx, cy, dot&, lnth, thk, rtn
fcirc x1, y1, thk / 2, klr
fcirc x2, y2, thk / 2, klr
End Sub
Sub RotoLine (x1 As Single, y1 As Single, x2 As Single, y2 As Single, thk As Single, klr As _Unsigned Long)
'use rotozoom to draw a line of thickness thk of color klr from x1,y1 to x2,y2
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
o& = _Dest
_Dest dot&
PSet (0, 0), klr
_Dest o&
rtn = DegTo!(x1, y1, x2, y2)
lnth = Sqr(Abs(x2 - x1) * Abs(x2 - x1) + Abs(y2 - y1) * Abs(y2 - y1))
RotoZoom23d cx, cy, dot&, lnth, thk, rtn
End Sub
Sub RotoZoom23d (centerX As Single, centerY As Single, Image As Long, xScale As Single, yScale As Single, Rotation As Single)
'rotate an image with Rotation defined in units of degrees, 0 is along x axis to the right gogin clockwise
Dim px(3) As Single: Dim py(3) As Single
Wi& = _Width(Image&): Hi& = _Height(Image&)
W& = Wi& / 2 * xScale
H& = Hi& / 2 * yScale
px(0) = -W&: py(0) = -H&: px(1) = -W&: py(1) = H&
px(2) = W&: py(2) = H&: px(3) = W&: py(3) = -H&
sinr! = Sin(-0.01745329 * Rotation): cosr! = Cos(-0.01745329 * Rotation)
For i& = 0 To 3
x2& = (px(i&) * cosr! + sinr! * py(i&)) + centerX: y2& = (py(i&) * cosr! - px(i&) * sinr!) + centerY
px(i&) = x2&: py(i&) = y2&
Next
_MapTriangle (0, 0)-(0, Hi& - 1)-(Wi& - 1, Hi& - 1), Image& To(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
_MapTriangle (0, 0)-(Wi& - 1, 0)-(Wi& - 1, Hi& - 1), Image& To(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
End Sub
Function DegTo! (x1, y1, x2, y2)
' returns an angle in degrees from point x1,y1 to point x2,y2
DegTo! = _Atan2((y2 - y1), (x2 - x1)) / 0.01745329
End Function
Sub fcirc (CX As Single, CY As Single, 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), klr: 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
Sub ftri (xx1, yy1, xx2, yy2, xx3, yy3, c As _Unsigned Long)
'Andy Amaya's triangle fill modified for QB64
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As Single
Dim slope1 As Single, slope2 As Single, length As Single, x As Single, lastx%, y As Single
Dim slope3 As Single
'make copies before swapping
x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
'triangle coordinates must be ordered: where x1 < x2 < x3
If x2 < x1 Then Swap x1, x2: Swap y1, y2
If x3 < x1 Then Swap x1, x3: Swap y1, y3
If x3 < x2 Then Swap x2, x3: Swap y2, y3
If x1 <> x3 Then slope1 = (y3 - y1) / (x3 - x1)
'draw the first half of the triangle
length = x2 - x1
If length <> 0 Then
slope2 = (y2 - y1) / length
For x = 0 To length
Line (Int(x + x1), Int(x * slope1 + y1))-(Int(x + x1), Int(x * slope2 + y1)), c
lastx% = Int(x + x1)
Next
End If
'draw the second half of the triangle
y = length * slope1 + y1: length = x3 - x2
If length <> 0 Then
slope3 = (y3 - y2) / length
For x = 0 To length
If Int(x + x2) <> lastx% Then
Line (Int(x + x2), Int(x * slope1 + y))-(Int(x + x2), Int(x * slope3 + y2)), c
End If
Next
End If
End Sub
FUNCTIONWindowWidth WindowWidth = glutGet(102) '102 is the const value of GLUT_WINDOW_WIDTH END FUNCTION
FUNCTIONWindowHeight WindowHeight = glutGet(103) '103 is the const value of GLUT_WINDOW_HEIGHT END FUNCTION
It's been a long time since I've had such a simple concept cause me such a large headache, so I can honestly say that this is one of the code snippets that I'm most proud of right now.
What's the basic concept here?
Just make a resizable screen that refuses to go beyond the minimal/maximal boundaries set for it.
I'm not going to go into all the issues I ran into coming up with this, but if you want a nice challenge, try it for yourself -- Just write a simple little program with $RESIZE, where you can limit the minimum and maximum size that the user can drag that window and make it.
The only solution I found to this issue was to completely sidestep out of QB64 itself and step back over into glut, and make it do all the heavy lifting and work for us.
If one of you guys can come up with a native way to do this reliably with just QB64PE code, I'd love to see it. I've broken my brain trying to get things to work as intended here. (And I'm still not 110% certain that it still isn't going to break under some odd condition which I'm just not finding with my own testing at the moment!)
A friend asked me to help him out how making a notebook paper screen that would work for various screen sizes and font size. He was trying to use an image&, but couldn't get the LOCATE/PRINT to fit in the paper lines. I suggested this way to him, using _FONTWIDTH/_FONTHEIGHT to scale drawing text LINEs instead. Thought I'd share it here because it may be something others may want. I commented this code more than usual to help my friend learn. This SUB draws a yellow legal pad paper, but you can make other papers styles fairly easy.
- Dav
Code: (Select All)
'yellowpaper.bas
'by Dav, OCT/2023
SCREEN _NEWIMAGE(800, 600, 32)
'Here's where you can load another font you want to use....
'fnt& = _LOADFONT("lucon.ttf", 24, "monospace")
'_FONT fnt&
'Call the SUB, with your title$ message
YellowPaper "John's QB64-PE Code Notebook"
'You need to call below so PRINTing text doesn't destroy background.
_PRINTMODE _KEEPBACKGROUND
'=== show some sample information....
COLOR _RGB(64, 64, 64)
FOR y = 5 TO 16
LOCATE y, 2: PRINT DATE$;
LOCATE , 16: PRINT "Random Data ="; RND; RN;
NEXT: PRINT
'Use location 2 to print in left column, 16 for printing in the text lines.
PRINT
LOCATE , 16: PRINT "This is another line."
PRINT
LOCATE , 2: PRINT "Tuesday:"
LOCATE , 16: PRINT "Dear diary, today I wrote this...."
SLEEP
SUB YellowPaper (title$)
'This SUB draws yellow notebook paper, scaled to fit current font settings.
'It also prints and centers title$ in the top title area.
fw = _FONTWIDTH: fh = _FONTHEIGHT 'get current font width/height settings
'(the fw & fh we will use to calculate LINE drawing so they line up right with PRINT)
CLS , _RGB(255, 245, 154) 'clear screen to yellow color
'draw the two vertical brown lines, to make column/text area
LINE (fw * 12, 0)-(fw * 12, _HEIGHT), _RGB(205, 185, 98)
LINE (fw * 12.5, 0)-(fw * 12.5, _HEIGHT), _RGB(205, 185, 98)
'draw the text lines to bottom of screen
FOR y = fh - 1 TO _HEIGHT STEP fh
LINE (0, y)-(_WIDTH, y), _RGB(152, 160, 74)
NEXT
'draw top brown tile area (remove this if not wanted)
LINE (0, 0)-(_WIDTH, fh * 3), _RGB(102, 19, 15), BF '<< enough for 3 lines
COLOR _RGB(255, 255, 0)
'Next we print title$, centering the text in the top area
'For this we need to calcuale how many letters fit on one line, INT(_WIDTH/fw) / 2.
'I divided that by 2 to find the center spot on the line.
'So, subtract half of the title$ length from that spot to make it centered nice.
LOCATE 2, INT((_WIDTH / fw) / 2) - INT(LEN(title$) / 2)
'Now we PRINT the text, but we need to print a certain way so the background isn't
'messed up. We will use _PRINTMODE _KEEPBACKGROUND to do that.
'First, let's save the current printmode so we can restore that when SUB is done.
pmode = _PRINTMODE
_PRINTMODE _KEEPBACKGROUND
PRINT title$; 'finally, PRINT the title$
'All done, so let's restore previous printmode setting
IF pmode = 1 THEN _PRINTMODE _KEEPBACKGROUND
IF pmode = 2 THEN _PRINTMODE _ONLYBACKGROUND
IF pmode = 3 THEN _PRINTMODE _FILLBACKGROUND
this is a simplified example from what I was doing but it produces the same syntax error. I was able to get arround the problem but this is just annoying:
Code: (Select All)
Screen _NewImage(400, 300, 32)
dm = _PrintMode
_PrintMode _KeepBackground
Print "X"
Select Case dm
Case 1
_PrintMode _KeepBackground
Case 2
_PrintMode _OnlyBackground
Case 3
_PrintMode _FillBackground
End Select
Something I've been tinkering with. I created the QB64PE fire logo on the tutorial site and decided to keep going with the code to create animated logos.
I've created a demo animation in the "main code" section to show how the graphics can be used. The zip file includes the sprite sheets and phoenix sound.
I envision the demo I made as a "Made With QB64 Phoenix Edition" intro to game programs.
At the top of the code is a complete chart of all assets brought in and their locations on the sprite sheet as well as where they should be placed on the screen to create a logo (of course you can choose to put them any where you like). Play around and see what you can come up with.
The ZIP file below contains the sprite sheets, sound file, and the .BAS file.
Code: (Select All)
' QB64PE Fire Logo
'
' All the assets are here needed to create custom QB64PE logos
' The subroutine "GetAssets" gathers everything from the image and sound files
' The included animation is just a sample (main code).
'
' SPRITE SHEET SIZE
' ----------------------------- ---------
' LogoLargeSheetTransparent.PNG - 3000x4800 (10 columns, 16 rows)
' LogoSmallSheetTransparent.PNG - 215x 460
' LogoPhoenixMaskTransparent.PNG - 300x 300 (not really a sprite sheet as it contains only one image)
'
' Note: The screen or image used to create QB64PE logos is assumed to be 300x300 pixels.
' The numbers below are based on that 300x300 screen/image size.
'
' ON SCREEN
' SPRITE COORDINATES ON SHEET LOCATION SIZE ON SPRITE SHEET
' ------------------ ----------- ----------------- ------- -----------------------------
' PhoenixFire(x) - ( 0, 0) 110 phoenix fire images 300x300 LogoLargeSheetTransparent.PNG (0, 0)-(2999,3299) @ 300x300
' Fire(c) - ( 0, 0) 50 bottom fire images 300x300 LogoLargeSheetTransparent.PNG (0,3300)-(2999,4799) @ 300x300
' Sprite.RedPhoenix - ( 59, 8) ( 0, 0)-(182, 289) 183x290 LogoSmallSheetTransparent.PNG
' Sprite.QB64 - (110, 19) ( 0, 290)-( 78, 375) 79x 86 LogoSmallSheetTransparent.PNG
' Sprite.PE - (108, 162) ( 79, 240)-(162, 329) 84x 40 LogoSmallSheetTransparent.PNG
' Sprite.LetterQ - (110, 19) ( 0, 290)-( 36, 333) 37x 44 LogoSmallSheetTransparent.PNG
' Sprite.LetterB - (154, 19) ( 44, 290)-( 77, 330) 34x 41 LogoSmallSheetTransparent.PNG
' Sprite.Number6 - (111, 65) ( 1, 336)-( 34, 375) 34x 40 LogoSmallSheetTransparent.PNG
' Sprite.Number4 - (152, 65) ( 42, 336)-( 78, 375) 37x 40 LogoSmallSheetTransparent.PNG
' Sprite.LetterP - (108, 162) ( 79, 290)-(117, 329) 40x 40 LogoSmallSheetTransparent.PNG
' Sprite.LetterE - (154, 162) (125, 290)-(162, 329) 38x 40 LogoSmallSheetTransparent.PNG
' Sprite.WordPhoenix - (108, 162) ( 0, 376)-(214, 417) 215x 42 LogoSmallSheetTransparent.PNG
' Sprite.WordEdition - (154, 162) ( 0, 418)-(185, 459) 186x 42 LogoSmallSheetTransparent.PNG
' Sprite.PhoenixMask - ( 0, 0) ( 0, 0)-(299, 299) 300x300 LogoPhoenixMaskTransparent.PNG
' COLORS USED
' -----------
' Color of Q = _RGB32( 77, 161, 179) Dark Cyan
' Color of B = _RGB32( 26, 50, 230) Off Blue
' Color of 6 = _RGB32(242, 175, 13) Light Orange
' Color of 4 = _RGB32(242, 94, 13) Burnt Orange
' Color of P = _RGB32(255, 255, 0) Yellow
' Color of E = _RGB32(255, 255, 0) Yellow
' All RED in images = _RGB32(255, 0, 0) (red phoenix, red in "hoenix" and "dition")
' BLACK around "dition" and "hoenix" = _RGB32( 0, 0, 1) Almost Black (if letter border fading/hiding is desired)
' All other BLACK in images = _RGB32( 0, 0, 0) (letter outlines, phoenix mask)
' All TRANSPARENT in images = _RGB32(255, 0, 255) Magenta
OPTION _EXPLICIT ' declare those variables!
CONST BACKGROUND~& = _RGB32(0, 0, 0) ' background color
' Note: Background color not working correctly when flame outline is faded out. Need to correct this.
' Use black for now.
TYPE IMAGE ' IMAGE & LOCATION PROPERTIES
Image AS LONG ' sprite image
x AS SINGLE ' default screen X location
y AS SINGLE ' default screen Y location
END TYPE
TYPE SPRITE ' SPRITE IMAGE PROPERTIES
RedPhoenix AS IMAGE ' red phoenix silhoutte surrounded by black outline
QB64 AS IMAGE ' multicolored QB64 as one image each letter surrounded by black outline
PE AS IMAGE ' yellow PE as one image each letter surrounded by black outline
LetterQ AS IMAGE ' just the cyan letter Q surrounded by black outline
LetterB AS IMAGE ' just the blue letter B surrounded by black outline
Number6 AS IMAGE ' just the light orange number 6 surrounded by black outline
Number4 AS IMAGE ' just the dark orange number 4 surrounded by black outline
LetterP AS IMAGE ' just the yellow letter P surrounded by black outline
LetterE AS IMAGE ' just the yellow letter E surrounded by black outline
WordPhoenix AS IMAGE ' the entire word "Phoenix", yellow P, red "hoenix" surrounded by black outline
WordEdition AS IMAGE ' the entire word "Edition", yellow W, red "dition" surrounded by black outline
PhoenixMask AS IMAGE ' the black phoenix mask
END TYPE
DIM Sprite AS SPRITE ' sprite images
DIM Fire(49) AS LONG ' fire frames
DIM PhoenixFire(109) AS LONG ' red phoenix outline flame frames
DIM ClearScreen AS LONG ' CLS replacement
DIM FireBox AS LONG ' bottom fire animation box
DIM WordPhoenix AS LONG ' the entire word "Phoenix" image
DIM WordEdition AS LONG ' the entire word "Edition" image
DIM Screech AS LONG ' the sound a Phoenix makes (I think)
DIM px AS SINGLE ' letter P location before move
DIM py AS SINGLE
DIM ex AS SINGLE ' letter E location before move
DIM ey AS SINGLE
DIM pxvec AS SINGLE ' letter P vector to final location
DIM pyvec AS SINGLE
DIM exvec AS SINGLE ' letter E vector to final location
DIM eyvec AS SINGLE
DIM Alpha AS INTEGER ' alpha counter
DIM Skip AS INTEGER ' frame skip counter
DIM Frame AS INTEGER ' outline flame frame counter
DIM Size AS INTEGER ' size counter
'+-----------+
'| Main code |
'+-----------+
GetAssets ' set up images and sound
SCREEN _NEWIMAGE(300, 300, 32) ' set up screen
Size = 0
Frame = 0
Skip = 0
DO
_LIMIT 120 ' 120 frames per second
Skip = Skip + 1 ' keep flames at 30 FPS
IF Skip = 4 THEN ' time for next flame frame?
Skip = 0 ' yes, reset 30FPS counter
Frame = Frame + 1 ' increment animation counter
IF Frame = 110 THEN Frame = 0 ' reset animation counter when needed
END IF
_PUTIMAGE (0, 0), ClearScreen ' clear screen
_PUTIMAGE (149 - Size, 149 - Size)-(149 + Size, 149 + Size), PhoenixFire(Frame) ' display flaming outline
_PUTIMAGE (149 - Size, 149 - Size)-(149 + Size, 149 + Size), Sprite.PhoenixMask.Image ' display phoenix mask
_DISPLAY ' update screen
Size = Size + 1 ' increase size of images
LOOP UNTIL Size = 150 ' leave when image full size
'+---------------------+
'| Fade in red phoenix |
'+---------------------+
px = 42 ' word "Phoenix" location
py = 202
ex = 57 ' word "Edition" location
ey = 247
Alpha = 0
_SNDPLAY Screech
DO
_LIMIT 30
Frame = Frame + 1
IF Frame = 110 THEN Frame = 0
_SETALPHA Alpha, _RGBA32(255, 0, 0, 0) TO _RGBA(255, 0, 0, 255), Sprite.RedPhoenix.Image ' fade phoenix red
Alpha = Alpha + 4 ' increase fade
_PUTIMAGE (0, 0), ClearScreen ' clear screen
_PUTIMAGE (0, 0), PhoenixFire(Frame) ' display flaming outline
_PUTIMAGE (Sprite.RedPhoenix.x, Sprite.RedPhoenix.y), Sprite.RedPhoenix.Image ' display red phoenix
_PUTIMAGE (Sprite.QB64.x, Sprite.QB64.y), Sprite.QB64.Image ' display QB64
UpdateWords ' update flames in letters of words
_PUTIMAGE (px, py), WordPhoenix ' display "Phoenix"
_PUTIMAGE (ex, ey), WordEdition ' display "Edition"
_DISPLAY ' update screen
LOOP UNTIL Alpha = 256
pxvec = (108 - px) / 30 ' calculate vectors of letter P to new location
pyvec = (162 - py) / 30 ' (30 steps)
exvec = (154 - ex) / 30 ' calculate vectors of letter E to new location
eyvec = (162 - ey) / 30 ' (30 steps)
'+----------------------------+
'| Move PE to banner location |
'+----------------------------+
Alpha = 255
DO
_LIMIT 30
Frame = Frame + 1
IF Frame = 110 THEN Frame = 0
_PUTIMAGE (0, 0), ClearScreen ' clear screen
_SETALPHA Alpha, _RGB32(0, 0, 0, 0) TO _RGB32(255, 255, 255, 255), PhoenixFire(Frame) ' fade out flaming outline
_PUTIMAGE (0, 0), PhoenixFire(Frame) ' display flaming outline
_PUTIMAGE (Sprite.RedPhoenix.x, Sprite.RedPhoenix.y), Sprite.RedPhoenix.Image ' display red phoenix
_PUTIMAGE (Sprite.QB64.x, Sprite.QB64.y), Sprite.QB64.Image ' display QB64
_PUTIMAGE (px, py), Sprite.LetterP.Image ' display letter P
px = px + pxvec ' update letter P position
py = py + pyvec
_PUTIMAGE (ex, ey), Sprite.LetterE.Image ' display letter E
ex = ex + exvec ' update letter E position
ey = ey + eyvec
Alpha = Alpha - 5 ' increase fade
_DISPLAY ' update screen
LOOP UNTIL INT(px) > 107 ' leave when letter P in place
'+--------------------+
'| Display final logo |
'+--------------------+
_PUTIMAGE (0, 0), ClearScreen
_PUTIMAGE (Sprite.RedPhoenix.x, Sprite.RedPhoenix.y), Sprite.RedPhoenix.Image
_PUTIMAGE (Sprite.QB64.x, Sprite.QB64.y), Sprite.QB64.Image
_PUTIMAGE (Sprite.PE.x, Sprite.PE.y), Sprite.PE.Image
_DISPLAY
SLEEP 1
FOR Frame = 0 TO 109 ' free assets from RAM
_FREEIMAGE PhoenixFire(Frame)
IF Frame < 50 THEN _FREEIMAGE Fire(Frame)
NEXT Frame
_FREEIMAGE FireBox
_FREEIMAGE ClearScreen
_FREEIMAGE WordPhoenix
_FREEIMAGE WordEdition
_FREEIMAGE Sprite.RedPhoenix.Image
_FREEIMAGE Sprite.QB64.Image
_FREEIMAGE Sprite.PE.Image
_FREEIMAGE Sprite.LetterQ.Image
_FREEIMAGE Sprite.LetterB.Image
_FREEIMAGE Sprite.Number6.Image
_FREEIMAGE Sprite.Number4.Image
_FREEIMAGE Sprite.LetterP.Image
_FREEIMAGE Sprite.LetterE.Image
_FREEIMAGE Sprite.WordPhoenix.Image
_FREEIMAGE Sprite.WordEdition.Image
_FREEIMAGE Sprite.PhoenixMask.Image
_SNDCLOSE Screech
SYSTEM ' return to OS
' ______________________________________________________________________________________________________
'/ \
SUB UpdateWords () ' UpdateWords |
' __________________________________________________________________________________________________|____
'/ \
'| Updates the fire animation inside "hoenix" and "dition". |
'\_______________________________________________________________________________________________________/
SHARED Sprite AS SPRITE
SHARED WordPhoenix AS LONG
SHARED WordEdition AS LONG
SHARED FireBox AS LONG
UpdateFireBox -1 ' next flame animation
_CLEARCOLOR _RGB32(255, 0, 0), Sprite.WordPhoenix.Image ' make red transparent
_PUTIMAGE (0, 0), FireBox, WordPhoenix, (0, 258)-(214, 299) ' put fire on image
_PUTIMAGE (0, 0), Sprite.WordPhoenix.Image, WordPhoenix ' overlay word onto image
_CLEARCOLOR _RGB32(255, 255, 255), WordPhoenix ' make white transparent
_CLEARCOLOR _RGB32(255, 0, 0), Sprite.WordEdition.Image ' make red transparent
_PUTIMAGE (0, 0), FireBox, WordEdition, (114, 258)-(299, 299) ' put fire on image
_PUTIMAGE (0, 0), Sprite.WordEdition.Image, WordEdition ' overlay word onto image
_CLEARCOLOR _RGB32(255, 255, 255), WordEdition ' make white transparent
END SUB
' ______________________________________________________________________________________________________
'/ \
SUB UpdateFireBox (Action AS INTEGER) ' UpdateFireBox |
' __________________________________________________________________________________________________|____
'/ \
'| Updates the firebox image with the next fire animation frame |
'| |
'| Action: 0 same frame, non 0 next frame |
'\_______________________________________________________________________________________________________/
SHARED FireBox AS LONG
SHARED Fire() AS LONG
SHARED ClearScreen AS LONG
STATIC c AS INTEGER
IF Action THEN ' move to next frame?
c = c + 1 ' yes, increment frame counter
IF c = 50 THEN c = 0 ' reset counter when needed
END IF
_PUTIMAGE (0, 0), ClearScreen, FireBox ' clear firebox image
_PUTIMAGE (0, 0), Fire(c), FireBox ' display next frame in animation
END SUB
' ______________________________________________________________________________________________________
'/ \
SUB GetAssets () ' GetAssets |
' __________________________________________________________________________________________________|____
'/ \
'| Get images and sounds from asset files |
'\_______________________________________________________________________________________________________/
SHARED Fire() AS LONG ' fire frames
SHARED PhoenixFire() AS LONG ' red phoenix outline flame frames
SHARED Sprite AS SPRITE ' need access to sprite images
SHARED ClearScreen AS LONG ' blank screen (alternate CLS)
SHARED FireBox AS LONG ' image to hold bottom flame animation
SHARED WordPhoenix AS LONG ' "Phoenix" word image holder
SHARED WordEdition AS LONG ' "Edition" word image holder
SHARED Screech AS LONG ' phoenix mating call?
DIM SmallSheet AS LONG ' small sprite sheet
DIM LargeSheet AS LONG ' large sprite sheet
DIM x AS INTEGER ' row counter
DIM y AS INTEGER ' column counter
DIM c AS INTEGER ' image counter
Sprite.PhoenixMask.Image = _LOADIMAGE("LogoPhoenixMaskTransparent.png", 32) ' load phoenix black mask
SmallSheet = _LOADIMAGE("LogoSmallSheetTransparent.png", 32) ' load small sprite sheet
LargeSheet = _LOADIMAGE("LogoLargeSheetTransparent.png", 32) ' load large sprite sheet
'+---------------------------------------------------------------------------------------------------+
'| Set location of images on screen, create image containers, extract images from small sprite sheet.|
'+---------------------------------------------------------------------------------------------------+
'+---------------------------------------------------+
'| Red phoenix silhoutte surrounded by black outline |
'+---------------------------------------------------+
Sprite.RedPhoenix.x = 59: Sprite.RedPhoenix.y = 8
Sprite.RedPhoenix.Image = _NEWIMAGE(183, 290, 32)
_PUTIMAGE , SmallSheet, Sprite.RedPhoenix.Image, (0, 0)-(182, 289)
'+------------------------------------------------------------------------+
'| Multicolored QB64 as one image each letter surrounded by black outline |
'+------------------------------------------------------------------------+
Sprite.QB64.x = 110: Sprite.QB64.y = 19
Sprite.QB64.Image = _NEWIMAGE(79, 86, 32)
_PUTIMAGE , SmallSheet, Sprite.QB64.Image, (0, 290)-(78, 375)
'+----------------------------------------------------------------+
'| Yellow PE as one image each letter surrounded by black outline |
'+----------------------------------------------------------------+
Sprite.PE.x = 108: Sprite.PE.y = 162
Sprite.PE.Image = _NEWIMAGE(84, 40, 32)
_PUTIMAGE , SmallSheet, Sprite.PE.Image, (79, 290)-(162, 329)
'+----------------------------------------------------+
'| Just the cyan letter Q surrounded by black outline |
'+----------------------------------------------------+
Sprite.LetterQ.x = 110: Sprite.LetterQ.y = 19
Sprite.LetterQ.Image = _NEWIMAGE(37, 44, 32)
_PUTIMAGE , SmallSheet, Sprite.LetterQ.Image, (0, 290)-(36, 333)
'+----------------------------------------------------+
'| Just the blue letter B surrounded by black outline |
'+----------------------------------------------------+
Sprite.LetterB.x = 154: Sprite.LetterB.y = 19
Sprite.LetterB.Image = _NEWIMAGE(34, 41, 32)
_PUTIMAGE , SmallSheet, Sprite.LetterB.Image, (44, 290)-(77, 330)
'+------------------------------------------------------------+
'| Just the light orange number 6 surrounded by black outline |
'+------------------------------------------------------------+
Sprite.Number6.x = 111: Sprite.Number6.y = 65
Sprite.Number6.Image = _NEWIMAGE(34, 40, 32)
_PUTIMAGE , SmallSheet, Sprite.Number6.Image, (1, 336)-(34, 375)
'+-----------------------------------------------------------+
'| Just the dark orange number 4 surrounded by black outline |
'+-----------------------------------------------------------+
Sprite.Number4.x = 152: Sprite.Number4.y = 65
Sprite.Number4.Image = _NEWIMAGE(37, 40, 32)
_PUTIMAGE , SmallSheet, Sprite.Number4.Image, (42, 336)-(78, 375)
'+------------------------------------------------------+
'| Just the yellow letter P surrounded by black outline |
'+------------------------------------------------------+
Sprite.LetterP.x = 108: Sprite.LetterP.y = 162
Sprite.LetterP.Image = _NEWIMAGE(40, 40, 32)
_PUTIMAGE , SmallSheet, Sprite.LetterP.Image, (79, 290)-(117, 329)
'+------------------------------------------------------+
'| Just the yellow letter E surrounded by black outline |
'+------------------------------------------------------+
Sprite.LetterE.x = 154: Sprite.LetterE.y = 162
Sprite.LetterE.Image = _NEWIMAGE(38, 40, 32)
_PUTIMAGE , SmallSheet, Sprite.LetterE.Image, (125, 290)-(162, 329)
'+-------------------------------------------------------------------------------+
'| The entire word "Phoenix", yellow P, red "hoenix" surrounded by black outline |
'+-------------------------------------------------------------------------------+
Sprite.WordPhoenix.x = 108: Sprite.WordPhoenix.y = 162
Sprite.WordPhoenix.Image = _NEWIMAGE(215, 42, 32)
_PUTIMAGE , SmallSheet, Sprite.WordPhoenix.Image, (0, 376)-(214, 417)
'+-------------------------------------------------------------------------------+
'| The entire word "Edition", yellow E, red "dition" surrounded by black outline |
'+-------------------------------------------------------------------------------+
Sprite.WordEdition.x = 154: Sprite.WordEdition.y = 162
Sprite.WordEdition.Image = _NEWIMAGE(186, 42, 32)
_PUTIMAGE , SmallSheet, Sprite.WordEdition.Image, (0, 418)-(185, 459)
_FREEIMAGE SmallSheet ' small sprite sheet no longer needed
'+----------------------------------------+
'| extract images from large sprite sheet |
'+----------------------------------------+
y = 0
c = -1
DO
x = 0
DO
'+--------------------------------------+
'| Extract phoenix flame outline images |
'+--------------------------------------+
c = c + 1
PhoenixFire(c) = _NEWIMAGE(300, 300, 32)
_PUTIMAGE , LargeSheet, PhoenixFire(c), (x * 300, y * 300)-(x * 300 + 299, y * 300 + 299)
IF c < 50 THEN
Fire(c) = _NEWIMAGE(300, 300, 32)
_PUTIMAGE , LargeSheet, Fire(c), (x * 300, 3300 + y * 300)-(x * 300 + 299, y * 300 + 3599)
END IF
x = x + 1
LOOP UNTIL x = 10
y = y + 1
LOOP UNTIL y = 11
_FREEIMAGE LargeSheet ' large sprite sheet no longer needed
Hi all
Need help with a Scientific Notation to real number converter. Below is a mockup for testing the Function but if I do the
calculations by hand the outputs don't match.
Thanks in advance
R1
Code: (Select All)
FOR L1 = 1 TO 9
IF L1 = 1 THEN A = 75 / 130
IF L1 = 2 THEN A = 1 / 103
IF L1 = 3 THEN A = 7 / 27
IF L1 = 4 THEN A = 11 / 42
IF L1 = 5 THEN A = 15 / 63
IF L1 = 6 THEN A = 35 / 118
IF L1 = 7 THEN A = 60 / 142
IF L1 = 8 THEN A = 47 / 125
IF L1 = 9 THEN A = 93 / 148
P = (P/9)
A$ = STRNUM$(P)
A$=MID$(A$,1,6)
PRINT A$ + " <- averaged"
color 10
print "Press any key"
SLEEP
SYSTEM
FUNCTION StrNum$ (n)
value$ = UCASE$(LTRIM$(STR$(n)))
XPOS1 = INSTR(value$, "D") + INSTR(value$, "E")
IF XPOS1 THEN
expo = VAL(MID$(value$, XPOS1 + 1))
IF VAL(value$) < 0 THEN
sign$ = "-": value$ = MID$(value$, 2, XPOS1 - 2)
ELSE value$ = MID$(value$, 1, XPOS1 - 1)
END IF
dot = INSTR(value$, "."): L = LEN(value$)
IF expo > 0 THEN ADD$ = StrNum$(expo - (L - dot), "0")
IF expo < 0 THEN min$ = StrNum$(ABS(expo) - (dot - 1), "0"): DP$ = "."
FOR N = 1 TO L
IF MID$(value$, N, 1) <> "." THEN num$ = num$ + MID$(value$, N, 1)
NEXT
ELSE StrNum$ = value$: EXIT FUNCTION
END IF
StrNum$ = sign$ + DP$ + min$ + num$ + ADD$
END FUNCTION