Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Steel Wool
#7
Add  interactivity
     UP/DOWN to zoom in/out  
     F to set fire
     Try to hold F longer or shorter
     Watch how black turn to grey when F is not pressed

Code:
'=========================================
' Control Keys
' - UP / DOWN : zoom in/out
' - F         : try to press long enough
' - ESC       : quit
'
' Logs :
' -2D burning forest simulation
' -Steel Wool in N7 by Johnno
' -Some modification in N7 by Micha
'==========================================


'----------------
' INITIALIZATION
'----------------
#win32
set window "Steel Wool", 500, 300, false,2
set redraw off
randomize clock()

'color definition
white = [255,255,255]
black = [0,0,0]
grey  = [64,64,64]

'cells of array
f1 = dim(width()/3, height()/3)
f2 = dim(width()/3, height()/3)

'variables
s = 1            'scale
pressF = "false" 'keypress F


'-----------
' MAIN LOOP
'-----------
do
    'color
    fire = [255, 128 + rnd(128), 0]

    'clear screen
    set color black;cls
   
    'interactivity
    if keydown(KEY_UP,true) then s = min(s + 1,20)
    if keydown(KEY_DOWN,true) then s = max(s - 1,1)
   
    'color changing      
    for x = 0 to width()/3-2
        for y = 0 to height()/3-2
       
            'less than 3% black turn to grey
            if not f1[x][y] and rnd(1000)/1000 < 0.03 then
                f2[x][y] = 1
            endif
           
            'fire turn to black
            if f1[x][y] = 2 then
                f2[x][y] = 0
            endif
           
            'selected grey turn to fire
            if f1[x][y] = 1 and keydown(KEY_F) then
                pressF = "true"
                if (f1[x - 1][y - 1] = 2 or f1[x][y - 1] = 2 or f1[x + 1][y - 1] = 2) or  
                   (f1[x - 1][y] = 2 or f1[x + 1][y] = 2 or f2[x][y]=2  or rnd(10000)/10000 < 0.00003) or     
                   (f1[x - 1][y + 1] = 2 or f1[x][y + 1] = 2 or f1[x + 1][y + 1] = 2) then  
                        f2[x][y] = 2
                endif
            else
                pressF = "false"
            endif

            'set the fire now !!!
            if f2[x][y] = 0     set color black
            if f2[x][y] = 1     set color grey
            if f2[x][y] = 2     set color fire
            draw rect (x-1)*s , (y-1)*s , s, s, false
   
        next
    next
   
    for x = 1 to width()/3-2
        for y = 1 to height()/3-2
            f1[x][y] = f2[x][y]
        next
    next

    'info box
    set color white
    set caret 10,10
    wln "Scale :"+s
    wln "F     :"+pressF
    set caret 10,height()-80
    wln "UP/DOWN to zoom in/out" 
    wln "F to set fire"
    wln "Try to hold F longer or shorter"
    wln "watch how black turn to grey when F is not pressed"
      
    redraw
    fwait 15
until keydown(KEY_ESCAPE, true)
Reply


Messages In This Thread
Steel Wool - by johnno56 - 12-05-2024, 09:31 AM
RE: Steel Wool - by oskarg - 12-05-2024, 06:49 PM
RE: Steel Wool - by johnno56 - 12-05-2024, 07:36 PM
RE: Steel Wool - by 1micha.elok - 12-06-2024, 03:06 AM
RE: Steel Wool - by johnno56 - 12-06-2024, 03:31 AM
RE: Steel Wool - by Marcus - 12-06-2024, 04:54 PM
RE: Steel Wool - by 1micha.elok - 12-07-2024, 08:33 AM
RE: Steel Wool - by johnno56 - 12-07-2024, 12:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)