Created
March 7, 2015 16:31
-
-
Save mathias-brandewinder/8f081f3c1fae03133bba to your computer and use it in GitHub Desktop.
Bubbles from Fractal Forest
This file contains 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
// just a tiny tweak on the Fractal Forest dojo: | |
// https://github.com/c4fsharp/Dojo-Fractal-Forest | |
open System | |
open System.Drawing | |
open System.Windows.Forms | |
let width, height = 500, 500 | |
let form = new Form(Width = width, Height = height) | |
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill) | |
let image = new Bitmap(width, height) | |
let graphics = Graphics.FromImage(image) | |
graphics.SmoothingMode <- System.Drawing.Drawing2D.SmoothingMode.HighQuality | |
let brush = new SolidBrush(Color.FromArgb(0, 0, 0)) | |
box.Image <- image | |
form.Controls.Add(box) | |
let endpoint x y angle length = | |
x + length * cos angle, | |
y + length * sin angle | |
let flip x = (float)height - x | |
let drawCircle (target : Graphics) (brush : Brush) | |
(x : float) (y : float) | |
(angle : float) (length : float) (width : float) = | |
let x_end, y_end = endpoint x y angle length | |
let origin = new PointF((single)x, (single)(y |> flip)) | |
let destination = new PointF((single)x_end, (single)(y_end |> flip)) | |
let pen = new Pen(brush, (single)width) | |
target.DrawEllipse(pen, int x, int y, int length, int length) | |
let draw x y angle length width = | |
drawLine graphics brush x y angle length width | |
let pi = Math.PI | |
let bubblify depth = | |
let rec bubbles (x:float) (y:float) angle length width depth = | |
drawCircle graphics brush x y angle length width |> ignore | |
if depth > 0 then | |
for i in 1 .. 7 do | |
let i' = float i | |
let angle = angle + 0.2 * i' | |
let length = length * 0.4 | |
let width = width * 0.8 | |
let x1, y1 = endpoint x y angle (length * 1.4 * i') | |
bubbles x1 y1 angle length width (depth - 1) | |
bubbles 250. 50. (pi*(0.5)) 100. 4. depth | |
bubblify 6 | |
form.ShowDialog() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment