     let a: UInt8 = 255
 }
 
-func createImage(width: Int, height: Int, pixels: [Pixel]) -> UIImage? {
-    guard pixels.count == (width * height) else {
+class Image {
+    let width: Int
+    let height: Int
+    var pixels: [Pixel]
+
+    init(width: Int, height: Int, pixels: [Pixel]) {
+        self.width = width
+        self.height = height
+        self.pixels = pixels
+    }
+
+    func setPixel(location: Point2d<Int>, colour: Colour) {
+        pixels[location.x + (pixels.count - (location.y * width))] = colour
+    }
+}
+
+typealias Colour = Pixel
+
+func drawLine(start: Point2d<Int>, end: Point2d<Int>, colour: Colour, image: Image) {
+    for (var t = 0.0; t < 1.0; t += 0.05) {
+        let x = Int(Double(start.x) * (1.0 - t)) + Int(Double(end.x) * t)
+        let y = Int(Double(start.y) * (1.0 - t)) + Int(Double(end.y) * t)
+        image.setPixel(Point2d(x: x, y: y), colour: colour)
+    }
+}
+
+func uiImageForImage(image: Image) -> UIImage? {
+    guard image.pixels.count == (image.width * image.height) else {
         return nil
     }
-    let dataProvider = CGDataProviderCreateWithCFData(
-        NSData(bytes: pixels, length: pixels.count * sizeof(Pixel))
-    )
 
+    let pixelData = NSData(bytes: image.pixels, length: image.pixels.count * sizeof(Pixel))
+    let dataProvider = CGDataProviderCreateWithCFData(pixelData)
     let bytesPerPixel = 4
     let bitsPerComponent = 8
     let colourSpace = CGColorSpaceCreateDeviceRGB()
     let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue)
-    if let cgImage = CGImageCreate(width, height, bitsPerComponent, bytesPerPixel * 8, bytesPerPixel * width, colourSpace, bitmapInfo, dataProvider, nil, false, .RenderingIntentDefault) {
-        let image = UIImage(CGImage: cgImage)
-        UIImagePNGRepresentation(image)
-        return image
+
+    if let cgImage = CGImageCreate(image.width, image.height, bitsPerComponent, bytesPerPixel * 8, bytesPerPixel * width, colourSpace, bitmapInfo, dataProvider, nil, false, .RenderingIntentDefault) {
+        return UIImage(CGImage: cgImage)
     } else {
         return nil
     }


let width = 320
let height = 240
let redPixel = Pixel(r: 255, g: 0, b: 0)
let pixelData = [Pixel](count: width * height, repeatedValue: redPixel)
let image = createImage(width, height: height, pixels: pixelData)

import UIKit

struct Point2d<T> {
