sync on : sync rate 0
hide mouse
 
`Some constants
#constant scrY screen height()
#constant scrX screen width()
#constant q = 20.0
#constant a = 0.5
 
`Make a matrix image
ink rgb(0, 0, 100), 0
for y = 1 to scrY
    line 0, a*y^2 - q*y, scrX, a*y^2 - q*y
next y
for x = 1 to scrX * 2
    line -scrX/4 + x*20, 0, -scrX + x*40, scrY
next x
 
get image 1, 0, 0, scrX, scrY, 1
 
`Some globals
global tx1 as integer
global ty1 as integer
global tx2 as integer
global ty2 as integer
global fade# as float
i# = 0.2
 
do
 
    `Background
    cls rgb(0, 0, fade#/4)
    inc fade#, i#
    if fade# => 255.0 then i# = -0.2
    if fade# <= 0.0 then i# = 0.2    
 
    `Paste background
    paste image 1, 0, 0, 1
 
    CalcTile(mousex(), mousey())
    DrawMouse()
 
    sync
loop
 
function CalcTile(x#, y#)
 
    `Get last coordinates
    tx2 = 0
    repeat
 
        `Increase tx2
        inc tx2
 
        `Get triangle coordinates
        fx# = -scrX/4 + (tx2*20)
        tx# = -scrX + (tx2*40)
 
        `Until the point is left of the line
        gx# = tx# + ((fx# - tx#) * (scrY - y#) / scrY)
 
    until gx# > x#
 
    y = 0
    repeat
 
        `Increase ty 2
        inc y
 
        `Get y coordinates
        gy# = a*y^2 - q*y
 
    until gy# > y#
    ty2 = y
 
    tx1 = tx2 - 1
    ty1 = ty2 - 1
 
endfunction
 
function DrawMouse()
 
    `Draw small circle
    ink rgb(255, 255, 255), 0
    circle mousex(), mousey(), 3
 
    `Draw white lines
    ink rgb(0, 0, 50), 0
    x11 = -scrX/4 + tx1*20
    x12 = -scrX + tx1*40
    x21 = -scrX/4 + tx2*20
    x22 = -scrX + tx2*40 
    y1# = a*ty1^2 - q*ty1
    y2# = a*ty2^2 - q*ty2
 
    `Draw after calculating the points
    x1# = x11 + ((x12 - x11) * y1# / scrY)
    x2# = x11 + ((x12 - x11) * y2# / scrY)
    x3# = x21 + ((x22 - x21) * y1# / scrY)
    x4# = x21 + ((x22 - x21) * y2# / scrY)
 
 
    `The box    
 
    `bottom face
    ink rgb(0, 0, 255), 0
    line x1#, y1#, x2#, y2#
    line x2#, y2#, x4#, y2#
    line x3#, y1#, x1#, y1#
    line x4#, y2#, x3#, y1#
 
    `Sides
    h# = (y2# - y1#)*0.75
    line x1#, y1#, x1#, y1# - h#
    line x2#, y2#, x2#, y2# - h#
    line x3#, y1#, x3#, y1# - h#
    line x4#, y2#, x4#, y2# - h#
 
    `Upper face
    line x1#, y1# - h#, x2#, y2# - h#
    line x2#, y2# - h#, x4#, y2# - h#
    line x3#, y1# - h#, x1#, y1# - h#
    line x4#, y2# - h#, x3#, y1# - h#
 
endfunction