This site requires JavaScript, please enable it in your browser!
Greenfoot back
wabuilderman
wabuilderman wrote ...

2013/9/19

Help with dynamic grid lighting.

1
2
3
danpost danpost

2013/9/21

#
Change lines 10 and 11 above to this:
if (Math.abs(tint-(255-lightness)*darkness/255) < 8) return;
tint = (255-lightness)*darkness/255;
I think that does it.
danpost danpost

2013/9/24

#
Try limiting the range of darkness and lightness to between 0 and 100 and use the following for the value of tint: tint = 255-255*((100-darkness)+lightness)/200;
Kartoffelbrot Kartoffelbrot

2013/9/24

#
I haven't read all your entries. If my comment is useless ignore it, please. I have used GreenfootImages to create light. I gave them a color, which is a bit transparent. Then I placed them onto all the other actors. Therefore I used an own class. So you can see everything through them, but with the colored "light".
/**
     * draws the lights around the center
     */
    private void drawImage(){
        int lights = help.random(5)+3;
        GreenfootImage n = new GreenfootImage(680,680);
        for(int i = 1; i <= lights; i++){
            GreenfootImage light = new GreenfootImage(this.light);
            n.drawImage(light,(n.getWidth()-light.getWidth())/2, n.getHeight()-light.getHeight());
            n.rotate(360/lights);
        }
        setImage(n);
    }

    /**
     * paints one light image and saves it
     */
    private GreenfootImage getLight(){
        GreenfootImage light = new GreenfootImage(100, 300);
        light.setColor(drawingColor);
        light.fillPolygon(
            new int[]{//x
                0, light.getWidth()/5, light.getWidth()-(light.getWidth()/5), light.getWidth()},
            new int[]{//x
                light.getHeight(), 0, 0, light.getHeight()},
            4);
        int startOfTransparency = 100;
        for(int i = 0; i < startOfTransparency; i++){
            for(int j = 0; j < light.getWidth(); j++){
                int alpha = drawingColor.getAlpha()-(i*2);
                if(alpha<0)
                    alpha = 0;
                Color next = new Color(drawingColor.getRed(), drawingColor.getGreen(),
                        drawingColor.getBlue(), alpha);
                if(light.getColorAt(j, light.getHeight()-startOfTransparency+i).getAlpha()>50)
                //if it isn't transparent already
                    light.setColorAt(j, light.getHeight()-startOfTransparency+i, next);
            }
        }
        light.setTransparency(100);
        return light;
    }
info: this.light is declared in constructor with: light = getLight(); It is a star like circle.
You need to login to post a reply.
1
2
3