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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 492
» Latest member: Feederumn
» Forum threads: 2,829
» Forum posts: 26,512

Full Statistics

Latest Threads
Rock Jockey 2.0 is ready ...
Forum: Games
Last Post: NakedApe
2 hours ago
» Replies: 18
» Views: 493
Aloha from Maui guys.
Forum: General Discussion
Last Post: bplus
2 hours ago
» Replies: 1
» Views: 14
ANSIPrint
Forum: a740g
Last Post: bplus
3 hours ago
» Replies: 9
» Views: 125
Audio Spectrum Analyser
Forum: Programs
Last Post: Jack002
6 hours ago
» Replies: 7
» Views: 131
_mem
Forum: Help Me!
Last Post: hsiangch_ong
6 hours ago
» Replies: 13
» Views: 270
pan around a large image ...
Forum: Programs
Last Post: hsiangch_ong
6 hours ago
» Replies: 0
» Views: 11
trouble building ansiprin...
Forum: Help Me!
Last Post: hsiangch_ong
7 hours ago
» Replies: 2
» Views: 49
decfloat -- again
Forum: Programs
Last Post: Jack002
9 hours ago
» Replies: 42
» Views: 2,921
multiplayer spacewar
Forum: Works in Progress
Last Post: madscijr
Yesterday, 07:07 PM
» Replies: 0
» Views: 22
games or graphics for 3-D...
Forum: General Discussion
Last Post: madscijr
Yesterday, 04:39 AM
» Replies: 28
» Views: 1,081

 
  Toggles
Posted by: SMcNeill - 10-12-2023, 02:42 AM - Forum: Works in Progress - Replies (2)

Code: (Select All)
Option _Explicit
$Color:32
Type ToggleButton
active As Integer
state As Integer
x As Integer
y As Integer
End Type
ReDim Shared Toggles(1000) As ToggleButton
ReDim Shared As Integer TogglesInUse
Dim Shared As Long Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY

Screen _NewImage(640, 480, 32)

Dim As Long foo, fred, MBS

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
_Limit 30
_Display
Loop Until _KeyDown(27)
FreeToggle 0 'free all toggles for use later
System


Function GetToggleValue (handle As Long)
If handle < 0 Or handle > 1000 Then Exit Function
GetToggleValue = Toggles(handle).state
End Function

Sub FreeToggle (handle As Long)
If handle < 0 Or handle > 1000 Then Exit Sub
If handle = 0 Then TogglesInUse = 0
Toggles(handle).active = 0
End Sub


Sub ProcessToggles (MBS As Long)
Dim As Long i
If MBS And 8 Then 'left button was clicked
For i = 1 To TogglesInUse
If _MouseX >= Toggles(i).x And _MouseX <= Toggles(i).x + 100 Then
If _MouseY >= Toggles(i).y And _MouseY <= Toggles(i).y + 24 Then
Toggles(i).state = Not Toggles(i).state
End If
End If
Next
End If
End Sub

Sub DisplayToggles
Dim As Long i, x, y, state, w, t, cx, cy
Dim As Long DC, BGC
DC = _DefaultColor: BGC = _BackgroundColor
w = 25: t = 12
Color White, 0
For i = 1 To 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

Function CreateToggle (x As Long, y As Long)
Dim As Long i
For i = 1 To TogglesInUse
If Toggles(i).active = 0 Then
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

