import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*; public class beachcomber extends BApplet { // Beachcomber // Kevan Davis, 5/4/03 int direction = 0; int stone = 0; int scatter = 0; int wipenext = 1; BImage beachpic; void setup() { size(200,200); beachpic = loadImage("god.jpg"); noBackground(); } void loop() { int off = 0; for (int i = 0; i < 10000; i++) { int cX = (int)random(width-2)+1; int cY = (int)random(height-2)+1; int bX=0, bY=0; if (direction == 0) { bX = cX; bY = cY-1; } if (direction == 1) { bX = cX+1; bY = cY-1; } if (direction == 2) { bX = cX+1; bY = cY; } if (direction == 3) { bX = cX+1; bY = cY+1; } if (direction == 4) { bX = cX; bY = cY+1; } if (direction == 5) { bX = cX-1; bY = cY+1; } if (direction == 6) { bX = cX-1; bY = cY; } if (direction == 7) { bX = cX-1; bY = cY-1; } if (scatter == 1) { bX = bX+(int)random(3)-1; bY = bY+(int)random(3)-1; } if (bX < width && bX > 0 && bY < height && bY > 0) { int first = getPixel(cX, cY); int second = getPixel(bX, bY); if (red(first)+green(first)+blue(first) > red(second)+green(second)+blue(second)) { setPixel(cX, cY, second); setPixel(bX, bY, first); } } } if (wipenext == 1) { wipenext = 0; if (stone == 3) { image(beachpic, 0, 0); } else { for (int x = width-1; x >= 0; x--) { for (int y = 0; y < height; y++) { setPixel(x, y, pebble()); } } } } } void keyPressed() { if(key == 'z' || key == 'Z') { size(100, 100); direction++; if (direction == 8) { direction = 0; } } if(key == ' ') { wipenext = 1; } if(key == 'x' || key == 'X') { stone++; if (stone == 4) { stone = 0; } wipenext = 1; } if(key == 'c' || key == 'C') { scatter = 1 - scatter; } } void mousePressed() { for (int yoff=-8; yoff<8; yoff++) { for (int xoff=-8; xoff<8; xoff++) { if (sqrt((xoff*xoff)+(yoff*yoff))<8) { int z = (int)random(255); if (mouseY+yoff > 0 && mouseY+yoff < height && mouseX+xoff > 0 && mouseX+xoff < width) { setPixel(mouseX+xoff, mouseY+yoff, pebble()); } } } } } int pebble() { if (stone == 0) { int z = (int)random(155)+100; return color(z,z/1.5f+random(50),z/3+random(50)); } else if (stone == 2) { if ((int)random(2)==1) { return color(200,0,0); } return color(100,0,0); } else { int z = (int)random(255); return color(z,z,z); } } }