This is an optical illusion. All you have to do is look at the dot in the center. Because it’s an animation I cant show you a picture, but here is the source code…

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
public class Illusion extends JFrame{
public static void main(String args[]) {
new Illusion();
}


public Illusion() {
Draw d = new Draw();
setTitle(“Troxler effect”);
setSize(600,600);
add(d);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setVisible(true);
}
}
class Draw extends JPanel {
ArrayList<Circle> cs = new ArrayList();
public Draw() {
setBackground(Color.WHITE);
}
int q = 0;
public void paintComponent(Graphics g) {
super.paintComponent(g);

g.fillOval(330,300, 10,10);
for(int i = 0; i < 10; i++) {
Circle c = new Circle();
c.opaque = 0.05f;
c.c = new Color(1, 0, 0, c.opaque);

int xTic = (int) ((int) (300) – 170 * Math.sin(i
* (2 * Math.PI / 10)));
int yTic = (int) ((int) (300) – 170 * Math.cos(i
* (2 * Math.PI / 10)));
c.x = xTic;
c.y = yTic;
cs.add(c);
cs.get(i).draw(g);

}
q++;
if(q >= 10) {
q = 0;
}
int xTic1 = (int) ((int) (300) – 170 * Math.sin(q
* (2 * Math.PI / 10)));
int yTic1 = (int) ((int) (300) – 170 * Math.cos(q
* (2 * Math.PI / 10)));

g.setColor(new Color(1, 1, 1, 100));
g.fillOval(xTic1, yTic1, 50, 50);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
repaint();
}
}
class Circle {
Color c;
int x, y;
float opaque = 0.1f;
public void draw(Graphics g) {
g.setColor(c);
g.fillOval(x, y, 50, 50);
}
}

Advertisements