aUCBLogo Demos and Tests / ideal_gas2
			
				
			
			to ideal_gas2
;   norefresh
   cs ht
   setUpdateGraph false
   setScreenColor 0
   n=1000
   x=Array n
   ox=Array n
   v=Array n
   c=Array n
   repeat n
   [   v.repcount=List 4*(rnd-0.5) 4*(rnd-0.5)
      ifelse repcount < n/2
      [   x.repcount=List -200*rnd 400*(rnd-0.5)
         c.repcount=hsb (random 120)-60 0.7 1
      ]
      [   x.repcount=List 200*rnd 400*(rnd-0.5)
         c.repcount=hsb 120+random 120 0.7 1
      ]
   ]
   ox=x+0   ; to create the same structure as in x, so that we can use xcopy and x+=v
   separated=true
   i=0
   t=0
   spur=false
   pr [SPACE toggles cleaning, ENTER toggles separation]
   forever
   [;   t0=timefine
      xcopy "ox x      ; copy only the values (no new nodes are made)
      x+=v         ; dito
      repeat n
      [   if (maxnorm x.repcount) > 290
         [   if (abs first x.repcount) > 290
            [   _setFirst      v.repcount  -(first v.repcount)
            ]
            if (abs first bf x.repcount) > 290
            [   _setFirst bf v.repcount  -( last v.repcount)
            ]
         ]
      ]
      if key? 
      [   ch=readChar
         if ch==char 27 [stop]
         if ch=="\  [spur=not spur]
         if ch==char 13 [separated=not separated]
      ]
      if separated
      [   repeat int n/2
         [   if (first x.repcount) > 0
            [   _setFirst v.repcount  -abs first v.repcount
            ]
            if (first x.(repcount+int n/2)) < 0
            [   _setFirst v.(repcount+int n/2)  abs first v.(repcount+int n/2)
            ]
         ]
      ]
      if not spur [clean]
      setPixel x c
      updateGraph
      gc
   ;   t = (i*t + timefine-t0)/(i+1)
   ;   ct (pr 1/t "frames/sec)
   ;   i+=1
   ]
end