Created
September 6, 2013 08:50
-
-
Save AnimeshShaw/6461240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.applet.*; | |
import java.awt.image.*; | |
public class PixeloMatic extends Applet implements Runnable { | |
int pixl2[] = new int[256]; | |
Thread t = null; | |
final int width=500, height=500; | |
Image buffer = null; | |
int pixl1[],pixlook[]; | |
@Override | |
public void init() { | |
setSize(500, 500); | |
int r, g, b, i; | |
pixl1 = new int[width * height]; | |
pixlook = new int[width * height]; | |
for (i = 0; i < 256; i++) { | |
r = (int) (128 + 128 * Math.sin(Math.PI * i / 32.0)); | |
g = (int) (128 + 128 * Math.sin(Math.PI * i / 64.0)); | |
b = (int) (128 + 128 * Math.sin(Math.PI * i / 128.0)); | |
pixl2[i] = (255 << 24) | (r << 16) | (g << 8) | b; | |
} | |
for (r = 0; r < height; r++) { | |
for (g = 0; g < width; g++) { | |
i = (int) (128 + 128 * Math.sin(r / 16.0) + 128 + 128 * Math.sin(g / 16.0)); | |
i = i / 2; | |
pixlook[g + r * height] = i; | |
} | |
} | |
} | |
@Override | |
public void start() { | |
t = new Thread(this); | |
t.start(); | |
} | |
@Override | |
public void run() { | |
while(true) { | |
try { | |
repaint(); | |
Thread.sleep(2); | |
} catch (InterruptedException e) { | |
} | |
} | |
} | |
@Override | |
public void stop() { | |
t = null; | |
} | |
@Override | |
public void paint(Graphics g) { | |
update(g); | |
} | |
@Override | |
public void update(Graphics g) { | |
int i, x, y, t; | |
for (y = 0; y < height; y++) { | |
for (x = 0; x < width; x++) { | |
t = x + y * height; | |
pixl1[t] = pixl2[pixlook[t]]; | |
} | |
} | |
buffer = createImage(new MemoryImageSource(width, height, pixl1, 0, width)); | |
g.drawImage(buffer, 0, 0, this); | |
int tmp; | |
tmp = pixl2[0]; | |
for (i = 1; i < 256; i++) { | |
pixl2[i - 1] = pixl2[i]; | |
} | |
pixl2[255] = tmp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment