VIEW FOR FUN!

I have created a class that continuosly creates dynamic images based on a fractal pattern. The image is so distorted it makes your vision go blurry and makes you feel dizzy. I find this interesting because every image it produces makes you feel sick.

Simple Steps:

1] Copy File: Target.java, Fractal.java

2] Compile File: Target.java

3] Execute: Target

Target.java

import java.awt.*;

import java.awt.event.*;

import java.lang.*;

import javax.swing.*;

publicclass Targetextends JFrame

{

private JMenuItem objItemExit;

public Target()

{

super("Target");

getContentPane().add(new Fractal());

pack();

setResizable(false);

setVisible(true);

addWindowListener(new WindowAdapter(){

publicvoid windowClosing(WindowEvent argEvent){

Destructor();

}

});

}

publicvoid Destructor()

{

dispose();

System.exit(0);

}

publicstaticvoid main(String [] argCommand)

{

Target objTarget =new Target();

}

}

Fractal.java

import java.awt.*;

import java.lang.*;

import java.util.*;

import javax.swing.*;

publicclass Fractalextends JPanelimplements Runnable

{

privateint [][] iMap;

privateint iSize;

privateint iWidth;

privateint iHeight;

privateint iMax;

privateint iMin;

private Thread objThread;

public Fractal()

{

setPreferredSize(new Dimension(550, 550));

iSize = 512;

iWidth = 1;

iHeight = 1;

objThread =new Thread(this);

objThread.start();

}

publicvoid run()

{

while (true){

setMap();

repaint();

try{

objThread.sleep(2500);

}catch (InterruptedException argException){

}

}

}

publicvoid setMap()

{

iMap =null;

System.gc();

Random objRandom =new Random();

iMap =newint[iSize][iSize];

iMap[0][0] = 0;

for (int iD1 = iSize; iD1 > 1; iD1>>=1){

int iD2 = iD1>>1;

int iAdd = objRandom.nextInt(iSize);

for (int iY = 0; iY < iSize; iY += iD1){

for (int iX = 0; iX < iSize; iX += iD1){

iMap[iY][iX + iD2] = (sample(iX, iY) + sample(iX + iD1, iY)) / (2) + iAdd;

iMap[iY + iD2][iX] = (sample(iX, iY) + sample(iX, iY + iD1)) / (2) + iAdd;

}

}

for (int iY = 0; iY < iSize; iY += iD1){

for (int iX = 0; iX < iSize; iX += iD1){

iMap[iY + iD2][iX + iD2] = (sample(iX, iY) + sample(iX + iD1, iY) + sample(iX + iD1, iY + iD1) + sample(iX, iY + iD1)) / (4) + iAdd;

}

}

}

iMax = iMap[0][0];

iMin = iMap[0][0];

for (int ir = 0; ir < iSize; ir++){

for (int ic = 0; ic < iSize; ic++){

if (iMap[ir][ic] > iMax){

iMax = iMap[ir][ic];

}

if (iMap[ir][ic] < iMin){

iMin = iMap[ir][ic];

}

}

}

}

publicint sample(int argX,int argY)

{

return iMap[argY & (iSize - 1)][argX & (iSize - 1)];

}

publicvoid paintComponent(Graphics argGraphic)

{

int iColor =new Random().nextInt() % 3;

int iShiftX = (getWidth() - (iSize * iWidth)) / 2;

int iShiftY = (getHeight() - (iSize * iHeight)) / 2;

argGraphic.setColor(Color.white);

argGraphic.fillRect(0, 0, getWidth(), getHeight());

int iColorShade = ((iMax - iMin) / 255) + 1;

for (int ir = 0; ir < iSize; ir++){

for (int ic = 0; ic < iSize; ic++){

switch (iColor){

case 0:

argGraphic.setColor(new Color((iMap[ir][ic] - iMin) / iColorShade, 0, 0));

break;

case 1:

argGraphic.setColor(new Color(0, (iMap[ir][ic] - iMin) / iColorShade, 0));

break;

case 2:

argGraphic.setColor(new Color(0, 0, (iMap[ir][ic] - iMin) / iColorShade));

break;

default:

argGraphic.setColor(new Color((iMap[ir][ic] - iMin) / iColorShade, (iMap[ir][ic] - iMin) / iColorShade, (iMap[ir][ic] - iMin) / iColorShade));

break;

}

argGraphic.fillRect((ir * iWidth) + iShiftX, (ic * iHeight) + iShiftY, iWidth, iHeight);

}

}

}

}

Please let me know what you think of it.

DeltaCoder

[9321 byte] By [DeltaCoder] at [2007-9-30 18:57:03]
# 1
Ok, I let it run longer. Not every image is so bad. Just look straight into the middle and try to maintain eye focus.DeltaCoder
DeltaCoder at 2007-7-6 21:15:55 > top of Java-index,Security,Cryptography...