Phillip Trelford's Array

POKE 36879,255

Animating Lohse

Richard Paul Lohse was a Swiss born painter and graphic artist who typically produced pieces that had “interacting colour elements in various logical/mathematical relations visible to the eye”

Out of curiosity I’ve taken a small number of Lohse’s work, generated them procedurally and added simple animations.

Sechs Serigraphien

Sechs Serigraphien

Here I imagined the centre blocks bleeding out and filling the adjacent blocks a line at a time.

 

15 systematische Farbreihen mit 5 gleichen horizontalen Rythmen

15 systematische Farbreihen mit 5 gleichen horizontalen Rythmen

This picture is composed of lines with a 15 row colour progression with each column having an offset. To animate it I rotate each column’s colours in an opposing direction.

Spiral

Lohse inspired animated spiral

This Lohse inspired spiral consists of alternating block patterns animated anti-clockwise.

Opposing Spiral

Lohse inspired animated opposing spiral

The same pattern with alternating block patterns rotating clockwise and anti-clockwise.

Four Similar Groups

Four Similar Groups

Here I imagined the red blocks shooting up and down and  from side-to-side.

Method

Each piece was generated procedurally using an F# script. A parameterized function is used to generate a frame as a bitmap, with a series of frames created to form an animated gif.

For example to draw the 15 lines

// Column widths
let xs = [3;2;1;4;2;1;4;2;1;4;2;1;4;2;1]
// Column color offsets 
let ys = [0;10;14;8;11;6;9;4;7;2;5;12;4;13;1]
// Image width and height
let width,height=476,450
// Block width and height
let w,h = 14,30

// Returns image using specified color offset
let draw n =
   let image = new Bitmap(width,height)
   use graphics = Graphics.FromImage(image)
   for y = 0 to 14 do
      List.zip xs ys
      |> List.mapi (fun i xy -> i,xy)
      |> List.scan (fun x (i,(dx,dy)) ->
         let n = if i%2 = 0 then -n else n
         let brush = brushes.[(15 + y + dy + n) % 15]
         graphics.FillRectangle(brush, x*w, y*h, w*dx,h)
         x + dx
      ) 0 |> ignore
   image

// http://www.codeproject.com/Articles/11505/NGif-Animated-GIF-Encoder-for-NET
#r @"Gif.Components.dll" 
open Gif.Components

let encoder = AnimatedGifEncoder()
if encoder.Start(@"c:\temp\15lines.gif") then
   encoder.SetFrameRate(2.0f)
   encoder.SetRepeat(0)
   for i = 0 to 15 do
      encoder.AddFrame(draw i) |> ignore
   encoder.Finish() |> ignore

Full Scripts

Have fun!

24hrs in F#

The easiest place to see what’s going on in the F# community is to follow the #fsharp hash tag on Twitter. The last 24hrs have been as busy as ever, to the point where it can be hard to keep up these days.

Here’s some of the highlights

Events

Build Stuff conference to feature 8 F# speakers:


and workshops including:

FP Days programme is now live, and features key notes from Don Syme & Christophe Grand, and presentations from:


New Madrid F# meetup group announced:


F# MVP Rodrigo Vidal announces DNA Rio de Janeiro:


Try out the new features in FunScript at MF#K Copenhagen:


Mathias Brandewinder will be presenting some of his work on F# & Azure in the Bay Area


Let’s get hands on session in Portland announced:


Riccardo Terrell will be presenting Why FP? in Washington DC


Sessions featuring FsCheck, Paket & SpecFlow scheduled in Vinnitsa (Ukraine)


Projects

Get Doctor Who stats with F# Data HTML Type Provider:


Major update to FSharp.Data.SqlClient:


ProjectScaffold now uses Paket:


Microsoft Research presentation on new DBpedia Type Provider:


Blogs

More F#, Xamarin.Forms and MVVM by Brad Pillow


Cross-platform MSBuild API by Robin Neatherway


Hacking the Dream Cheeky Thunder Missle Launcher by Jamie Dixon:



Want more?

Check out Sergey Tihon’s F# Weekly!

The Last Assignment

Back in November last year, my eldest son and I popped over to the Insomnia Gaming Festival in Telford to take part in a game jam organised by Global GameCraft. (Today I  bumped into the source again on a USB stick).

The theme for the day was “The Last Assignment”. We decided to go with a text based adventure game loosely based on the Dirty Harry movie.

With just 7 hours on the clock we managed to put together quite a fun adventure game with ambient sound and graphics:

The Last Assignment - Start Screen

and picked up the prize for best storyline!

The Last Assignment - Insomnia Telford

Given the time constraints I decided to build the dialogue as a simple state machine using coroutines. In this scenario C# was my go to language as it provides basic iterator block support and a first class goto statement.

By building the game dialogue as a simple state machine I was able test it from the start as a console app and later easily integrate it into a graphical environment.

Here’s the state machine for the rookie scene:

public static IEnumerable<State> Rookie()
{
   yield return new State(
         "One way or another this will be your last assignment.\r\n" +
         "Just 2 weeks left on the force before you retire.\r\n" +
         "Back at the police station",
         "You get a black coffee and a donut",
         "A chai latte and a cup cake") { Theme="70s reflective;bullpen"};
   if (Choice.Taken == 2) goto imposter;
   yield return new State(
         "Your new partner introduces himself.",
         "You give him a stern look",
         "Ignore him") { Theme = "70s reflective;bullpen" };
   yield return new State(
         "\"Why do they call ya 'Dirty Harry'?\"",
         "Make up your own mind kid",
         "Turn up your eye brow"
         ) { Theme = "70s reflective;bullpen" };
   yield break;
imposter:
   Game.Ended = true;
   yield return new State(
         "You have been exposed as an imposter.\r\n" +
         "Cops don't chai latte, keep it real!")
         { Theme = "end game mp3;bullpen" };
}

 

which looked like this:

Rookie Scene

If you fancy having a play, the source for the game as a console app is available here:

Have fun!