Guest User

Untitled

a guest
Apr 6th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import java.applet.*;
  2. import java.awt.*;
  3.  
  4.  
  5. public class BasicApplet extends Applet {
  6. private static final long serialVersionUID = 1L;
  7.  
  8. private final int FACTOR = 3;
  9. private final int BORDER = 16;
  10.  
  11.  
  12. private final float sunR = 1.0f;
  13. private final float sunG = 1.0f;
  14. private final float sunB = 1.0f;
  15. private final float moonR = 0.0f;
  16. private final float moonG = 0.0f;
  17. private final float moonB = 0.2f;
  18.  
  19. private final int DAYLIGHT_TICKS = 24000;
  20. private int time = 15000;
  21.  
  22. public void init()
  23. {
  24. setSize(2*BORDER+16*16*FACTOR, 2*BORDER+16*16*FACTOR);
  25. setBackground(Color.WHITE);
  26. }
  27.  
  28. public void paint(Graphics p)
  29. {
  30. for (int r=0; r<16; r++) { //X
  31. for (int sun=0; sun<16; sun++){ //Y
  32. for (int b=0; b<16; b++) { //x
  33. for (int g=0; g<16; g++) { //y
  34.  
  35. setColor(p,sun,r,g,b,time);
  36.  
  37. //p.fillRect((b*16*FACTOR+sun*FACTOR),(16*16*FACTOR-r*16*FACTOR-g*FACTOR-FACTOR),FACTOR,FACTOR);
  38. p.fillRect((BORDER + g*16*FACTOR+r*FACTOR),(BORDER + 16*16*FACTOR-sun*16*FACTOR-b*FACTOR),FACTOR,FACTOR);
  39. }
  40. }
  41. }
  42. }
  43. time+=250;
  44. if (time > DAYLIGHT_TICKS)
  45. time = 0;
  46. System.out.println(time);
  47.  
  48. try {
  49. Thread.sleep(300);
  50. } catch (InterruptedException e) {
  51. e.printStackTrace();
  52. }
  53.  
  54. repaint();
  55. }
  56.  
  57. public void setColor(Graphics p, int sun, int cr, int cg, int cb, int time) {
  58. float dayMultiplier = Math.abs((float)Math.abs(time-3000)-12000)/12000;
  59. float nightMultiplier = Math.abs((float)Math.abs(time-15000)-12000)/12000;
  60. float s = (float)sun/15f;
  61. s = s*s; //BAM!
  62. float r = s*(sunR*dayMultiplier + moonR*nightMultiplier) + (float)cr/16f;
  63. float g = s*(sunG*dayMultiplier + moonG*nightMultiplier) + (float)cg/17f;
  64. float b = s*(sunB*dayMultiplier + moonB*nightMultiplier) + (float)cb/15f;
  65.  
  66. if (r>1.0f)
  67. r = 1.0f;
  68. if (r<0.0f)
  69. r = 0.0f;
  70. if (g>1.0f)
  71. g = 1.0f;
  72. if (g<0.0f)
  73. g = 0.0f;
  74. if (b>1.0f)
  75. b = 1.0f;
  76. if (b<0.0f)
  77. b = 0.0f;
  78.  
  79. p.setColor(new Color(r,g,b));
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment