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

2019/7/23

Dematerializing image

GingaSnap GingaSnap

2019/7/23

#
Hello, i'm trying to experiment with image manipulation and I'm trying to get the effect of an image dematerializing by randomly setting each individual pixel transparent until the entire image is transparent. It works but it takes way too long for the entire image to become completely transparent as it only checks one pixel at a time. Here is the code I have been using. Are there any recommendations on what I should change/add?
 public void dematerialize()
    {
        int w = getImage().getWidth();
        int h = getImage().getHeight();
        int randW= Greenfoot.getRandomNumber(w);
        int randH=Greenfoot.getRandomNumber(h);
        Color transparent = new Color(255,255,255,0);

        if(getImage().getColorAt(randW,randH)!=transparent)
            getImage().setColorAt(randW, randH, transparent);

    }
danpost danpost

2019/7/23

#
You could use a for loop to remove multiple pixels at a time. However, the two big problems would be (1) as pixels get removed, the chance lessens in hitting one that needs removed; and (2) determining when ALL pixels have been removed would not be an easy matter. Fading might be a favorable alternative -- gradually diminishing the transparency of the entire image. Or, maybe a combination of the two -- that way, at least the time for total removal is limited to a specific amount.
You need to login to post a reply.