'#lang "qb" '...for freebasic compiler. Keep disabled for QB64.
' *** Video settings. ***
screenwidth = 640
screenheight = 480
' *** Performance settings. ***
bignumber = 500000 ' Maximum objects per array (determined by memory).
globaldelayinit = 1000 ' Loop damping factor (fine adjustment below).
' *** Initialize counters and array sizes. ***
numparticleorig = bignumber
numparticlevisible = bignumber
' *** Define basis arrays and structures. ***
' Screen vectors in three-space.
' These vectors define the camera angle.
' Basis vectors defined in three-space.
xhat(1) = 1: xhat(2) = 0: xhat(3) = 0: xhat(4) = 4
yhat(1) = 0: yhat(2) = 1: yhat(3) = 0: yhat(4) = 2
zhat(1) = 0: zhat(2) = 0: zhat(3) = 1: zhat(4) = 1
' Basis vectors projected into uv two-space.
DIM xhatp
(1 TO 2), yhatp
(1 TO 2), zhatp
(1 TO 2) DIM xhatp.old
(1 TO 2), yhatp.old
(1 TO 2), zhatp.old
(1 TO 2)
' *** Define particle arrays and structures. ***
' Particle vectors defined in three-space.
DIM vec
(numparticleorig
, 4) DIM vecdotnhat
(numparticleorig
) DIM vecdotnhatunit.old
(numparticleorig
) DIM vecvisible
(numparticlevisible
, 4) DIM vecvisibledotnhat
(numparticlevisible
) DIM vecvisibledotnhatunit.old
(numparticlevisible
)
' Particle vectors projected onto infinite uv two-space.
DIM vecpuv
(numparticleorig
, 1 TO 2) DIM vecpuv.old
(numparticleorig
, 1 TO 2) DIM vecvisiblepuv
(numparticlevisible
, 1 TO 2) DIM vecvisiblepuv.old
(numparticlevisible
, 1 TO 2)
' Particle projections adjusted for screen uv two-space.
DIM vecpuvs
(numparticleorig
, 1 TO 2) DIM vecpuvs.old
(numparticleorig
, 1 TO 2) DIM vecvisiblepuvs
(numparticlevisible
, 1 TO 2) DIM vecvisiblepuvs.old
(numparticlevisible
, 1 TO 2)
' *** Define specialized arrays and structures. ***
' Arrays for tech 2 mesh plotting.
DIM plotflag
(numparticleorig
) DIM plotflag.old
(numparticleorig
)
' *** Set mathematical constants. ***
pi = 3.1415926536
ee = 2.7182818285
mainstart:
' *** Initialize user input variables. ***
'mousekey$ = ""
' *** Process first user input. ***
a$ = "13"
CASE "13": genscheme$
= "wave2d": plotmode$
= "simplemesh"
substart:
' *** Zero counters and array sizes. ***
numparticleorig = 0
numparticlevisible = 0
' *** Constants and switch control. ***
' Perspective and animation switches/defaults.
centerx = screenwidth / 2
centery = screenheight / 2
speedconst = 50
falsedepth = .01
zoom = 30
timevar = 0
T = 0
togglehud = 1
toggleatomnumbers = -1
toggletimeanimate = -1
toggletimealert = 0
camx = 0
camy = 0
camz = 0
uhat(1) = -3: uhat(2) = 5: uhat(3) = 1 / 4
vhat(1) = -1: vhat(2) = -1: vhat(3) = 8
globaldelay = globaldelayinit * 1500
uhat(1) = .7802773: uhat(2) = -.4759201: uhat(3) = .4058135
vhat(1) = .2502121: vhat(2) = .8321912: vhat(3) = .4948249
togglehud = 1
toggletimealert = 1
GOSUB genscheme.wave2d.init
numparticleorig = pcountparticleorig
REDIM vec2dz
(xrange
, yrange
) REDIM vec2dztemp
(xrange
, yrange
) REDIM vec2dzprev
(xrange
, yrange
) GOSUB genscheme.wave2d.gridinit
' Move objects to accomodate initial camera position.
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) + camx
vec(i, 2) = vec(i, 2) + camy
vec(i, 3) = vec(i, 3) + camz
' *** Begin main loop. ***
flagredraw = 1
flagredraw = -1
' *** End main loop. ***
' *** Begin function definitions. ***
' Comment out the conents of this gosub for non-QB64 compiler.
mouseprocess:
keyprocess:
flagredraw = 1
GOSUB rotate.counterclockwise
GOSUB strafe.objects.vhat.plus
GOSUB strafe.camera.vhat.plus
GOSUB strafe.objects.vhat.minus
GOSUB strafe.camera.vhat.minus
uhat(1) = 0: uhat(2) = 1: uhat(3) = 0
vhat(1) = 0: vhat(2) = 0: vhat(3) = 1
uhat(1) = 0: uhat(2) = 0: uhat(3) = 1
vhat(1) = 1: vhat(2) = 0: vhat(3) = 0
uhat(1) = 1: uhat(2) = 0: uhat(3) = 0
vhat(1) = 0: vhat(2) = 1: vhat(3) = 0
toggletimeanimate = -toggletimeanimate
timevar = 0
globaldelay = globaldelay * 1.1
globaldelay = globaldelay * 0.9
globaldelayinit = globaldelay
togglehud = -togglehud
convert:
' Convert graphics from uv-cartesian coordinates to monitor coordinates.
x0 = x: y0 = y
x = x0 + centerx
y = -y0 + centery
' *** Define functions for view translation and rotation. ***
rotate.uhat.plus:
uhat(1) = nhat(1) + speedconst * uhat(1)
uhat(2) = nhat(2) + speedconst * uhat(2)
uhat(3) = nhat(3) + speedconst * uhat(3)
rotate.uhat.minus:
uhat(1) = -nhat(1) + speedconst * uhat(1)
uhat(2) = -nhat(2) + speedconst * uhat(2)
uhat(3) = -nhat(3) + speedconst * uhat(3)
rotate.vhat.plus:
vhat(1) = nhat(1) + speedconst * vhat(1)
vhat(2) = nhat(2) + speedconst * vhat(2)
vhat(3) = nhat(3) + speedconst * vhat(3)
rotate.vhat.minus:
vhat(1) = -nhat(1) + speedconst * vhat(1)
vhat(2) = -nhat(2) + speedconst * vhat(2)
vhat(3) = -nhat(3) + speedconst * vhat(3)
rotate.counterclockwise:
v1 = vhat(1)
v2 = vhat(2)
v3 = vhat(3)
vhat(1) = uhat(1) + speedconst * vhat(1)
vhat(2) = uhat(2) + speedconst * vhat(2)
vhat(3) = uhat(3) + speedconst * vhat(3)
uhat(1) = -v1 + speedconst * uhat(1)
uhat(2) = -v2 + speedconst * uhat(2)
uhat(3) = -v3 + speedconst * uhat(3)
rotate.clockwise:
v1 = vhat(1)
v2 = vhat(2)
v3 = vhat(3)
vhat(1) = -uhat(1) + speedconst * vhat(1)
vhat(2) = -uhat(2) + speedconst * vhat(2)
vhat(3) = -uhat(3) + speedconst * vhat(3)
uhat(1) = v1 + speedconst * uhat(1)
uhat(2) = v2 + speedconst * uhat(2)
uhat(3) = v3 + speedconst * uhat(3)
strafe.objects.uhat.plus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) + uhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) + uhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) + uhat(3) * 1 / zoom
strafe.objects.uhat.minus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) - uhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) - uhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) - uhat(3) * 1 / zoom
strafe.objects.vhat.plus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) + vhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) + vhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) + vhat(3) * 1 / zoom
strafe.objects.vhat.minus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) - vhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) - vhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) - vhat(3) * 1 / zoom
strafe.objects.nhat.plus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) + nhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) + nhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) + nhat(3) * 1 / zoom
strafe.objects.nhat.minus:
FOR i
= 1 TO numparticleorig
vec(i, 1) = vec(i, 1) - nhat(1) * 1 / zoom
vec(i, 2) = vec(i, 2) - nhat(2) * 1 / zoom
vec(i, 3) = vec(i, 3) - nhat(3) * 1 / zoom
strafe.camera.uhat.plus:
camx = camx + uhat(1) * 1 / zoom
camy = camy + uhat(2) * 1 / zoom
camz = camz + uhat(3) * 1 / zoom
strafe.camera.uhat.minus:
camx = camx - uhat(1) * 1 / zoom
camy = camy - uhat(2) * 1 / zoom
camz = camz - uhat(3) * 1 / zoom
strafe.camera.vhat.plus:
camx = camx + vhat(1) * 1 / zoom
camy = camy + vhat(2) * 1 / zoom
camz = camz + vhat(3) * 1 / zoom
strafe.camera.vhat.minus:
camx = camx - vhat(1) * 1 / zoom
camy = camy - vhat(2) * 1 / zoom
camz = camz - vhat(3) * 1 / zoom
strafe.camera.nhat.plus:
camx = camx + nhat(1) * 1 / zoom
camy = camy + nhat(2) * 1 / zoom
camz = camz + nhat(3) * 1 / zoom
strafe.camera.nhat.minus:
camx = camx - nhat(1) * 1 / zoom
camy = camy - nhat(2) * 1 / zoom
camz = camz - nhat(3) * 1 / zoom
' *** Define core functions. ***
timeanimate:
timevar = timevar + 1
IF timevar
> 10 ^ 6 THEN timevar
= 1 CASE "wave2d":
GOSUB genscheme.wave2d.timeanimate
'normalize the two vectors that define the screen orientation
uhatmag
= SQR(uhat
(1) ^ 2 + uhat
(2) ^ 2 + uhat
(3) ^ 2)uhat(1) = uhat(1) / uhatmag: uhat(2) = uhat(2) / uhatmag: uhat(3) = uhat(3) / uhatmag
vhatmag
= SQR(vhat
(1) ^ 2 + vhat
(2) ^ 2 + vhat
(3) ^ 2)vhat(1) = vhat(1) / vhatmag: vhat(2) = vhat(2) / vhatmag: vhat(3) = vhat(3) / vhatmag
uhatdotvhat = uhat(1) * vhat(1) + uhat(2) * vhat(2) + uhat(3) * vhat(3)
'DO: LOOP UNTIL INKEY$ = CHR$(27): END
' Compute the normal vector to the view plane.
' The normal vector points toward the eye, away from view frustum.
nhat(1) = uhat(2) * vhat(3) - uhat(3) * vhat(2)
nhat(2) = uhat(3) * vhat(1) - uhat(1) * vhat(3)
nhat(3) = uhat(1) * vhat(2) - uhat(2) * vhat(1)
nhatmag
= SQR(nhat
(1) ^ 2 + nhat
(2) ^ 2 + nhat
(3) ^ 2)nhat(1) = nhat(1) / nhatmag: nhat(2) = nhat(2) / nhatmag: nhat(3) = nhat(3) / nhatmag
redraw:
' Project the three-space basis vectors onto the screen plane.
xhatp(1) = xhat(1) * uhat(1) + xhat(2) * uhat(2) + xhat(3) * uhat(3)
xhatp(2) = xhat(1) * vhat(1) + xhat(2) * vhat(2) + xhat(3) * vhat(3)
yhatp(1) = yhat(1) * uhat(1) + yhat(2) * uhat(2) + yhat(3) * uhat(3)
yhatp(2) = yhat(1) * vhat(1) + yhat(2) * vhat(2) + yhat(3) * vhat(3)
zhatp(1) = zhat(1) * uhat(1) + zhat(2) * uhat(2) + zhat(3) * uhat(3)
zhatp(2) = zhat(1) * vhat(1) + zhat(2) * vhat(2) + zhat(3) * vhat(3)
GOSUB compute.visible.particles
GOSUB depth.adjust.particles
reverse.uvnhat:
uhat(1) = -uhat(1)
uhat(2) = -uhat(2)
uhat(3) = -uhat(3)
compute.visible.particles:
numparticlevisible = 0
FOR i
= 1 TO numparticleorig
numparticlevisible = numparticlevisible + 1
vecvisible(numparticlevisible, 1) = vec(i, 1)
vecvisible(numparticlevisible, 2) = vec(i, 2)
vecvisible(numparticlevisible, 3) = vec(i, 3)
vecvisible(numparticlevisible, 4) = vec(i, 4)
project.particles:
' Project object vectors onto the screen plane.
FOR i
= 1 TO numparticlevisible
vecvisibledotnhat(i) = vecvisible(i, 1) * nhat(1) + vecvisible(i, 2) * nhat(2) + vecvisible(i, 3) * nhat(3)
vecvisiblepuv(i, 1) = (vecvisible(i, 1) * uhat(1) + vecvisible(i, 2) * uhat(2) + vecvisible(i, 3) * uhat(3))
vecvisiblepuv(i, 2) = (vecvisible(i, 1) * vhat(1) + vecvisible(i, 2) * vhat(2) + vecvisible(i, 3) * vhat(3))
depth.adjust.particles:
FOR i
= 1 TO numparticlevisible
vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * fovd / vecvisibledotnhat(i)
vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * fovd / vecvisibledotnhat(i)
FOR i
= 1 TO numparticlevisible
vecvisiblepuvs(i, 1) = vecvisiblepuv(i, 1) * (1 + falsedepth * vecvisibledotnhat(i))
vecvisiblepuvs(i, 2) = vecvisiblepuv(i, 2) * (1 + falsedepth * vecvisibledotnhat(i))
' Replace basis vector triad.
x
= 50 * xhatp.old
(1): y
= 50 * xhatp.old
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), 0 x
= 50 * yhatp.old
(1): y
= 50 * yhatp.old
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), 0 x
= 50 * zhatp.old
(1): y
= 50 * zhatp.old
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), 0 x
= 50 * xhatp
(1): y
= 50 * xhatp
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), xhat
(4) x
= 50 * yhatp
(1): y
= 50 * yhatp
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), yhat
(4) x
= 50 * zhatp
(1): y
= 50 * zhatp
(2):
GOSUB convert
LINE (centerx
, centery
)-(x
, y
), zhat
(4)
xhatp.old(1) = xhatp(1): xhatp.old(2) = xhatp(2)
yhatp.old(1) = yhatp(1): yhatp.old(2) = yhatp(2)
zhatp.old(1) = zhatp(1): zhatp.old(2) = zhatp(2)
FOR i
= 1 TO numparticlevisible
vecvisiblepuvs.old(i, 1) = vecvisiblepuvs(i, 1)
vecvisiblepuvs.old(i, 2) = vecvisiblepuvs(i, 2)
numparticlevisible.old = numparticlevisible
plotmode.simplemesh:
FOR i
= 1 TO numparticlevisible
- 1 IF i
MOD yrange
<> 0 THEN 'point obeys normal neighbor-connect scheme ' Erase old graphics.
x
= zoom
* vecvisiblepuvs.old
(i
, 1): y
= zoom
* vecvisiblepuvs.old
(i
, 2):
GOSUB convert: x1
= x: y1
= y
x
= zoom
* vecvisiblepuvs.old
(i
+ 1, 1): y
= zoom
* vecvisiblepuvs.old
(i
+ 1, 2):
GOSUB convert: x2
= x: y2
= y
x
= zoom
* vecvisiblepuvs.old
(i
+ yrange
, 1): y
= zoom
* vecvisiblepuvs.old
(i
+ yrange
, 2):
GOSUB convert: x3
= x: y3
= y
LINE (x1
, y1
)-(x2
, y2
), 0 IF i
< (numparticlevisible
- yrange
) THEN LINE (x1
, y1
)-(x3
, y3
), 0 ' Draw new graphics.
x
= zoom
* vecvisiblepuvs
(i
, 1): y
= zoom
* vecvisiblepuvs
(i
, 2):
GOSUB convert: x1
= x: y1
= y
x
= zoom
* vecvisiblepuvs
(i
+ 1, 1): y
= zoom
* vecvisiblepuvs
(i
+ 1, 2):
GOSUB convert: x2
= x: y2
= y
x
= zoom
* vecvisiblepuvs
(i
+ yrange
, 1): y
= zoom
* vecvisiblepuvs
(i
+ yrange
, 2):
GOSUB convert: x3
= x: y3
= y
LINE (x1
, y1
)-(x2
, y2
), vecvisible
(i
, 4) IF i
< (numparticlevisible
- yrange
) THEN LINE (x1
, y1
)-(x3
, y3
), vecvisible
(i
, 4) ELSE 'point does not obey normal neighbor-connect scheme ' Erase old graphics.
x
= zoom
* vecvisiblepuvs.old
(i
, 1): y
= zoom
* vecvisiblepuvs.old
(i
, 2):
GOSUB convert: x1
= x: y1
= y
x
= zoom
* vecvisiblepuvs.old
(i
+ yrange
, 1): y
= zoom
* vecvisiblepuvs.old
(i
+ yrange
, 2):
GOSUB convert: x3
= x: y3
= y
IF i
< (numparticlevisible
- yrange
+ 1) THEN LINE (x1
, y1
)-(x3
, y3
), 0 ' Draw new graphics.
x
= zoom
* vecvisiblepuvs
(i
, 1): y
= zoom
* vecvisiblepuvs
(i
, 2):
GOSUB convert: x1
= x: y1
= y
x
= zoom
* vecvisiblepuvs
(i
+ yrange
, 1): y
= zoom
* vecvisiblepuvs
(i
+ yrange
, 2):
GOSUB convert: x3
= x: y3
= y
IF i
< (numparticlevisible
- yrange
+ 1) THEN LINE (x1
, y1
)-(x3
, y3
), vecvisible
(i
, 4)
genschemeUSAcolors:
'delinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec2dztemp(i, j) = vec(pcountparticleorig, 4)
FOR j
= jj
* yrange
/ 13 + 1 TO (jj
+ 1) * yrange
/ 13 vec2dztemp(i, j) = 4
FOR j
= jj
* yrange
/ 13 + 1 TO (jj
+ 1) * yrange
/ 13 vec2dztemp(i, j) = 7
starflag = -1
FOR i
= 1 TO xrange
* .76 / 1.9 vec2dztemp(i, j) = 15
vec2dztemp(i, j) = 1
starflag = -starflag
'relinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec(pcountparticleorig, 4) = vec2dztemp(i, j)
genscheme.wave2d.init:
xl = -1.9: xr = 1.9
yl = -1: yr = 1
xl = xl * 4: xr = xr * 4: yl = yl * 4: yr = yr * 4
Dx = .32
Dy = .32
xrange
= 1 + INT((-xl
+ xr
) / Dx
)yrange
= 1 + INT((-yl
+ yr
) / Dy
)alpha = .25
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec(pcountparticleorig, 1) = i
vec(pcountparticleorig, 2) = j
vec(pcountparticleorig, 3) = 0
'*' vec(pcountparticleorig, 4) = 14 'use special color scheme
genscheme.wave2d.gridinit:
'delinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec2dztemp(i, j) = vec(pcountparticleorig, 3)
'initial position condition
'FOR i = 1 TO xrange 'random high points
' FOR j = 1 TO yrange
' nrand = RND * 1000
' IF nrand < 10 THEN
' vec2dz(i, j) = 5
' END IF
' NEXT
'NEXT
'vec2dz(xrange * .8, yrange * .2) = -2.5 'single plucked point
'FOR i = 1 TO xrange 'cross arm
' vec2dz(i, yrange / 3) = 2
'NEXT
'FOR j = 1 TO yrange 'cross arm
' vec2dz(xrange / 2, j) = 1
'NEXT
'sync
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec2dzprev(i, j) = vec2dz(i, j)
vec2dztemp(i, j) = vec2dz(i, j)
'initial velocity condition
vec2dzprev(xrange * .8, yrange * .8) = 1.5 'single struck point
'relinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec(pcountparticleorig, 3) = vec2dz(i, j)
genscheme.wave2d.timeanimate:
'delinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec2dztemp(i, j) = vec(pcountparticleorig, 3)
'begin propagation process
FOR i
= 2 TO xrange
- 1 'boDy, no edges wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'comment out this section for fixed edges (or pieces of this section)
i = 1 'left edge
wfp = vec2dztemp(i, j)
wp1 = alpha * (vec2dztemp(i + 1, j) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
i = xrange 'right edge
wfp = vec2dztemp(i, j)
wp1 = alpha * (wfp + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
j = 1 'bottom edge
wfp = vec2dztemp(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + wfp) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
j = yrange 'top edge
wfp = vec2dztemp(i, j)
wp2 = alpha * (wfp + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp1 = alpha * (vec2dztemp(i + 1, j) + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'bottom left corner
i = 1: j = 1
wfp1 = vec2dztemp(i, j)
wfp2 = vec2dztemp(i, j)
wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'bottom right corner
i = xrange: j = 1
wfp1 = vec2dztemp(i, j)
wfp2 = vec2dztemp(i, j)
wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (vec2dztemp(i, j + 1) + wfp2) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'top left corner
i = 1: j = yrange
wfp1 = vec2dztemp(i, j)
wfp2 = vec2dztemp(i, j)
wp1 = alpha * (vec2dztemp(i + 1, j) + wfp1) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
'vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'top right corner
i = xrange: j = yrange
wfp1 = vec2dztemp(i, j)
wfp2 = vec2dztemp(i, j)
wp1 = alpha * (wfp1 + vec2dztemp(i - 1, j)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
wp2 = alpha * (wfp2 + vec2dztemp(i, j - 1)) + 2 * (1 - alpha) * vec2dztemp(i, j) - vec2dzprev(i, j)
vec2dz(i, j) = (1 / 2) * (wp1 + wp2)
'start special movements
T = timevar / 5
IF T
< pi
THEN 'wave left edge just once i = 1
vec2dz
(i
, j
) = (j
/ yrange
) * 1.5 * SIN(T
)IF T
< pi
THEN 'wave bottom edge just once j = 1
vec2dz
(i
, j
) = (i
/ xrange
) * .45 * SIN(T
)'relinearize
pcountparticleorig = 0
pcountparticleorig = pcountparticleorig + 1
vec2dzprev(i, j) = vec2dztemp(i, j)
vec2dztemp(i, j) = vec2dz(i, j)
vec(pcountparticleorig, 3) = vec2dz(i, j)