Created
May 5, 2017 17:26
-
-
Save noelwelsh/ea15eb450e28fbde245cf999021f0d59 to your computer and use it in GitHub Desktop.
Random circles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We going to create random circles inside a circle. (This is called "generative art". If you own a beret now is a good time to put it on.) | |
We're going to use `map` and a new tool, `flatMap`, in a different context. The idea is to broaden how we think about these tools. | |
Step 1. | |
- How could we create a point that is randomly located within a circle? There are many ways to do this. Think of one. | |
- Use the following methods to create random numbers (you'll need to `import doodle.random._`) | |
`Random.double` | |
`Random.natural` | |
`Random.int` | |
also `Random[A] map (A => B): Random[B]` and | |
`Random[A] flatMap (A => Random[B]): Random[B]` | |
to compose functions with `Random` and thus transform them | |
- Now implement your method to a create point. | |
- Finally, call the `run` method and you should get a `Point`. | |
Step 2. | |
- Given a random point, transform it into a random circle (choose size and color at random) | |
- Don't use `run`---you're only allowed to call `run` at the very end! | |
- Draw an `Image` (you're only allowed to call `run` immediately before you call `draw`) | |
Step 3. | |
- Create lots of random circles to create a picture of circles arranged in a circle shape. | |
- Don't use `run`---you're only allowed to call `run` at the very end! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment