Computation Contest #8 Results and Solution

in programming •  5 years ago 

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:
  1. Choose one of the n points randomly
  2. Move x half the distance towards the chosen point
  3. 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:

NameSolution foundComment
@enderragLooks good, although I don't like that the edges are cut.

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

Winners:

Congratulations @enderrag, you won 2 SBI!

↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓↑↓

The next contest starts soon. Don't miss it!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

A member bonus $trendotoken tip, and !trendovoter, for @quantumdeveloper from MAPXV! These bonuses are for members, selected at random, and last for a few days.

Also consider our MAPR fund and MAXUV vote bonds too.
MAP Steem Fintech: growing your STEEM without SP.

Congratulations @mapxv, you successfuly trended the post shared by @quantumdeveloper!
@quantumdeveloper will receive 4.72489200 TRDO & @mapxv will get 3.14992800 TRDO curation in 3 Days from Post Created Date!

"Call TRDO, Your Comment Worth Something!"

To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site

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:

@mapxv earned : 3.149928 TRDO curation


To view or trade TRDO go to steem-engine.com
Join TRDO Discord Channel or Join TRDO Web Site