You are here: start » geeny » examples » demos » lightshow

Lightshow

demo_lightshow.jpg

A simple demo.

///////////////////////////////////////////////////////////////////////////////////
BEGIN       object               DEMOLIGHTSHOW
///////////////////////////////////////////////////////////////////////////////////
  OBJECT    Scripta              = @ DEMO_lightshow
  OBJECT    Parent               = APPLET
  ATOM      FSRenderer           = SMOOTHX2
END
                          
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////////////
branch init()
///////////////////////////////////////////////////////////////////////////////////
 
  @.init()
 
  INTEGER  $.raynum    = 80
  
  FLOATS   $.rayspd    = {}
  FLOATS   $.raypos    = {}
  FLOATS   $.raywidth  = {}
  FLOATS   $.raylength = {}
  INTEGERS $.triC      = {} 
  INTEGERS $.triI      = {}
  
  INTEGER i = 0     
  FLOAT cpos          = 0.0
  FLOAT dpos   
  while (i += 1) <= raynum
    rayspd        = rayspd append rand(0.05, 2.55) * rand({-1.0, 1.0})
    dpos          = rand(0.2, 50)
    raypos        = raypos append cpos
    cpos += dpos
    raywidth      = raywidth append dpos
    raylength     = raylength append rand(200.0, 300.0)
    triC          = triC append rendColor(rand(0, 10), rand(0, 10), rand(30, 105))
    triC          = triC append rendColor(rand(30, 105), rand(0, 10), rand(0, 10))
    triC          = triC append rendColor(rand(0, 10), rand(30, 105), rand(0, 10))
    triI          = triI append ({ 0 , 1 , 2 } + (i - 1) * 3)
  endwhile
    
  INTEGERS $.triX      = repeat(20,    3 * raynum)
  INTEGERS $.triY      = repeat(20,    3 * raynum)
end
 
///////////////////////////////////////////////////////////////////////////////////
branch update()
///////////////////////////////////////////////////////////////////////////////////
 
  INTEGER i = 0
  INTEGER t = 1
  while (i += 1) <= raynum
    if (raypos[i] += rayspd[i]) >= 360.0
      raypos[i] -= 360.0
    endif         
    FLOAT p1 = raypos[i]
    FLOAT p2 = raypos[i] + raywidth[i]
    FLOAT x1 = sin rad (p1)
    FLOAT y1 = cos rad (p1)
    FLOAT x2 = sin rad (p2)
    FLOAT y2 = cos rad (p2)
    x1 *= 500
    y1 *= 500
    x2 *= 500
    y2 *= 500
    triX[t] = 320
    triY[t] = 220
    t += 1
    t += 1
    triX[t] = 320 + x2
    triY[t] = 220 + y2
    t += 1
  endwhile
end
 
///////////////////////////////////////////////////////////////////////////////////
 
branch render()       
  rendClear(rendColor(0, 0, 0))
  rendSet()
  rendSetRenderer('ramp')
  rendSetBlending('add')        
  rendSetViewport(40, 40, 600, 440)
  
  rendSetPassColors(1, triC)
  rendTriangles(raynum, triX, triY, triI, 3)
    
  rendSetViewport()
  rendSet()
  rendSetBlending('posterize')
  rendClearPass()
  rendSetPassColor(1, 5)
  rendFill(80, 80, 560, 400)
end                 
 
///////////////////////////////////////////////////////////////////////////////////
 
geeny/examples/demos/lightshow.txt · Last modified: 2015/11/18 07:37 by matija
Recent changes · Show pagesource · Login