Below are a couple of functions which can come in handy if one wants to flash the screen, simply fade it, or de-fade it! It can be integrated into any program, on condition that the camera used is the default one (0). Also, the object number 1 has to be free, but if it isn't just modify the code a bit. Anyway, here are the functions with an example :
set ambient light 100
REM - SAMPLE OBJECT TO LOOK AT
make object sphere 2, 50
REM - EXAMPLE OF A MAIN LOOP USING THE FUNCTIONS
do
ink rgb(255, 100, 100), rgb(0, 0, 0)
text 0, 0, "To fade screen, press ENTER, to defade, press SHIFT,"
text 0, 10, "and to flash the screen, press CTRL"
if returnkey()=1
fade_screen(10)
endif
if shiftkey()=1
defade_screen(10)
endif
if controlkey()=1
flash_screen(10)
endif
loop
REM - BELOW ARE THE THREE FUNCTIONS - FEEL FREE TO MODIFY THEM AT YOUR WILL. -------
REM --------------------------------------------------------------------------------
REM --------------------------------------------------------------------------------
REM - THE SPEED IS PROCESSOR TIME ELAPSED BETWEEN TWO LOOPS - THE LESS THIS VALUE THE
REM - FASTER THE EFFECT WILL BE
REM - THE 'SET AMBIENT LIGHT 100' ENSURES THE DUMMY OBJECT IS WHITE, IF YOU
REM - SET IT TO LOWER VALUES, THE SCREEN WILL HAVE A MORE GRAYISH COLOUR
function fade_screen(speed)
set ambient light 100
REM - THE DUMMY OBJECT
if not object exist(1)
autocam off
make object plain 1, screen width(), screen height()
color object 1, rgb(255,255,255)
position object 1, camera position x()+200, camera position y(), camera position z()+100
lock object on 1
xrotate object 1, 16
endif
REM - THE EFFECT
for t=0 to 99 step 1
set alpha mapping on 1, t
wait speed
next t
endfunction
REM --------------------------------------------------------------------------------
function defade_screen(speed)
set ambient light 100
REM - THE DUMMY OBJECT
if not object exist(1)
autocam off
make object plain 1, screen width(), screen height()
color object 1, rgb(255,255,255)
position object 1, camera position x()+200, camera position y(), camera position z()+100
lock object on 1
xrotate object 1, 16
endif
REM - THE EFFECT
for t=100 to 0 step -1
set alpha mapping on 1, t
wait speed
next t
endfunction
REM --------------------------------------------------------------------------------
function flash_screen(speed)
set ambient light 100
REM - THE DUMMY OBJECT
if not object exist(1)
autocam off
make object plain 1, screen width(), screen height()
color object 1, rgb(255,255,255)
position object 1, camera position x()+200, camera position y(), camera position z()+100
lock object on 1
xrotate object 1, 16
endif
REM - THE EFFECT
for t=0 to 99 step 1
set alpha mapping on 1, t
wait speed
next t
for t=100 to 0 step -1
set alpha mapping on 1, t
wait speed
next t
endfunction