Advertisement
tyridge77

LightRender

Feb 17th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. if(pixelcolor!=null)
  2.     {
  3.       g.fillRect(x,y,PixelSize,PixelSize);
  4.    
  5.  
  6.        
  7.              LightSource light = getNearestLightSource(pixelpoint);
  8.              light.Brightness =(float) clamp((float)Math.sin(tick)*1,0.0f,1.0f);
  9.              int red = (int) (pixelcolor.getRed());
  10.              int green = (int) (pixelcolor.getGreen());
  11.              int blue = (int) (pixelcolor.getBlue());
  12.              
  13.              
  14.              if(light!=null)                   
  15.              {
  16.               float lightbrightness = light.Brightness;
  17.               float distance_from_lightsource = (float) pixelpoint.distance(light.location);
  18.               float brightperc = (1-(clamp(distance_from_lightsource/light.Range,0.0f,1.0f)))*lightbrightness;
  19.              
  20.                
  21.            
  22.               red = (int) clamp((red*brightperc*lightbrightness),0.0f,255.0f);
  23.               green = (int) clamp((green*brightperc*lightbrightness),0.0f,255.0f);
  24.               blue = (int) clamp((blue*brightperc*lightbrightness),0.0f,255.0f);
  25.              
  26.              
  27.               g.setColor(new Color(red,green,blue));
  28.  
  29.              }
  30.              else       // There is no light nearby
  31.              {
  32.               g.setColor(Color.BLACK);
  33.              }
  34.          }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement