package graphtest; import java.awt.*; import java.awt.image.*; import javax.swing.*; class Graphtest extends JFrame { private int w = 255, h = 255, j; private int[] pix = new int[w*h]; private Image img; MemoryImageSource mis; Graphtest (String s) { super(s); mis = new MemoryImageSource(w, h, pix, 0, w); // задати можливість анімації mis.setAnimated(true); img = createImage(mis); setSize(275, 300); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } @Override public void paint(Graphics gr) { gr.drawImage(img, 10, 35, this); } public void go() { while(j < 256*2) { int i = 0; // зміна інтенсивностей кольорів пікселів for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) pix [i++] = (255 << 24)| ((int) (127.999*((1+Math.cos( ((float) (x-j))/50.)))) << 16)| // червоний ((int) (127.999*((1+Math.cos( ((float) (y-j))/50.)))) << 8)| // зелений 0; // блакитний // Сповіщення споживача про зміни mis.newPixels(); try {Thread.sleep(10);} catch(InterruptedException e) {} j++; } } public static void main(String[] args) { Graphtest f = new Graphtest ("MemoryImageSource"); f.go (); } }