space-invader-generator


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
A model that generates space-invader-like blocks of pixels.

Procedures

NetLogo Version: NetLogo 4.0.4

globals
[ n m pow2
]
to setup
   ca
   set n min-pxcor + 1
   set m max-pycor - 1
   
   ;; build powers of 2
   ;; [ 2^0 2^1 2^2,...,2^16]
   set pow2 [ 1 ]
   repeat 18
   [ set pow2 fput ((first pow2) * 2) pow2
   ]
   set pow2 reverse pow2
   output-print pow2
end

to startup setup end


to go

   let bits (floor bytes / 2) + 1
   let wird bytes + margin
   every delay
   [ 
   cp
   set n min-pxcor + margin
   set m max-pycor - margin
   repeat floor ((world-width - margin) / (wird) ) * floor ( (world-height - margin ) / (wird) )
   [
     let data n-values bytes [ get-bits bits]
     draw-space-inv m n data
     set n n + wird
     if n > max-pxcor - wird + 1
     [ set n min-pxcor + margin
       set m m - wird
       if m < min-pycor + wird - 1
       [ set m min-pycor - margin ]
     ]
   ]
   tick
   ]
end

to-report get-bits [ bits ]
   let source random (item bits pow2)
   let result []
   repeat bits
   [ set result fput (source mod 2) result
     set source floor ( source / 2)
   ] 
  report result
end
  
to draw-space-inv [ row col data ]    
   let i 0
   
   foreach data
   [ ;; ? is a row
     let j 0
     let c  [ ] 
     foreach ?
     [ ;; ? is a bit
       let v  ?
       let cc 0
       ifelse color?
       [ set cc 15 + random 12 * 10 ]
       [ set cc 9.9 * random 2 ]
       
       ask patch (col + j) (row - i) [ set pcolor cc * v ]
       set c fput cc c
       set j j + 1
     ]
     foreach but-first reverse ?
     [ ;; ? is a bit
       let v  ?
       set c but-first c
       let cc first c
       ask patch (col + j) (row - i) [ set pcolor cc * v ]
       set j j + 1
     ]

     set i i + 1
   ]   
end     

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download space-invader-generator --