EU Code Week 2020 - Day Five - Code Your Camera
About this lesson
We're going to learn about using a lot of the things we've learned already to build a functioning camera app. There may be a lot of code that looks unfamiliar to you, but the instructions will walk us through adding code to the playground to get a functioning camera.
Try your best to follow along, and we'll give you some tips for thinking about these new features today!
To Be Recorded ..., 2020:
Make a paper spinnerYou will need:
- Paper or card
- Optional: dice
What are the components for a perfect dance? Create a paper spinner with numbers 1 to 6 (or use dice). Choose 6 dance moves you would like in your dance.
Each number matches a dance move. You could sketch them on your spinner. Spin the spinner 10 times and write down the combination of dance moves.
Construct your camera in the 'Lights, Camera, Code' playground. Now use the Camera you have created with code to capture the moves for your random, perfect dance.
There is so much more to explore (and implement) in the Lights, Camera, Code playground.
Start with the next page, Saving Your Photos. This saves the pictures you take right in the camera roll on the iPad!
Try and complete the Lights, Camera, Code playground.
If your curiosity is piqued, you can try out the recommended follow-on playgrounds, like Assemble Your Camera or Flashy Photos. Or grab the App at Home playground from The Code Hub's playground feed and try building out an app of your own design, using the components you learned about in this playground.
Code in this session:
Starting with a Camera
// Create the space. let space = Space() // Create the component. let camera = SwiftyCamera(style: .cloud) // Add the component to the space. space.add(camera, at: Point(x: 0, y: 0), size: Size(width: 500, height: 500)) // Start the camera. camera.start()
Seeing Your Photos
// Create the space. let space = Space() // Create the components. let camera = SwiftyCamera(style: .plain) let imageView = ImageView() // Add the components to the space. space.add(camera, at: Point(x: 0, y: -100), size: Size(width: 600, height: 500)) space.add(imageView, at: Point(x: 0, y: 300), size: Size(width: 400, height: 300)) // Set the properties of the image view. imageView.borderColor = colorLiteral(red: 0.1411764770746231, green: 0.3960784375667572, blue: 0.5647059082984924, alpha: 1.0) imageView.borderWidth = 5 imageView.image = imageLiteral(resourceName: "cf_floatyCloudsWP") imageView.cornerRadius = 10 imageView.rotation = 5 // Start the camera. camera.start() // Connect the camera to the image view. camera.photoTaken.connect(to: imageView.input)