Skip to main content

2019 | Buch

Simulations in Swift 5

Design and Implement with Swift Playgrounds

insite
SUCHEN

Über dieses Buch

Design and implement simulations using Apples Swift Playgrounds. Computer simulations are used to replicate the physical systems we see all around us. They help us solve problems by performing experiments that may otherwise be impossible in the real world. This book uses simulations to solve counter-intuitive logic puzzles, create procedural artworks, and build habitats for digital lifeforms.

To help you create your own simulations using the Swift programming language, this book is filled with projects that you can easily follow along with. All you need is a Mac with the latest version of Xcode installed. All projects are written in Xcode’s Playgrounds. This keeps the process simple. No need to setup an Apple account, or learn anything further about building apps.

Simulations are used in many areas within computer science and yet, barely anyone is teaching them. Sure, the fundamentals are in algorithm design, but simulations are a step above that. Usually when writing an algorithm you have a specific outcome in mind. However, when you create a simulation, the system you are modelling can be far more unpredictable than sorting a list, or navigating a maze. Simulations in Swift 5 will guide you through all of this.

What You'll Learn

Simulate situations with advanced algorithms to solve advanced problems

Incorporate real-world physics into simulated problems

Predict biological and other systems behavior and the outcome of events based on presented factors

Who This Book Is For

Swift programmers interested in tackling fun projects in Swift involving advanced algorithms and factors

Inhaltsverzeichnis

Frontmatter
Chapter 1. Swift Playgrounds
Abstract
We’re going to be creating most of our projects with Xcode’s Swift Playgrounds. They’re the easiest and fastest way to start writing Swift. I use them all the time for prototyping, or working through math problems and refining algorithms. Once I’m happy with the code, I will usually move it into a more significant project.
Beau Nouvelle
Chapter 2. The Monty Hall Problem
Abstract
The Monty Hall Problem gets its name from a TV game show that originated in 1963 named Let’s Make a Deal. The problem is a counterintuitive puzzle where you have the opportunity to choose from one of three closed doors. Two doors have a goat behind them, and one has a car. The aim is to pick a door with the car.
Beau Nouvelle
Chapter 3. Guessing Game
Abstract
Here’s a puzzle that features on Randall Munroe’s XKCD blog, and is explained in the Numberphile YouTube video “How to Win a Guessing Game.”
Beau Nouvelle
Chapter 4. Theatre Seating
Abstract
This time around I’ll be introducing some new data types and walk you through how you can create your own. While they’re not completely necessary to complete the tasks in this chapter, they will make things a little easier to understand what’s going on and become essential tools for us to use in future projects.
Beau Nouvelle
Chapter 5. Projectile Motion
Abstract
Up until now we’ve been able to avoid some of the more math-heavy simulations. While projectile motion can include some very intense calculations, I promise to keep things simple throughout this chapter (the really tricky stuff is coming later).
Beau Nouvelle
Chapter 6. Live Views
Abstract
It’s time to work on something a little bit different. In this chapter we’ll be taking a short break from creating simulations and introducing you to live views. You’ll also get to learn how to create art with code and how to export it. If you enjoy generating artwork in this way, keep an eye out for my next book. It will lead you through creating chaotic looped animations, fractals, image filters, and terrain/planet generation.
Beau Nouvelle
Chapter 7. Game of Life
Abstract
Developed by John Conway in 1970, the Game of Life is a cellular-automaton, zero-player game. A game in the lightest sense as there is no user interaction beyond the initial starting conditions and neither is there an end.
Beau Nouvelle
Chapter 8. The Forest: Part One
Abstract
In the previous chapter, we created a world full of cells. We made it possible for them to be in one of two states—dead or alive. This time around we’ll be replacing the states with types and augmenting them with some protocol-oriented programming.
Beau Nouvelle
Chapter 9. The Forest: Part Two
Abstract
We now have the initial conditions of our forest completed, and so it’s time to start applying some rules around life and death—you didn’t think this was going to be a happy forest, did you?
Beau Nouvelle
Backmatter
Metadaten
Titel
Simulations in Swift 5
verfasst von
Beau Nouvelle
Copyright-Jahr
2019
Verlag
Apress
Electronic ISBN
978-1-4842-5337-3
Print ISBN
978-1-4842-5336-6
DOI
https://doi.org/10.1007/978-1-4842-5337-3