Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
anyone good at javascript want to help convert a cool animation to QB64PE?
#3
Grok AI gave this https://grok.com/share/c2hhcmQtMg%3D%3D_...cc41aa5c6d
but all I get is a black screen

Code: (Select All)

' QB64 translation of JavaScript inversion effect
' Original: https://codepen.io/yukulele/pen/qEEvrmO

' Set up graphics screen (640x480, 32-bit color)
Dim Shared w As Integer, h As Integer
Dim Shared zoom As Single, zoomFactor As Single
Dim Shared r As Single, r2 As Single
Dim Shared imageHandle As Long

w = 640
h = 480
zoom = 1
zoomFactor = 0
r = 250
r2 = r * r

Screen _NewImage(w, h, 32)
imageHandle = _NewImage(w, h, 32)
_Dest imageHandle

' Main loop
Do
    _Limit 60 ' Approximate 60 FPS
    Drawit
    _PutImage , imageHandle, 0 ' Copy image to screen
    HandleInput
    _Display
Loop Until _KeyDown(27) ' Exit on ESC

Sub Drawit
    Dim x As Integer, y As Integer
    Dim x0 As Single, y0 As Single, x2 As Single
    Dim f As Single, x1 As Single, y1 As Single
    Dim cx As Single, cy As Single, hue As Single
    Dim rgb(2) As Integer
    Dim c As Single
    Dim now As Single

    now = Timer / 1000
    c = 20 * zoom

    For x = 0 To w - 1
        x0 = x - w / 2
        x2 = x0 * x0
        For y = 0 To h / 2
            y0 = y - h / 2
            f = r2 / (x2 + y0 * y0)
            x1 = x0 * f
            y1 = y0 * f
            cx = Cos(now + x1 / c / 10)
            cy = Cos(y1 / c / 10)
            hue = Int((cx - cy) * 9) / 9

            HueToRGB hue, rgb()

            ' Set pixels (top half)
            PSet (x, y), _RGB32(rgb(0), rgb(1), rgb(2))
            ' Mirror to bottom half
            PSet (x, h - y - 1), _RGB32(rgb(0), rgb(1), rgb(2))
        Next
    Next
End Sub

Sub HueToRGB (h As Single, rgb() As Integer)
    Dim r As Single, g As Single, b As Single
    r = Hue2RGB(h + 1 / 3)
    g = Hue2RGB(h)
    b = Hue2RGB(h - 1 / 3)
    rgb(0) = r * 255
    rgb(1) = g * 255
    rgb(2) = b * 255
End Sub

Function Hue2RGB! (t As Single)
    t = ((t Mod 1) + 1) Mod 1
    If t < 1 / 6 Then
        Hue2RGB! = 6 * t
    ElseIf t < 1 / 2 Then
        Hue2RGB! = 1
    ElseIf t < 2 / 3 Then
        Hue2RGB! = 4 - t * 6
    Else
        Hue2RGB! = 0
    End If
End Function

Sub HandleInput
    Dim k As Long
    While _MouseInput: Wend ' Clear mouse buffer
    k = _KeyHit
    If k = 43 Then ' + key for zoom in
        zoomFactor = zoomFactor + 10
        zoom = 1.0005 ^ zoomFactor
    ElseIf k = 45 Then ' - key for zoom out
        zoomFactor = zoomFactor - 10
        zoom = 1.0005 ^ zoomFactor
    ElseIf k = 19200 + 68 Then ' F11 for fullscreen toggle
        If _FullScreen = 0 Then
            _FullScreen _SquarePixels
        Else
            _FullScreen _Off
        End If
    End If
End Sub
Reply


Messages In This Thread
RE: anyone good at javascript want to help convert a cool animation to QB64PE? - by Jack - 05-19-2025, 11:49 PM



Users browsing this thread: 1 Guest(s)