//*********************************************************************************
//                          SPARK Wrapper Rain Demo
//                   Demonstrating the Line Trail Renderer
//*********************************************************************************

autocam off

// first we create a small floor
make object box 1,100,1,100
position object 1,0,-5,0
load image "media\concwall05.bmp" ,1
texture object 1,1
scale object texture 1,4,4


color backdrop rgb(80,90,100)

//  This sytem will use 2 groups and 2 different renderers

RainSystem = sp create system (0,0,0,0)

// we add 2 groups to our rain system

RainGroup1 = sp add group (RainSystem , 600 , 0.01 ,0,0,0)
RainGroup2 = sp add group (RainSystem , 800 , 0.01 ,0,0,0)

// we add line trail renderers to both groups , but one will renderer
// shorter and less visible lines , because we want different raindrops
// to keep our system realistic.

lineRenderer1 = sp set line trail renderer (RainGroup1 , 3 , 0.024 , BLEND_ADD)
lineRenderer2 = sp set line trail renderer (RainGroup2 , 3 , 0.038 , BLEND_ADD)

// we dont need any fade out effect or scale or anything dynamic so
// we use a "default initilizer" rgba interpolator which will set aour color
// and alpha to constant value

rgba1 = sp add rgba interpolator (RainGroup1 , sp rgba (152,189,203,63))

// we set the RainGroup2's color a bit different

rgba2 = sp add rgba interpolator (RainGroup2 , sp rgba (152,189,213,58))

// we add spheric emitters to our groups with a very large box zone.
// This box zone will be shared between this 2 emitters

rainZone = sp box zone (0,0,0,50,50,50)

emitter1 = sp add spheric emitter (RainGroup1 ,0,-1,0, 0.05 , 0.1 ,350 , 50 , 100 , -1 ,rainZone)
emitter2 = sp add spheric emitter (RainGroup2 ,0,-1,0, 0.02 , 0.07 ,550 , 100 , 150 , -1 ,rainZone)


sp position system RainSystem ,0,50,0


// and we add some code to change our rain parameters . NOTE: pressing
// random keys from 1 to 6 will change youre rain into snow :D


do
    control camera using arrowkeys 0,0.02,0.1
    
    set cursor 0,0
    print " +/- increase / decrease rain intensity "
    print "1-2 increase / decrease raindrop lenght"
    print "3-4 increase / decrease force "
    print "5-6 change alpha of the rain "
    
   
    if inkey$() = "+"
        flow1# = flow1# + 1 : flow2# = flow2# + 2
        
        if flow1# > 250 then flow1# = 350
        if flow2# > 450 then flow2# = 550
       
        sp set emitter flow emitter1 , flow1#
        sp set emitter flow emitter2 , flow2#
        
    endif
    
    
        
    if inkey$() = "-"
    
        flow1# = flow1# - 1 : flow2# = flow2# - 2
        
        if flow1# < 20 then flow1# = 20
        if flow2# < 30 then flow2# = 30
        
        sp set emitter flow emitter1 , flow1#
        sp set emitter flow emitter2 , flow2#
        
    endif
    
    
    // increase decrease duration 
    
    if inkey$ () = "1"
        duration1# = duration1#+0.0001
        duration2# = duration2#+0.0003          
        sp set line trail duration lineRenderer1 , duration1# 
        sp set line trail duration lineRenderer2 , duration2# 
    endif
    
    
    if inkey$ () = "2"
        duration1# = duration1#-0.0001
        duration2# = duration2#-0.0003  
        if duration1#<0.0001 then duration1# =  0.0001
        if duration2#<0.0003 then duration2# =  0.0003
        sp set line trail duration lineRenderer1 , duration1# 
        sp set line trail duration lineRenderer2 , duration2# 
    endif
    
    
    // set force
    
    
    if inkey$ () = "3"
        force# = force#+1          
        sp set emitter force emitter1 , force# ,force#+50
        sp set emitter force emitter2 , force# ,force#+50
    endif
    
    
    if inkey$ () = "4"
        force# = force#-1
        if force#<10 then force# = 10          
        sp set emitter force emitter1 , force# ,force#+50
        sp set emitter force emitter2 , force# ,force#+50
    endif
    
    
    
    // set alpha
    
    
    if inkey$ () = "5"
        alpha = alpha+1          
        if alpha >255 then alpha=255
        sp change color rgba1 , sp rgba (152,189,203,alpha)
        sp change color rgba2 , sp rgba (152,189,203,alpha)
        
    endif
    
    
    if inkey$ () = "6"
        alpha = alpha-1          
        if alpha <5 then alpha=5
        sp change color rgba1 , sp rgba (152,189,203,alpha)
        sp change color rgba2 , sp rgba (152,189,203,alpha)
        
    endif
    
    
    sp update
    
    
    
loop
    


















