Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mystify
#5
Just another version of Mystify.... not as good as the real one Big Grin

Code:
' Mystify
set window "mystify", 800, 600,false
set redraw off

numPolys = 2           ' Number of polygons
pointsPerPoly = 4      ' Points per polygon (3=triangle, 4=quad)
trailLength = 10       ' Number of trailing positions to show
trailGap = 3           ' Space between trail segments

' Initialize arrays
x=dim(numPolys * pointsPerPoly, trailLength)
y=dim(numPolys * pointsPerPoly, trailLength)
dx=dim(numPolys * pointsPerPoly)
dy=dim(numPolys * pointsPerPoly)

' Set up initial positions and velocities
for poly1 = 0 to numPolys-1

    for i = 0 to pointsPerPoly-1
        index = poly1*pointsPerPoly + i
        x[index][0] = rnd(800)
        y[index][0] = rnd(600)
        for t = 1 to trailLength-1
            x[index][t] = x[index][0]
            y[index][t] = y[index][0]
        next
        do
            dx[index] = (rnd(6))-3  ' Random velocity
            dy[index] = (rnd(6))-3
        until dx[index] <> 0 and dy[index] <> 0
    next
next


'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE,true)
    set color 0,0,0
    cls
   
    for poly1 = 0 to numPolys-1
       
        polyStart = poly1*pointsPerPoly
       
        'color
        if poly1=0 then set color 255,255,0
        if poly1=1 then set color 255,0,0
       
        ' Update positions and shift trail history
        for i = 0 to pointsPerPoly-1
            index = polyStart + i
           
            ' Update current position
            x[index][0] = x[index][0]+dx[index]
            y[index][0] = y[index][0]+dy[index]
           
            ' Collision detection
            if x[index][0] < 0 or x[index][0] > 800 then dx[index] = -dx[index]
            if y[index][0] < 0 or y[index][0] > 600 then dy[index] = -dy[index]
           
            ' Shift history buffer
            for t = trailLength-1 to 1 step -1
                x[index][t] = x[index][t-1]+trailGap
                y[index][t] = y[index][t-1]+trailGap
            next
        next
       
        ' Draw all trail segments with solid color       
        for t = 0 to trailLength-1
            for i = 0 to pointsPerPoly-1
                index = polyStart + i
                nextIndex = polyStart + (i+1) % pointsPerPoly
                draw line x[index][t], y[index][t], x[nextIndex][t], y[nextIndex][t]
            next
        next
       
    next
   
    fwait 60
    redraw
wend
Reply


Messages In This Thread
Mystify - by johnno56 - 03-07-2025, 01:30 PM
RE: Mystify - by Marcus - 03-07-2025, 03:09 PM
RE: Mystify - by johnno56 - 03-07-2025, 06:22 PM
RE: Mystify - by Marcus - 03-08-2025, 10:18 AM
RE: Mystify - by 1micha.elok - 03-10-2025, 03:01 AM
RE: Mystify - by johnno56 - 03-10-2025, 05:36 AM
RE: Mystify - by 1micha.elok - 03-10-2025, 09:51 AM
RE: Mystify - by Marcus - 03-10-2025, 04:45 PM

Forum Jump:


Users browsing this thread: 4 Guest(s)