Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.applet.*;
- import java.awt.*;
- public class BasicApplet extends Applet {
- private static final long serialVersionUID = 1L;
- private final int FACTOR = 3;
- private final int BORDER = 16;
- private final float sunR = 1.0f;
- private final float sunG = 1.0f;
- private final float sunB = 1.0f;
- private final float moonR = 0.0f;
- private final float moonG = 0.0f;
- private final float moonB = 0.2f;
- private final int DAYLIGHT_TICKS = 24000;
- private int time = 15000;
- public void init()
- {
- setSize(2*BORDER+16*16*FACTOR, 2*BORDER+16*16*FACTOR);
- setBackground(Color.WHITE);
- }
- public void paint(Graphics p)
- {
- for (int r=0; r<16; r++) { //X
- for (int sun=0; sun<16; sun++){ //Y
- for (int b=0; b<16; b++) { //x
- for (int g=0; g<16; g++) { //y
- setColor(p,sun,r,g,b,time);
- //p.fillRect((b*16*FACTOR+sun*FACTOR),(16*16*FACTOR-r*16*FACTOR-g*FACTOR-FACTOR),FACTOR,FACTOR);
- p.fillRect((BORDER + g*16*FACTOR+r*FACTOR),(BORDER + 16*16*FACTOR-sun*16*FACTOR-b*FACTOR),FACTOR,FACTOR);
- }
- }
- }
- }
- time+=250;
- if (time > DAYLIGHT_TICKS)
- time = 0;
- System.out.println(time);
- try {
- Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- repaint();
- }
- public void setColor(Graphics p, int sun, int cr, int cg, int cb, int time) {
- float dayMultiplier = Math.abs((float)Math.abs(time-3000)-12000)/12000;
- float nightMultiplier = Math.abs((float)Math.abs(time-15000)-12000)/12000;
- float s = (float)sun/15f;
- s = s*s; //BAM!
- float r = s*(sunR*dayMultiplier + moonR*nightMultiplier) + (float)cr/16f;
- float g = s*(sunG*dayMultiplier + moonG*nightMultiplier) + (float)cg/17f;
- float b = s*(sunB*dayMultiplier + moonB*nightMultiplier) + (float)cb/15f;
- if (r>1.0f)
- r = 1.0f;
- if (r<0.0f)
- r = 0.0f;
- if (g>1.0f)
- g = 1.0f;
- if (g<0.0f)
- g = 0.0f;
- if (b>1.0f)
- b = 1.0f;
- if (b<0.0f)
- b = 0.0f;
- p.setColor(new Color(r,g,b));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment