I wanted to replace the messy ripple tanks used to get familiar with wave behaviour with computer equivalents.
- -
Previous attempts had used line graphics and the drawing 'circle' command. But they don't LOOK right. I wanted grey-scale images that looked more realistic. This led to some pretty slow code, but images can be saved and animated as GIFs. And yes, I accidentally animated this backwards!!
- -
It was particularly fun to model phased-arrays of multipole emitters and create a steerable main lobe.
- -
- -
' *********************************************************
' ** **
' ** aniRippleV7b.bas tenochtitlanuk 18/06/2020 **
' ** **
' *********************************************************
' Generate stills to create animations of travelling waves.
' To-dos
' -change so calculates how much each source adds so total <256 and >=0.
' -check against preferred LB5 syntax.
' -add programmatic change to frequency /wavelength.
' -speed up a lot by summing waves then drawing each point.
nomainwin
WindowWidth =530
WindowHeight =550
open "Animate Phased Array" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "down"
#wg "size 1 ; fill 128 128 128"
dim screen( 500, 500)
phaseLag =0.8
pi =4 *atn( 1)
' phaseLag is amount adjacent sources lag by for steering.
' delay is overall phase offset to move pattern outwards fraction of wavelength.
delay = 0
count =20
for wLength =0.5 to 4 step 0.5
for x =0 to 499 step 1
for y =0 to 499 step 1
screen( x, y) =128
for j =1 to 2
radialDist =sqr( ( x -200 -j *32)^2 +( 460 -y)^2)
screen( x, y) =screen( x, y) +62 *( sin( radialDist /wLength +j *phaseLag +delay))
scan
next j
#wg "color "; screen( x, y); " "; screen( x, y); " "; screen( x, y)
#wg "set "; 10 +x; " "; 10 +y
next y
next x
#wg "flush ; getbmp scr 0 0 520 540"
bmpsave "scr", "V8" +right$( "00" +str$( count), 2) +".bmp"
#wg "cls ; fill 128 128 126"
count =count -1
next wLength
wait
sub quit h$
close #wg
end
end sub
nomainwin
WindowWidth =530
WindowHeight =550
open "Animate Phased Array" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "down"
#wg "size 1 ; fill 128 128 128"
dim screen( 500, 500)
global phaseLag, delay: phaseLag =1.5: pi =4 *atn( 1)
for delay =0 to 2 *pi step pi /5
for x =0 to 499
for y =0 to 499
screen( x, y) =128
next y
next x
call populate 1
#wg "getbmp scr 0 0 530 550"
bmpsave "scr", "aniRipple" +str$( time$( "seconds")) +".bmp"
#wg "cls ; fill 128 128 126"
next delay
wait
sub quit h$
close #wg
end
end sub
sub populate i
for j =1 to i
for x =0 to 499 step 1
for y =0 to 499 step 1
radialDist =sqr( ( x -200 -j *16)^2 +( 460 -y)^2)
screen( x, y) =screen( x, y) +127 *( sin( radialDist /4 +j *phaseLag +delay))
#wg "color "; int( screen( x, y)); " "; int( screen( x, y)); " "; int( screen( x, y))
#wg "set "; 10 +x; " "; 10 +y
scan
next y
next x
next j
end sub