Computation Contest #8 Results and Solution
Solution
The problem of this contest was to simply draw a fractal of your choice.
I chose to draw this fractal as an example:
This fractal was generated with the chaos game algorithm.
The chaos game works on a few simple rules:
Start with a set of n points in a 2d plane.
Choose a random point x on the plane.
Now in a loop make:
- Choose one of the n points randomly
- Move x half the distance towards the chosen point
- Paint a dot at x(Preferably with low alpha, to make the image look smoother).
In the example shown above I used 5 points:
The 4 corners of a rectangle and the exact center.
Here is my implementation:
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Graphics;
public class fractal extends JFrame {
double x, y;
int len;
double [] xP;
double [] yP;
public fractal() {
// Initialize JFrame:
super("Fractal");
this.setSize(1800, 1200);
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Initialize points:
// Here 4 corners of a rectangle and the center:
xP = new double[]{100, 100, 1700, 1700, 900};
yP = new double[]{100, 1100, 1100, 100, 600};
len = 5;
// Start at one of the corners:
x = xP[0];
y = yP[0];
}
int n = 0;
@Override
public void paint(Graphics g) {
// Make sure the background really gets drawn black:
if(n <= 100) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, 1800, 1200);
n++;
}
// Use some color different to the background with low alpha value to draw the current position of the dot:
g.setColor(new Color(255, 255, 255, 2));
g.drawRect((int)x, (int)y, 1, 1);
// Choose a new point:
int z = (int)(len * Math.random());
// Move the point half the distance to that point:
x -= (x-xP[z])/2;
y -= (y-yP[z])/2;
}
public static void main(String [] args) {
fractal f = new fractal();
while(true) {
f.repaint();
}
}
}
I wonder why only one participant showed up, although it wasn't that hard.
↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓
List of participants with their entries:
Name | Solution found | Comment |
---|---|---|
@enderrag | Looks good, although I don't like that the edges are cut. |
↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓
Winners:
Congratulations @enderrag, you won 2 SBI!
↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓
Congratulations @mapxv, 50.57% upvote has been shared with your successful call on the post that shared by @quantumdeveloper!
Support @trendotoken projects by delegating : 100SP , 200SP , 500SP , 1000SP , 2000SP
Congratulations @quantumdeveloper, your post successfully recieved 4.724892 TRDO from below listed TRENDO callers:
To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site