Sub EllipseFill (CX As Integer, CY As Integer, a As Integer, b As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' C = fill color
If a = 0 Or b = 0 Then Exit Sub
Dim h2 As _Integer64
Dim w2 As _Integer64
Dim h2w2 As _Integer64
Dim x As Integer
Dim y As Integer
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
Line (CX - a, CY)-(CX + a, CY), C, BF
Do While y < b
y = y + 1
x = Sqr((h2w2 - y * y * w2) \ h2)
Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
Loop
End Sub

Function MouseButtonStatus% 'Mouse Button Status
Static StartTimer As _Float
Static ButtonDown As Integer
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
Dim As Long tempMBS, BD
While _MouseInput 'Remark out this block, if mouse main input/clear is going to be handled manually in main program.
Select Case Sgn(_MouseWheel)
Case 1: tempMBS = tempMBS Or 512
Case -1: tempMBS = tempMBS Or 1024
End Select
Wend


If _MouseButton(1) Then tempMBS = tempMBS Or 1
If _MouseButton(2) Then tempMBS = tempMBS Or 2
If _MouseButton(3) Then tempMBS = tempMBS Or 4


If StartTimer = 0 Then
If _MouseButton(1) Then 'If a button is pressed, start the timer to see what it does (click or hold)
ButtonDown = 1: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
ElseIf _MouseButton(2) Then
ButtonDown = 2: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
ElseIf _MouseButton(3) Then
ButtonDown = 3: StartTimer = Timer(0.01)
Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
End If
Else
BD = ButtonDown Mod 3
If BD = 0 Then BD = 3
If Timer(0.01) - StartTimer <= ClickLimit Then 'Button was down, then up, within time limit. It's a click
If _MouseButton(BD) = 0 Then tempMBS = 4 * 2 ^ ButtonDown: ButtonDown = 0: StartTimer = 0
Else
If _MouseButton(BD) = 0 Then 'hold event has now ended
tempMBS = 0: ButtonDown = 0: StartTimer = 0
Mouse_EndX = _MouseX: Mouse_EndY = _MouseY
Else 'We've now started the hold event
tempMBS = tempMBS Or 32 * 2 ^ ButtonDown
End If
End If
End If
MouseButtonStatus = tempMBS
End Function

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.

Print this item

  Bestest non-bug yet!
Posted by: SMcNeill - 10-12-2023, 01:00 AM - Forum: General Discussion - Replies (1)

Code: (Select All)
OPTION _EXPLICIT
f 2

SUB f (x)
    DIM x AS LONG
    PRINT x
END SUB

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:

Code: (Select All)
OPTION _EXPLICIT
f 2

SUB f (x)
    DIM x AS LONG
    PRINT x, x!
END SUB

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......

Confused yet??

Print this item

  RotoLine line drawing
Posted by: James D Jarvis - 10-11-2023, 04:24 PM - Forum: Works in Progress - No Replies

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

'$dynamic
_Title "RotoLine Demo"
Screen _NewImage(800, 500, 32)
Dim Shared dot&
dot& = _NewImage(1, 1, 32) 'ALL rotoline routines all need this defiend as so
Dim a(10, 2)
Randomize Timer
Locate 1, 10: Print "Draw lines with thickness other than 1.   Press any key to continue"
RotoLine 300, 50, 700, 90, 32, _RGB32(100, 100, 0)
RotoLineEC 100, 100, 200, 100, 7, _RGB32(250, 0, 200)
RotoLineEC 200, 100, 300, 300, 7, _RGB32(250, 0, 200)
a(1, 1) = 0: a(1, 2) = 0
a(2, 1) = 50: a(2, 2) = 60
a(3, 1) = 55: a(3, 2) = 70
a(4, 1) = 100: a(4, 2) = 80
a(5, 1) = 101: a(5, 2) = 78
a(6, 1) = 108: a(6, 2) = 176
a(7, 1) = 111: a(7, 2) = 200
a(8, 1) = 113: a(8, 2) = 232
a(9, 1) = 112: a(9, 2) = 370
a(10, 1) = 110: a(10, 2) = 400
rline a(), 4, _RGB32(60, 120, 0)

'making a circle with rline
ReDim a(180, 2)
cx = 400: cy = 300: rad = 80: r = 0
For p = 1 To 180
    a(p, 1) = cx + (rad * Cos(0.01745329 * r))
    a(p, 2) = cy + (rad * Sin(0.01745329 * r))
    r = r + 2
Next p
rline a(), 3, _RGB32(0, 100, 200)
_PrintString (290, 200), "a circle from an array"
Sleep
'draw regular polygon with rpoly
cx = 200
For s = 3 To 40
    _Limit 4
    Cls
    Locate 1, 1: Print "sides "; s; ",radius "; s * 5; ", line thickness "; Int((s + 1) / 3)
    rpoly cx, 250, s * 5, s, s * 2, Int((s + 1) / 3), _RGB32(0, 200, 100)
    cx = cx + 10
    _Display
Next s
_AutoDisplay
Locate 2, 1: Print "Press any key to continue"
Sleep
Cls
t1 = Timer
dlimit = 64000
For n = 1 To dlimit
    RotoLine Int(Rnd * _Width), Int(Rnd * _Height), Int(Rnd * _Width), Int(Rnd * _Height), Int(1 + Rnd * 12), _RGB32(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
Next n
t2 = Timer
Print t2 - t1; " seconds to draw "; dlimit; " randomly generated lines"
Sleep
Cls
Print "roto_rect, roto_rectEC and rpolyFT"
roto_rect 101, 101, 200, 100, 3, 0, _RGB32(0, 100, 100), _RGB32(0, 200, 200)
'Line (101, 101)-(300, 200), _RGB32(250, 250, 250), B
roto_rectEC 101, 301, 200, 100, 12, 25, _RGB32(0, 200, 100), _RGB32(0, 230, 230)
rpolyFT 550, 250, 50, 5, 0, 3, _RGB32(0, 100, 70), _RGB32(0, 200, 140)


Sub roto_rect (rx, ry, ww, hh, thk, rtn, lklr As _Unsigned Long, fklr As _Unsigned Long)
    Dim sb&
    sb& = _NewImage(ww + thk * 2, hh + thk * 2, 32) 'make a scratchboard
    o& = _Dest
    _Dest sb&
    x1 = thk: x2 = thk + ww - 1
    y1 = thk: y2 = thk + hh - 1
    Line (x1, y1)-(x2, y2), fklr, BF
    RotoLine x1, y1, x2, y1, thk, lklr
    RotoLine x2, y1, x2, y2, thk, lklr
    RotoLine x2, y2, x1, y2, thk, lklr
    RotoLine x1, y2, x1, y1, thk, lklr
    _Dest o&
    RotoZoom23d rx + ww / 2, ry + hh / 2, sb&, 1, 1, rtn
    _FreeImage sb&
End Sub
Sub roto_rectEC (rx, ry, ww, hh, thk, rtn, lklr As _Unsigned Long, fklr As _Unsigned Long)
    Dim sb&
    sb& = _NewImage(ww + thk * 2, hh + thk * 2, 32) 'make a scratchboard
    o& = _Dest
    _Dest sb&
    x1 = thk: x2 = thk + ww - 1
    y1 = thk: y2 = thk + hh - 1
    Line (x1, y1)-(x2, y2), fklr, BF
    RotoLineEC x1, y1, x2, y1, thk, lklr
    RotoLineEC x2, y1, x2, y2, thk, lklr
    RotoLineEC x2, y2, x1, y2, thk, lklr
    RotoLineEC x1, y2, x1, y1, thk, lklr
    _Dest o&
    RotoZoom23d rx + ww / 2, ry + hh / 2, sb&, 1, 1, rtn
    _FreeImage sb&
End Sub



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

Print this item

  Snapback Windows
Posted by: SMcNeill - 10-11-2023, 12:58 PM - Forum: SMcNeill - Replies (3)

Code: (Select All)
DECLARE LIBRARY
    FUNCTION glutGet& (BYVAL what&)
    SUB glutReshapeWindow (BYVAL width&, BYVAL height&)
END DECLARE

$RESIZE:ON
_DELAY 2
ClearTheFlag = _RESIZE

DO
    CLS , 3
    IF _RESIZE THEN
        RSW = _RESIZEWIDTH
        RSH = _RESIZEHEIGHT
        W = RSW \ _FONTWIDTH
        H = RSH \ _FONTHEIGHT
        IF W < 40 THEN W = 40
        IF H < 15 THEN H = 15
        IF W > 120 THEN W = 120
        IF H > 50 THEN H = 50
        f = _FONT
        WIDTH W, H
        _FONT f
        IF _WIDTH * _FONTWIDTH <> WindowWidth OR _HEIGHT * _FONTHEIGHT <> WindowHeight THEN
            glutReshapeWindow _WIDTH * _FONTWIDTH, _HEIGHT * _FONTHEIGHT
        END IF
        ClearTheFlag = _RESIZE
    END IF
    PRINT _WIDTH, _HEIGHT
    _DISPLAY
LOOP

FUNCTION WindowWidth
    WindowWidth = glutGet(102) '102 is the const value of GLUT_WINDOW_WIDTH
END FUNCTION

FUNCTION WindowHeight
    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.  Sad

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!)

Print this item

  Yellow notebook paper background (scales to fit font setting)
Posted by: Dav - 10-11-2023, 12:55 PM - Forum: Programs - Replies (20)

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

END SUB

Print this item

  _printmode ???
Posted by: James D Jarvis - 10-10-2023, 07:36 PM - Forum: Help Me! - Replies (2)

why doesn't this work?

Code: (Select All)
Screen _NewImage(400, 300, 32)
dm = _PrintMode
_PrintMode _KeepBackground
Print "X"
_printmode dm

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

Print this item

  QB64 Logo Maker
Posted by: TerryRitchie - 10-10-2023, 02:16 AM - Forum: Works in Progress - Replies (2)

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

'+------------------------------+
'| Zoom flaming outline forward |
'+------------------------------+

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

    ClearScreen = _NEWIMAGE(300, 300, 32) '  create CLS alternative
    _DEST ClearScreen
    CLS , BACKGROUND
    _DEST 0
    FireBox = _NEWIMAGE(300, 300, 32) '      create image holders
    WordPhoenix = _NEWIMAGE(215, 42, 32)
    WordEdition = _NEWIMAGE(186, 42, 32)
    Screech = _SNDOPEN("LogoPhoenix.ogg") '  load phoenix mating call

    '+------------------+
    '| Load image files |
    '+------------------+

    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)

            '+-----------------------------+
            '| Extract bottom flame images |
            '+-----------------------------+

            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

END SUB



Attached Files
.zip   QB64Logo.zip (Size: 8.53 MB / Downloads: 45)
Print this item

  BAM: Release notes in the works for upcoming release
Posted by: CharlieJV - 10-10-2023, 01:26 AM - Forum: QBJS, BAM, and Other BASICs - Replies (6)

If you are interested in this, even just to see Feather Wiki in action for release notes:

Release Notes

Print this item

  Possible CLS improvement
Posted by: TerryRitchie - 10-09-2023, 04:35 PM - Forum: General Discussion - Replies (14)

Quite often I find the need to clear an image other than the current screen or _DISPLAY and have to do this:

oDest& = _DEST
_DEST MyImage&
CLS
_DEST oDest&

Perhaps CLS could be modified:

CLS [method%][, bgColor&][, ImageHandle&]

so this could be done:

CLS , , MyImage&

Just a thought.

If you have a better way of handing a situation like this than I'm doing let me know.

Print this item

  need a Scientific Notation to real number converter
Posted by: random1 - 10-09-2023, 06:15 AM - Forum: Help Me! - Replies (24)

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

    A=A^2
    A$ = StrNum$(A)
    A$=MID$(A$,1,6)
    P=P + VAL(A$)

    PRINT A$
NEXT

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

Print this item