Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

April 3, 2018 Xcode 4.

Project Description:

Parallax is the visual effect whereby the position of an object appears to differ when viewed from different positions. This forms the
basis of a popular effect, used today in animations, games, and in web design. The Parallax effect is constructed using layers of
images. An effect of the viewer position moving is created by moving (and perhaps scaling) the layers of images. Layers that will be
perceived as close to the viewpoint should move fastest, while layers that are far away should move slower, and slower, the further
they recede from the viewpoint.

My goal was to create a parallax effect in my program, using layers of images as the content, and the position of the mouse pointer
as the trigger/input for the change in position.

import Cocoa
import Tin

class ViewController: TController {

var scene: Scene!

override func viewWillAppear() {


super.viewWillAppear()
view.window?.title = "Parallax"
makeView(width: 1000.0, height: 600.0)
scene = Scene()
present(scene: scene)
scene.view?.showStats = false
}

class Scene: TScene {


// The ! after TImage is important here.
// We don't create the TImage object until the setup function runs.
var sanFran: TImage!
var skateboard: TImage!
var healingMusic: TImage!
var beyonce: TImage!
var mic: TImage!

override func setup() {


// The image must be added to the Xcode project.
// The image also needs to be part of the "target membership"
// of this application. Select the image, and look at the
// File inspector to verify the membership.
sanFran = TImage(contentsOfFileInBundle: "DSC_0507.png")
skateboard = TImage(contentsOfFileInBundle:"615c1825c4aa7612bdf843f2e29984a0.png")
healingMusic = TImage (contentsOfFileInBundle: "music.png")
beyonce = TImage ( contentsOfFileInBundle: "beyonce.png")
mic = TImage ( contentsOfFileInBundle: "mic.png")
}

override func update() {


background(gray: 0.5)
//background image

image(image: sanFran, x: 0, y: 0, width: 1000, height: 600)

// the yellow skateboard


let skateboardX = remap(value: tin.mouseX, start1: 250, stop1: 700, start2: 250, stop2: 400)
pushState()
translate(dx: skateboardX, dy: 0)
image(image: skateboard, x: 150, y: 60, width: 200, height: 100)
popState()

// the music notes that are symbolic for her singing to the community of San Francisco

let healingMusicX = remap(value: tin.mouseX, start1: 200, stop1: 800, start2:0 , stop2: 20)
pushState()
translate(dx: healingMusicX, dy: 0)
image(image: healingMusic, x: 0, y: 0, width: 1000 , height: 600)
popState()

// Beyonce

let beyonceX = remap(value: tin.mouseX, start1: 300, stop1: 700, start2: 300, stop2: 400)
pushState()
translate(dx: beyonceX, dy: 0)
image(image: beyonce, x: 0, y: 100, width: 500, height: 500)
popState()

//the mic Beyonce is "singing" with

let micX = remap(value: tin.mouseX, start1: 100, stop1: 900, start2: 470, stop2: 570)
pushState()
translate(dx: micX, dy: 0)
image(image: mic, x: 0, y: 415, width: 70, height: 100)
popState()

}
}

You might also like