Good morning
I just took over the plasma effect project
I'll give you my code, it will be simpler
I actually got rid of the bufferedimage
the code works but I have a little trouble with the if
for the moment the colors are displayed in full window
but do not give color spots
but this is due to the plasma, I think?
Thank you for your help
import greenfoot.*; /** * Plasma_Effect * * @author (Ronald) * @version (Plasma_Effect) */ public class PlasmaEffectWorld extends World { float[][] plasma; float hueShift = 255; private int timer = 42; GreenfootImage background = getBackground(); public PlasmaEffectWorld() { super(600, 600, 1); background.setColor(Color.WHITE); background = new GreenfootImage(getWidth(), getHeight()); plasma = createPlasma(getHeight(), getWidth()); } public void act() { timer--; if (timer == 0) { hueShift = (hueShift + 0.02f) % 1; repaint(); } started(); drawPlasma(); } public float[][] createPlasma(int w, int h) { float[][] buffer = new float[h][w]; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { double value = Math.sin(x / 16.0); value += Math.sin(y / 8.0); value += Math.sin((x + y) / 16.0); value += Math.sin(Math.sqrt(x * x + y * y) / 8.0); value += 4; // shift range from -4 .. 4 to 0 .. 8 value /= 8; // bring range down to 0 .. 1 // requires VM option -ea assert (value >= 0.0 && value <= 1.0) : "Hue value out of bounds"; buffer[y][x] = (float) value; } return buffer; } public void drawPlasma() { GreenfootImage gfim = new GreenfootImage(getWidth(), getHeight()); int h = plasma.length; int w = plasma[0].length; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { //float hue = hueShift + plasma[y][x] % 1; //img.setRGB(x, y, Color.HSBtoRGB(hue, 1, 1)); //Color color = new Color((int) hueShift + (int) plasma[y][x] % 1,1,1); //background.setColorAt(x, y, color); float hue = hueShift + plasma[y][x] % 1; Color red = new Color((int) hueShift + (int) plasma[y][x] % 1,1,1); Color green = new Color(1, (int) hueShift + (int) plasma[y][x] % 1,1); Color blue = new Color(1, 1, (int) hueShift + (int) plasma[y][x] % 1); if (hueShift <= 255) background.setColorAt(x, y, red); //Color.CYAN else if (hueShift <= 170) background.setColorAt(x, y, green); //Color.LIGHT_GRAY); else background.setColorAt(x, y, blue); //Color.GRAY); } gfim.drawImage(background, 0, 0); setBackground(gfim); } }