UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on March 09, 2011, 10:45:53 PM

Title: Gouraud Radar
Post by: kevin on March 09, 2011, 10:45:53 PM
  Gouraud Radar


    This little demo draws a glowing radar like effect.  It's drawn using gouruad shaded triangles, the colouring works by first calculating the difference between the current angle (while it's drawing the circle) and the needle highlight angle. This difference is then used to scale the colours at the current point,  so the further away from the needle from the current sector is the darker i'll be, the closer to the needle the brighter it'll get.


[pbcode]

   screen=newimage(800,600,2)

   Type tThrob
         x,y
         Radius
         colour
         angle#   
   Endtype
   Dim Throb as tThrob list

         
   For lp=1 to 10
      Throb=new tThrob
      Throb.x=rnd(GetSurfaceWidth())
      Throb.y=rnd(GetSurfaceHeight())
      Throb.radius=rndrange(50,250)
      Throb.angle#=rnd(360)
   Next

   setfps 50
   Do

      RenderToImage screen

      cls $305090

      for each Throb()
         x#=throb.x
         y#=throb.y
         Radius#=throb.Radius
         Angle#=throb.Angle
         Radar(x#,y#,Radius#,angle#)
         throb.Angle=wrapangle(angle#+2)
      next      


         
      RenderToScreen
      drawimage screen,0,0,false   

      Sync
   loop


Function Radar(X,Y,Radius#,HighlightAngle#)
   Sectors=100
   AngleStep#=360.0/Sectors

   inkmode 1+64
   lockbuffer
   For lp=0 to sectors-1

      angle1#=wrapangle(AngleStep#*lp)
      x1=x+cosradius(angle1#,radius#)
      y1=y+sinRadius(angle1#,radius#)

      angle2#=wrapangle(AngleStep#*(lp+1))
      x2=x+cosradius(angle2#,radius#)
      y2=y+sinRadius(angle2#,radius#)


      anglediff#=angledifference(angle1#,highlightangle#)  

      Scaler#=1-(anglediff#/240.0)
      highlightcolour=rgbfade(rgb(255,255,255),scaler#*100)

      Rgb1=rgbalphamult(rgb(200, 130, 50),highlightcolour)
      Rgb2=rgbalphamult(rgb(000, 00, 00),highlightcolour)

      gouraudtri x,y,rgb1,x1,y1,rgb2,x2,y2,rgb2

   next
   unlockbuffer
   inkmode 1

EndFunction



[/pbcode]