'Moving into the Matrix Rain
'MOD : Supports navigation from keyboard. For TempodiBasic (25 Jun, 2019)
'By Ashish Kushwaha
'23 Jun, 2019
'
'Inspire by B+ Matrix Rain.
_TITLE "Moving into the Matrix Rain"
strData
AS STRING 'string data of each matrix rain
' y as single
DIM SHARED charImg
(74) AS LONG, matRainWidth
, matRainHeight
'ascii char from 48 to 122, i.e, total 75 type of chars
glAllow = -1
currLoc.z = 0 : currLoc.x = 0
matrixRain(i).y = matrixRain(i).y - matrixRain(i).ay
d$ = ""
d$
= d$
+ CHR$(48 + p5random
(0, 74)) 'change the character of rain randomly by a chance of 10% matrixRain(i).strData = d$
' matrixRain(i).z = matrixRain(i).z + 0.00566 'move into the rain
if currLoc.z
= -1 then matrixRain
(i
).z
= matrixRain
(i
).z
+ 0.00766 if currLoc.z
= 1 then matrixRain
(i
).z
= matrixRain
(i
).z
- 0.00766 if currLoc.x
= -1 then matrixRain
(i
).x
= matrixRain
(i
).x
+ 0.00766 if currLoc.x
= 1 then matrixRain
(i
).x
= matrixRain
(i
).x
- 0.00766
IF matrixRain
(i
).z
> 0.1 or matrixRain
(i
).z
<-8 or matrixRain
(i
).x
>3 or matrixRain
(I
).x
<-3 THEN 'when behind screen matrixRain(i).x = p5random(-3, 3)
matrixRain(i).y = p5random(2, 3.7)
matrixRain
(i
).z
= map
((i
/ UBOUND(matrixRain
)), 0, 1, -8, -0.2) matrixRain(i).ay = p5random(0.006, 0.02)
glInit = 1
FOR i
= 0 TO UBOUND(matrixRainTex
) 'create texture for each ascii character
n = p5random(1, 15)
v$
= CHR$(p5random
(48, 122)) matrixRain(i).strData = matrixRain(i).strData + v$
matrixRain(i).x = p5random(-3, 3)
matrixRain(i).y = p5random(2, 3.7)
matrixRain
(i
).z
= map
((i
/ UBOUND(matrixRain
)), 0, 1, -8, -0.2) matrixRain(i).ay = p5random(0.006, 0.02)
_glEnable _GL_BLEND
'enabling necessary stuff
_glClear _GL_COLOR_BUFFER_BIT
OR _GL_DEPTH_BUFFER_BIT
'rendering the rain
n
= LEN(matrixRain
(i
).strData
) ca$
= MID$(matrixRain
(i
).strData
, j
, 1) 'selecting texture on the basis of ascii code.
_glVertex3f matrixRain
(i
).x
- matRainWidth
, matrixRain
(i
).y
- matRainHeight
+ 2 * (j
- 1) * matRainHeight
, matrixRain
(i
).z
_glVertex3f matrixRain
(i
).x
- matRainWidth
, matrixRain
(i
).y
+ matRainHeight
+ 2 * (j
- 1) * matRainHeight
, matrixRain
(i
).z
_glVertex3f matrixRain
(i
).x
+ matRainWidth
, matrixRain
(i
).y
+ matRainHeight
+ 2 * (j
- 1) * matRainHeight
, matrixRain
(i
).z
_glVertex3f matrixRain
(i
).x
+ matRainWidth
, matrixRain
(i
).y
- matRainHeight
+ 2 * (j
- 1) * matRainHeight
, matrixRain
(i
).z
'taken from p5js.bas
'https://bit.ly/p5jsbas
FUNCTION map!
(value!
, minRange!
, maxRange!
, newMinRange!
, newMaxRange!
) map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
' IF mn! > mx! THEN
' SWAP mn!, mx!
' END IF
p5random!
= RND * (mx!
- mn!
) + mn!