Generative Art Hands On with F#

14
Generative Art Phillip Trelford F#unctional Londoners 2013

description

Slides from hands on Generative Art with F# session for the F#unctional Londoners meetup group at Skills Matter

Transcript of Generative Art Hands On with F#

Page 1: Generative Art Hands On with F#

Generative ArtPhillip Trelford

F#unctional Londoners

2013

Page 2: Generative Art Hands On with F#

Generative Art: Que?

Generative artists are chaos artists

…embrace the chaos & learn to love it

Page 3: Generative Art Hands On with F#

Modern Art: Procedurally Generated

Page 4: Generative Art Hands On with F#

Modern Art: Animated

Page 5: Generative Art Hands On with F#

Animated Gifs

Page 6: Generative Art Hands On with F#

Happy endings

// Generate text from Philippe Decrauzat's D.T.A.B.T.W.H.A.H.E. 2010

let print (s:string) =

[|for y in 0..s.Length-1 ->

[|for x in 0..y-1 -> s.[x]

for x in y..s.Length-1 -> s.[y]

|]

|> fun cs ->

System.String(cs) +

System.String(cs |> Array.rev |> Seq.skip 1 |> Seq.toArray)

|]

|> fun ys -> [|yield! ys; yield! (Array.rev ys |> Seq.skip 1)|]

|> String.concat "\r\n"

print "A HAPPY ENDING"

Page 7: Generative Art Hands On with F#

Choose your own adventure

Page 8: Generative Art Hands On with F#

SmallSharp: Lines

open Library

do GraphicsWindow.Show()

GraphicsWindow.BrushColor <- red

for i in 0..5..200 do

GraphicsWindow.DrawLine(i,0,n-i,n)

GraphicsWindow.DrawLine(0,i,n,n-i)

Page 9: Generative Art Hands On with F#

Deviant Art: Bubbles

Page 10: Generative Art Hands On with F#

Rothko / Async Rectangles

let rec waiting() = async {

let! md = Async.AwaitObservable(main.MouseLeftButtonDown)

let rc = new Canvas(Background = transparentGray)

main.Children.Add(rc)

do! drawing(rc, md.GetPosition(main)) }

and drawing(rc:Canvas, pos) = async {

let! evt = Async.AwaitObservable(main.MouseLeftButtonUp, main.MouseMove)

match evt with

| Choice1Of2(up) ->

rc.Background <- SolidColorBrush(colorSelect.CurrentColor)

do! waiting()

| Choice2Of2(move) ->

moveControl rc pos (move.GetPosition(main))

do! drawing(rc, pos) }

Page 11: Generative Art Hands On with F#

Mandelbrot

let (|Escaped|DidNotEscape|) (cx,cy) =

let rec compute (zx,zy) i =

if i = maxIteration then DidNotEscape

elif zx * zx + zy * zy > 4.0 then Escaped i

else compute (zx*zx - zy*zy + cx, 2.0*zx * zy + cy) (i+1)

compute (cx,cy) 0

Page 12: Generative Art Hands On with F#

Turing Drawings

match action with

| Action.Left ->

xPos <- xPos + 1

if xPos >= mapWidth then xPos <- xPos - mapWidth

| Action.Right ->

xPos <- xPos - 1

if (xPos < 0) then xPos <- xPos + mapWidth

| Action.Up ->

yPos <- yPos - 1

if (yPos < 0) then yPos <- yPos + mapHeight

| Action.Down ->

yPos <- yPos + 1

if yPos >= mapHeight then yPos <- yPos - mapHeight

Page 13: Generative Art Hands On with F#

Inspirational Sites

This is Colossal Deviant Art Zen Bullets

Page 14: Generative Art Hands On with F#

F# Libraries

http://smallsharp.codeplex.com (Graphics)

http://funscript.info (F# -> JS)

http://www.pinksquirrellabs.com (CYAO Type Provider)