problem-specifications icon indicating copy to clipboard operation
problem-specifications copied to clipboard

Fractals/Sets

Open SaschaMann opened this issue 8 years ago • 3 comments

There's an exercise about complex numbers (#718), so let's have exercises that uses those!

Have the user implement and visualise different fractals based on the following sets:

What does this teach?

  • Recursion
  • Applications for complex numbers
  • Visualisation methods, such as generating images from matrices and optionally generating animations
  • Unittesting for software that outputs images (via visual regression testing)

Example image of a julia set: Example Plot (Source: https://commons.wikimedia.org/wiki/File:Julia_set_(ice).png)


I think this would make for an interesting exercise. The required math/algorithm is rather simple but it would teach a lot about testing.

However, the test data would be quite unusual compared to the usual exercism tests as it would require visual regression testing or comparing large matrices. It would also be possible to just have reference images as test data and then let the user compare it to that manually. The canonical data would probably just be reference images which could be replaced by track-specific images, depending on the rendering library of choice (or of ppm images).

What are your thoughts on the idea and the required testdata?

SaschaMann avatar Aug 03 '17 16:08 SaschaMann

Very interesting idea! I think the Mandelbrot set is awesome!

I know nothing about visual regression testing, but here are some thoughts.

The canonical data could perhaps be a result image in base64 encoding, but I worry that the implementations would have to output exactly what image would match the canonical data, which could be difficult to match coloring, positioning, sizing, etc.

It would also be very different from other exercises as in no other exercises are testing visual data.

Smarticles101 avatar Dec 08 '17 03:12 Smarticles101

I built a julia set generator last year for fun; it was in fact a fun exercise, but it took a week. That's more time than I'd typically allocate for an Exercism exercise.

If we did this, we'd have to be very careful with how to encode the expected data. Base64-encoding an image file seems like a bad idea, because the results would be vulnerable to changes in the image compression algorithm used. Best case, we'd encode a straight bitmap, but even that can be surprisingly complicated to encode.

More generally, we'd also have to specify at minimum:

  • size of the viewport in pixels
  • coordinates of the viewport in abstract x-j space
  • algorithm to use for generation
  • number of iterations to use for generation
  • function which transforms iterations_count into a color

As the fractals and generated images are sensitive to all of these things. There may be other requirements as well that I'm not remembering at the moment.

All told, I'm moderately against this idea on the grounds that it's just too big for an exercise. It's a great project for a motivated individual, but a big part of the fun for me was in experimenting with the parameters, and we'd have to set those in stone for the exercise version; it just doesn't work as well.

coriolinus avatar Dec 08 '17 09:12 coriolinus

I have to admit, I completely forgot about this suggestion, despite already working on an example implementation a while ago. Thanks for the reminder 😄 I even had some notes written in those files.

In a Gitter discussion a few months ago, we came to the conclusion that it would probably be best to split the tests in two parts:

  1. Single z, c values for specific cases that could cause issues.
  2. Example images in the form of either ppm, pgm or csv files.

On top of that, it would be encouraged to provide example images, but those wouldn't be used for automated testing because that is, as you both said, quite complicated and too specific for exercism.

One could start off with just the number of iterations and greyscale images. The colourisation could be a bonus part.


Best case, we'd encode a straight bitmap, but even that can be surprisingly complicated to encode.

ppm or pgm would be the simplest format that can be displayed as an image. They don't require encoding, just rgb or intensity values.

algorithm to use for generation

I would suggest limiting it to f_c(z) = z^2 + c. You can make lots of interesting pictures from that already. The examples would then provide datas for interesting values of c.

it's just too big for an exercise.

The examples on Rosetta Code are all rather short. There are exercises that require much more code.

but a big part of the fun for me was in experimenting with the parameters, and we'd have to set those in stone for the exercise version

I agree, that's the most fun. Providing a few examples as test cases and then encouraging the user to explore on their own if they want to could work.

SaschaMann avatar Dec 08 '17 23:12 SaschaMann