Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

March 9th, 2018 Xcode 4.

Project Description: This assignment I incorporated a creative usage of images in a program. I created a
program that makes an abstract self-portrait of a hand. To construct this self-portrait, I used simple drawing
primitives, such as lines and triangles.

//
// ViewController.swift

//

import Cocoa
import Tin

class ViewController: TController {

var scene: Scene!

override func viewWillAppear() {


super.viewWillAppear()
view.window?.title = "Abstract Portrait"
makeView(width: 560.0, height: 400.0)
scene = Scene()
present(scene: scene)
scene.view?.showStats = true
scene.view?.frameRate = 60
}

class Scene: TScene {

var photo: TImage!

override func setup() {


photo =
TImage (contentsOfFileInBundle: "Handnew.png")
photo.loadPixels()

override func update() {


background(gray: 0.0)

strokeDisable()
let width = 20.0

for _ in 1...10000 {
let pixelX = Int(random(max: tin.width))
let pixelY = Int(random(max: tin.height))

let color = photo.color(atX: pixelX, y: pixelY)


color.setFillColor()

let luma = color.luminance()


let w = remap(value: luma, start1: 0.0, stop1: 1.0, start2: width * 0.5, stop2: width * 2)

if pixelX % 3 == 0 {
rect(x: Double(pixelX), y: Double(pixelY), width: w, height: w)
}

else {
triangle(x1: Double (pixelX), y1: Double(pixelY), x2: Double (pixelX) + w, y2: Double (pixelY) +
w, x3: Double (pixelX) + (2 * w) , y3: Double (pixelY))
}

}
view?.stopUpdates()

You might also like