ironphoenix20 wrote...
your simulation has a timer for the emboss. can i use your method to make the emboss happen immediately when i press a button?
public static void emboss(BufferedImage bi)
{
int width = bi.getWidth();
int height = bi.getHeight();
BufferedImage copy = deepCopy(bi);
for (int i=0; i<height; i++)
{
for (int j=0; j<width; j++)
{
Color upperLeft = Color.GRAY;
Color lowerRight = Color.GRAY;
if (i > 0 && j > 0)
{
int[] color = unpackPixel(copy.getRGB(j-1, i-1));
upperLeft = new Color(color[1], color[2], color[3], color[0]);
}
if (i < height - 1 && j < width - 1)
{
int[] color = unpackPixel(copy.getRGB(j+1, i+1));
lowerRight = new Color(color[1], color[2], color[3], color[0]);
}
int redDiff = lowerRight.getRed()-upperLeft.getRed();
int greenDiff = lowerRight.getGreen()-upperLeft.getGreen();
int blueDiff = lowerRight.getBlue()-upperLeft.getBlue();
int diff = redDiff;
if (Math.abs(greenDiff) > Math.abs(diff))
{
diff = greenDiff;
}
if (Math.abs(blueDiff) > Math.abs(diff))
{
diff = blueDiff;
}
int grayColor = 128 + diff;
if (grayColor > 255)
{
grayColor = 255;
} else if (grayColor < 0)
{
grayColor = 0;
}
int newColor = packagePixel(redDiff+128, greenDiff+128, blueDiff+128, 255);
copy.setRGB(j, i, newColor);
}
}
}else if (Greenfoot.mouseClicked(emboss)){
if (redoImages.size()>0)
{
redoCount = 0;
redoImages.clear();
}
//if(undoCount>0)
undoImages.add(createGreenfootImageFromBI(deepCopy(image.getBufferedImage())));
undoImages.trimToSize();
Processor.emboss(image.getBufferedImage());
undoCount++;
}System.out.println("Click on 'emboss' detected");