'Moving into the Matrix Rain
'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
DIM SHARED charImg
(74) AS LONG, matRainWidth
, matRainHeight
'ascii char from 48 to 122, i.e, total 75 type of chars
glAllow = -1
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 matrixRain
(i
).z
> 0.1 THEN 'when behind screen matrixRain(i).x = p5random(-2, 2)
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)
mov = mov + 0.01
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(-2, 2)
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
_glRotatef SIN(mov
) * 20, 1, 0, 0 'rotating x-axis a bit, just to get Depth effect.
'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!
p5random!
= RND * (mx!
- mn!
) + mn!