Professional Documents
Culture Documents
LOG IN / MEMBERSHIP
FILTER CONTENTS
I O S , T U TO R I A L S
Published: 08/03/2016 | Views: 10,476 | c 2
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 1 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
This tutorial will introduce you to creative-coding on iOS with C4, a powerful framework for creating
expressive artworks and user experiences. Written entirely in Swift, C4 takes a modern approach to
working with animation, gestures and media. For example, there are no draw loops – you create
animations by defining states and changing properties. You can attach a gesture to any object by using a
simple block of code, and easily customize the number of touches, taps and more, to trigger it. You can
create images, audio and video players by simply stating the name of a file, and with images you can apply
filters. Yet, to say that C4 handles only animation, interaction and media would do it a disservice. There is
vector math, an event system for sending messages between objects, a transform class for performing
matrix calculations, camera access, and much more.
Here’s a short video of the 5 demos that you’ll build in this tutorial:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 2 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:20
Made with C4
C4 is broad framework that is integrated tightly with Apple’s native UIKit. You can create both experimental
creative works or integrate it directly into ready-to-ship professional quality apps. The following images and
videos will give you a good overview of the different kinds of things that have been made with C4.
M/O
Currently being built with C4, M/O is an interactive artwork made up of 28 iPads.
M/O Demo 1
from Logic&Form
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 3 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:07
M/O Demo 2
from Logic&Form
00:12
COSMOS
Released in late 2015, the COSMOS app is designed to show how beautiful user experiences can be
created with C4. We also published an end-to-end tutorial on how we designed, built and launched to the
App Store.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 4 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:23
01:47
Halo
In 2013, a basic form of C4 was used to generate the animations for an interactive light wall. Halo was a
collaboration between myself and Tangible Interaction.
Halo
from Logic&Form
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 5 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
01:12
Getting Started
1. A Mac
2. Xcode 7+
3. C4
Since C4 is built on Apple’s iOS frameworks, it is currently only availble for Mac. You can download the
latest copy of Xcode for free right from Apple’s Website.
Installing C4
The easiest way to create new projects is to install C4 directly into Xcode. I highly recommend this
approach because it makes it extremely easy to quickly create new projects and test out your ideas.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 6 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Like I mentioned above, I personally think this is the easiest way to test C4 projects. You can quickly create
new projects, all the test media are included, and its an easy setup for copying and pasting any example
code from our site straight into the WorkSpace. Furthermore, the code that installs is static so it should
always work out of the box.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 7 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
The only significant drawback is that this installs a static copy of C4’s code base in every project you
create. If there are updates to the core C4 project on Github this installer won’t update automagically. You’ll
have to wait until we create a new installer build.
There are a few other ways to get your hands on C4. You can use Cocoapods, Carthage, Github
for Mac, or work purely from git. If you want to explore these options have a look at the install
page.
The Basics
Here is a basic example that shows how to put a circle on the screen:
I recommend you ave a look at our guide to some of C4’s basic features. This is a set of about two dozen
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 8 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
very short code snippets that will introduce you to a variety of objects and techniques you can apply in C4.
C4 v Other Frameworks
Inspired by Processing and OpenFrameworks, one of the main goals of C4 is to help people learn how to
code and to open the door to native programming. The API is so designed that while you’re learning it
you’re actually learning how to program in Swift. There are many similarities with P5/OF, but there are
some fundamental differences as well.
P01
00:05
Here’s how you might fade a background color from black to white and back again in Processing:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 9 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
void setup() {
size(640, 360);
background(0);
}
void draw() {
background(val,val,val);
val += dir;
if (val == 255 || val == 0) {
dir *= -1;
}
}
The animation approach means that you don’t have to figure out every step along an animation. You simply
set the beginning / end states and let C4 do the rest!
Everything is an Object
C4 uses objects instead of drawings to represent visuals elements. Compared to other frameworks, the
process of adding and positioning basic elements is similar.
An Ellipse
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 10 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
void draw() {
ellipse(width/2,height/2,50,50);
}
func setup() {
let c = Circle(center: canvas.center, radius: 50)
canvas.add(c)
}
The major difference in the two approaches – objects v. renderings – is what you can do with the object
after it’s on the canvas. You can add gesture recognizers or animations to it, and change its visual style all
without redrawing. You can even add an object to another object!
Layers
Layers are an important concept in C4. You can achieve complex aesthetics with a few lines of code.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 11 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Here’s an example of adding one object to another and animating them both:
canvas.add(c)
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 12 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Processing Examples
Processing was a major influence on the development of C4. If you’ve used it in the past, and would like to
know how C4 differs, we’ve recreated a handful of Processing examples in C4.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 13 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Code
You can grab a copy of the code for this project from here
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 14 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Waves
In this section we’re going to introduce you to an important concept in C4: Animations. We’ll also show you
how to work with gradients and timers to create a wave effect. When we’re done, we’ll show you how to
tweak a single line of code to get some different aesthetics out of the example.
Animations
In C4, you’ll be working a lot with objects that contain properties. For example, all shapes have
a fillColor and strokeColor. C4 lets you create animations by changing the properties of objects.
Rather than calculating all the steps between a and b, you can focus on thinking about states. For
example, the following snippet will create a 0.25 second animation where a circle’s fill color will shift to red:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 15 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
ViewAnimation(duration: 0.25) {
circle.fillColor = red
}
Now’s a good time to check out the basics of animations and properties over at: C4 Basics
Gradients
For this section, we’re going to create a wave of gradients by using a for loop and a timer to offset our
animations. You can create a simple gradient by giving it a frame and a set of colors, like so:
By default, the gradient draws from top to bottom of its frame. If you want to change that you can specify a
new value for either its startPoint or endPoint.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 16 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
g.endPoint = Point(1,1)
… the gradient will draw from its top-left corner to its bottom-right:
Note: when setting the end points you do so with relative values. The corners of the gradient’s
frame are {0,0}, {1,0}, {1,1} and {0,1} read clockwise from the top-right.
Timers
By default, there are no draw-loops in C4, which means that we can’t trigger animations based on frame
counts. But, there are a variety of techniques that we can use to offset the triggering of code. For example,
we could use a wait that will execute a bit of code after a specified amount of time (measured in
seconds).
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 17 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
wait(0.25) {
//run a function
}
Waits are great for simple circumstances. You can tell the application to wait a quarter second before doing
something. However, they become unreliable when you start chaining them together.
If you want a lot of animations to start at regular intervals, the easiest technique is to use a Timer. You
create one by specifying an interval and a block of code to execute. For example, printing to the console
once every quarter-second looks like this:
NOTE: The timer has to be set as a variable outside the function in which you create it.
And, if you want to know how many times the timer has fired, you can do this:
This will continuously print like so: Hello C4: 1,Hello C4: 2,Hello C4: 3,…
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 18 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
And, if you want to have the timer stop after a given number of iterations, you can do this:
As you can see, timers are easy to work with and give you a range of flexibility in starting, stopping, and
changing their parameters.
Now that we’ve had an overview of the 3 main components of this section, let’s build it!
The Wave
To create our wave we’re going to follow this 4-step process:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 19 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
if random(below: 2) == 1 {
colors = [C4Pink,C4Blue]
}
This produces the same image as our first experiment with gradients.
random(below: 2) == 1
We use the result to determine whether we invert the colors of the gradient.
This specifies that the function requires you to give it a point, and when it has completed its job it will
return to you a new Gradient object. Which is why we see the return g statement at the end of the
function.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 20 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Before you move on to the next step, make sure to change from this:
…to:
Rect(0, 0, 2, 2)
This function requires you to pass it a gradient. It then creates a new animation that does the following:
The animation takes place over 2 seconds and when it completes it will reverse, and then repeat. This
makes the gradient look like it grows and shrinks forever.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 21 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
After running your project, you should see something like this:
The Repeat
Next, we want to create a LOT of gradients. Since we have our function ready to do, all we need to do is
change setup to run a loop so that we build enough objects to run across the screen.
Do this:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 22 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
gradients.append(createGradient(Point(x,canvas.center.y)))
x += 3.0
} while x < canvas.width
}
We want to keep track of our gradients, so we create an array that will hold them for us.
The Timer
Let’s bring those gradients to life with a timer.
Then, back inside setup and after the repeat loop, add the following:
This bit of code creates a new timer that fires 50x per second (i.e. 0.02, and once for every gradient in our
array (i.e. gradients.count).
Since the timer starts its step at 0, the following lines of code grab the next gradient in the array and
animate it:
let g = self.gradients[self.timer.step]
self.createAnim(g)
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 23 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
w10
00:10
EXPERIMENT!
Now that you’ve created your waves, try playing around with some variables.
In the createGradient function, you can add a transformation to the gradient like so:
g.transform.rotate(M_PI_4)
Try changing the variable to 0.05, 0.2, and M_PI_4 to see some unique renderings.
Also, try playing with any of the other variables in the code!
Code
You can grab a copy of the code for this section from here
Layers
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 24 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
In C4 all visible objects are layers. You can add them on top of one another, send them to the front or back,
or change their z-position. More importantly, you can add a layer to another layer. A powerful component of
C4, you can take advantage of the layering mechanism to create brilliant and complex effects.
In this section you’ll build a simple loop to create a layered effect. You’ll then be able to explore layers by
making slight modifications to that loop.
The Loop
Start by adding 20 circles to the canvas, each with a unique size, alternating colors, and set
its anchorPoint to its bottom-center.
if i % 2 == 0 {
s.fillColor = C4Pink
}
canvas.add(s)
}
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 25 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Notice how the bottom of each shape is right on the center of the screen? This is because we changed
the anchorPoint of each shape before centering it. When you change the center property of a visible
object, the object will orient itself based on its anchorPoint.
Simple Animation
Currently, the shapes are layered directly on top of one another. To see them in action, create the following
function:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 26 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
}
a.animate()
}
This will make a specific shape perform a 180 degree rotation over the course of 1 second.
Now, add a call to this animation after adding the shape to the canvas, like so:
L02
00:10
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 27 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Delayed Rotation
Now, let’s offset the starting of each object’s animation by a fraction of a second.
This function adds a delay to the animation, then when the animation completes it sets that value back
to 0.0. Setting the delay back to zero means the delay happens only on the first iteration of the animation.
L03
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 28 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:10
Or, simply removing the a.delay = 0.0 will cause the animation to look generative or chaotic.
Embedded Layers
The previous examples added each shape to the canvas. Now, we’re going to add each successive shape
to the previous one.
if i % 2 == 0 {
s.fillColor = C4Pink
}
if i == 1 {
s.center = canvas.center
canvas.add(s)
} else {
s.center = previous.bounds.center
previous.add(s)
}
previous = s
}
}
Outside the setup you create a variable to keep a reference to the previous shape. Then, you loop
through all 20 shapes in much the same way as the prior setup.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 29 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
This does two different things: 1) it adds the first object, i.e. if i == 1, to the canvas otherwise it adds
the new object to the previous one. 2) After setting up an object, it sets it to the previous variable,
i.e. previous = s so the next object can reference it.
Notice, the first shapes anchor to the center of the previous shape. You can’t see all the shapes because
they are positioned off-screen.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 30 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
L05
00:09
Too Quick
Pretty fast right??? Try changing the duration of the animation to 5.0, do this for
both basicRotate and delayRotate.
Delay Rotate
Add this call to setup in place of basicRotate:
Try playing with some variables for delayTime, and removing the a.delay = 0.0
L06
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 31 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:08
Randomize!
The last step we’re going to take is to use a timer to trigger our animations.
if i == 1 {
s.center = canvas.center
canvas.add(s)
} else {
s.center = previous.bounds.center
previous.add(s)
}
previous = s
if i % 2 == 0 {
s.fillColor = C4Pink
}
shapes.append(s)
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 32 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
self.animate()
}
timer.fire()
timer.start()
}
func animate() {
for s in shapes {
ViewAnimation(duration: random01() * 0.75 + 0.25) {
let dir = random(below: 2) == 1 ? 1.0 : -1.0
let angle = random01() * M_PI_4
s.rotation += angle * dir
}.animate()
}
}
}
This setup is pretty close to our first examples, except that it doesn’t apply an animation to each shape.
Instead, it creates an array of shapes:
func animate() {
for s in shapes {
ViewAnimation(duration: random01() * 0.75 + 0.25) {
let dir = random(below: 2) == 1 ? 1.0 : -1.0
let angle = random01() * M_PI_4
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 33 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
For every shape in the array, it creates an animation with a random duration, i.e. random01() * 0.75 +
0.25, with a random angle and direction.
L07
00:08
FIN
As you can see, using layers is pretty rad. You can generate some interesting effects by playing with
simple animation delays and settings.
Code
You can grab a copy of the final code for this section here
Microbes
In this section we are going to build a little petri dish full of randomly moving microbes. To achieve a
generative effect we will use randomization throughout our example. We’ll also use a pan gesture to create
microbes. Invisible animated layers will make the motion of our microbes look more natural and complex.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 34 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
A Single Microbe
The concept for this example is this: as you drag your finger across the screen you give birth to little
microbes. They then scurry to the center of the screen, after which they disperse throughout an invisible
petri dish. Since all the microbes will have the same behaviour, all we need to do is create one and fine-
tune it’s behaviour.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 35 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
return microbe
}
1. It creates a little microbe (which is just a pink circle), whose colors shift from C4Pink to C4Blue
2. It creates an animation that moves the microbe randomly across the screen.
3. The animation repeats by adding itself to its own completion observer
M02
00:09
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 36 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
This randomized animation is essentially the final product of our example, but it’s a bit raw. By adding
characteristics and constraints, we’re going to make the microbe’s motion look good.
Modified Movement
Since we’re going to simulate microbes in a petri dish, we want their motion constrained to a circle. Let’s
modify the randomMove() function to do just that:
This function now uses polar coordinate math to calculate the random position of the microbe. Now, the
microbe will randomly move within 150 points of the center of the canvas.
Run the app now and you’ll see that the microbe never leaves the area around the center of the canvas.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 37 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
M03
00:10
Still Erratic
The microbe are still erratic and they should rest between moving. If there were a lot of microbes on the
canvas they would look like this:
M04
00:09
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 38 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
In randomMove() change:
duration: 0.5
… to:
This will set the time of the microbe’s movement to a random value between 2.0 and 7.0 seconds.
anim.delay = random01()
This will make sure there’s a random gap from 0.0 to 1.0 seconds between each movement.
When you run the example now, you’ll see that the microbe moves much slower and rests between its
movements. This slow pace is okay because the end result of our sketch will have a lot of microbes
moving at the same time.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 39 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
self.randomMove(microbe)
}
anim.animate()
}
The pan gesture creates a microbe at its current location, adds it to the canvas and then starts its
movement. The calls to disableActions are helpers to make sure that the color and line width styles
don’t animate when we create the shapes.
M05
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 40 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
00:07
As you drag your finger across the screen the number of microbes continues to get bigger. Let’s now add a
function that will randomly remove them from the screen after a time.
self.fade(microbe)
The fade function adds an animation that has a long delay, between 5.0 and 10.0 seconds. When it
triggers, the microbe will fade out and then remove itself from the canvas.
If you run the example now you should see the microbes fading out as you constantly move your finger.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 41 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
self.randomMove(microbe)
self.fade(microbe)
… with:
self.moveToCenter(microbe)
The Petris
This step will apply a nice effect to the motion of the microbes. You will create 2 invisible petri dishes,
rotate them in random directions. After adding each of the microbes to one of the dishes the rotation of that
dish will get applied to the motion of the microbe.
This step requires a lot of little changes. Instead of walking through them step-by-step, we’ll just look at the
concept of each step. At the end, you’ll be able to grab a copy of the final code for this section.
This will allow us to reference them after we create and add them to the canvas.
func createPetris() {
for _ in 0...5 {
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 42 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
The more petris we have the more random the motion will be in the final example.
Fin
Our final result looks nice. We have applied randomness to movements and rotations, and have
dynamically layered the microbes. On top of that, we’ve created microbes from a pan gesture and gave
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 43 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
them a nice centering animation. Finally, we remove old microbes from the canvas to make way for new
generations of interaction.
M06
00:05
Code
You can grab a copy of the final code for this section from here.
Spark
C4 is great at creating animations between states, and since it uses Core Animation it is efficient at
drawing. But, it can also handle running dynamic animations at high frame rates. In this tutorial you’ll learn
how to create a displayLink to achieve near 60fps animations. You’ll also learn how to use masks and
modify the points of a shape.
Going through this section step-by-step is possible, but not the greatest use of time. Instead, we will
discuss the major points of the sketch. This will focus us on experimenting with initial variables to achieve
different aesthetic effects.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 44 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Grab a copy of the code for this project from here, and follow along.
Three Shapes
The shape we’re going to be playing with consists of 3 shapes:
An outer polygon
An inner polygon
A mask polygon
The effect will be this: the outer shape will appear masked by the inner shape. Here’s a breakdown of the
layers:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 45 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Overlaid layers
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 46 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Display Link
To run a frame-based animation you need to create a Display Link. This link will run a function whenever
the device redraws its screen. The device will always try to run as fast as possible, which means that your
animation will run as fast as the device, up to 60fps.
func initializeDisplayLink() {
let displayLink = CADisplayLink(target: self, selector: "update")
displayLink.addToRunLoop(NSRunLoop.mainRunLoop(), forMode: NSDefaultRunLoopMode)
}
Updating
The algorithm for updating points is straightforward. First, here is the function that gets called by the
display link:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 47 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
func update() {
ViewAnimation(duration: 0) {
self.inner.points = self.randomize(self.inner.points, radius: self.radius.1)
let maskPoints = self.randomize(self.innerMask.points, radius: self.radius.0)
self.innerMask.points = maskPoints
self.outer.points = maskPoints
}.animate()
}
This update() randomizes the inner points, randomizes the mask points, then sets both the mask and
outer polygons to have maskPoints.
This takes a given set of points and a default radius. It then iterates through each point, and for ~40% of
the time (i.e. anything over 600) it randomizes the radius. It calculates the current point’s distance to the
shape’s center, then adds +/- 5%.
Then, it recalculates the new point based on the new radius and updates the points array.
Customizations
You can find a wide variation of aesthetics by changing only a few initial variables.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 48 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
if rand < 0.9 ... Adjusts the probability of a point being updated
random(min: 90, max: 110) Adjusts the percent increase or decrease for the point (this value
is currently +/- 10%
let θ = ... Adjusts the calculated angle for the new point
Fire Burst
S05
00:10
var pointCount = 90
var radius = (60.0, 50.0)
var lineWidths = (1.0, 0.5)
var primaryColor = orange
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 49 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Pink
S06
00:10
var pointCount = 90
var radius = (60.0, 50.0)
var lineWidths = (1.0, 0.5)
var primaryColor = C4Pink
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 50 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
}
return points
}
Rotating Emerald
var pointCount = 90
var radius = (60.0, 50.0)
var lineWidths = (1.0, 0.5)
var primaryColor = green
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 51 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Blue Spark
S08
00:10
var pointCount = 90
var radius = (50.0,58.0)
var lineWidths = (2.0,0.5)
var primaryColor = C4Blue
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 52 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Fin
Try playing around with the settings to see what you come up wtih.
Code
You can grab a copy of the code for this project from here.
Bands
Let’s up our game now and get into complex interactions by creating a canvas for you to animate abstract
patterns using your fingertips. We’re going to add 9 interactions to each pattern object, and two to the main
canvas. With all these gestures kicking around we’ll have to be careful to balance the order and timing of
their execution.
Before we get going, let’s have a look at what we’re going to build!
Concept
To cap off this intro to C4, we wanted to build an app that would allow you to create some trippy abstract
animations. This app should be more than a simple sketch, it should allow you to add, animate, manipulate
(i.e. move or rotate) and delete objects. It should also allow you to screen cap your apps and save them
directly to your phone’s photos library. AND, it should do all that in a simple way.
You can also use the default preview to share your vids via message, twitter, email, etc.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 53 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
The Bands
The main component of this app are the bands. A band is a type of shape that has eight distinct gestures,
four of which create lines that animate across the face of the band. The other five gestures allow you to
move, rotate, toggle its line / background, and delete the shape from the canvas.
Swiping on a band will cause a line to start animating across the band in the direction of the swipe (Up,
Down, Left, or Right).
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 54 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Holding down on a band for a short time will cause it to go into “move” mode, where you can drag it around
the screen.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 55 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 56 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 57 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Bands are opaque by default. If one is on top of another it will block the other’s content.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 58 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 59 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 60 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
If you triple-tap a band it will disappear and remove itself from the canvas.
A Shell of a Band.swift
Let’s start out by building the band class. We’ll do this in steps so that you can demo your progress as you
go along.
Create a new C4 project. Then, add a new file called Band.swift to your project. You can create a new
file either by right-clicking on the project navigator and choosing New File ..., or hitting CMD+N.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 61 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
In that new file you can copy and paste the following:
//import C4
import UIKit
func addRotation() {
//rotates the band
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 62 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
func addSwipes() {
//Four swipes will add lines
}
func addTaps() {
//triple tap to remove the object
//double tap to toggle the background
//single tap to toggle the border
}
func addPan() {
//moves the shape around the canvas
}
}
This shell contains ALL of the function s and variables we will need to make a Band. As we go along we
will fill in each of the functions… Starting with setupIn(canvas:).
Setup
Now, we’ll want to see a band pretty soon… So, we should style it. Modify setupInCanvas: to look like
this:
The important part here is that we save a reference to an object called canvas. The canvas is the view in
which the band is going to exist – i.e. it’s superview.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 63 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
WorkSpace
Now, to see something in action you can switch to WorkSpace.swift where you will add a function that
creates a new band. You’ll apply the same process as with Band.swift by first adding the following
functions:
import UIKit
func canvasLongPress() {
//adds a longpress gesture to create a band
}
func canvasStartRecording() {
//adds a longpress gesture to start recording
}
}
Creating a Band
The only thing we need to worry about (for now) with the main WorkSpace is adding a gesture that will
create a new band.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 64 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
func canvasLongPress() {
var currentBand: Band?
var position = Point()
canvas.addLongPressGestureRecognizer { (locations, center, state) -> () in
switch state {
case .Began:
ShapeLayer.disableActions = true
position = center
currentBand = self.createBand(position, displacement: Vector())
self.canvas.add(currentBand)
case .Changed:
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 65 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Go ahead and modify the canvasLongPress in your WorkSpace to look like the above.
The Variables
Since the current band will be constantly updated we need to have a local reference to it. We also need to
store the center point of the shape.
.Began
This state gets triggered only once each time the user starts a new long press gesture. In this state you set
the center variable to the location of the gesture, and then set the variable currentBand to a newly
initialized Band. You then add the new band to the canvas.
You can pass a zero Vector (i.e. {0,0,0}) because the user hasn’t yet moved their finger.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 66 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
case .Began:
ShapeLayer.disableActions = true
position = center
currentBand = self.createBand(position, displacement: Vector())
self.canvas.add(currentBand)
Finally, you’ll notice that we set the following: ShapeLayer.disableActions = true. This line
tells C4 to create zero-second animations… That is, we want our bands to be created and styled
instantaneously.
Technically, in Core Animation an animation is created using an action. Actions define dynamic
behaviors for a layer. For example, the animatable properties of a layer typically have
corresponding action objects to initiate the actual animations.
.Changed
This is where things happen. Any time the user moves their finger, after a longpress is initiated,
the .Changed state will occur. This can happen dozens of times a second, which is why we previously
disabled animations.
Every time the user’s finger moves we run the following logic: determine how far their finger is from the
center of the shape, create a new band, remove the current band, update the current band to the new
band, add the new band to the canvas.
case .Changed:
let dxdy = Vector(center) - Vector(position)
let newBand = self.createBand(position, displacement: dxdy)
currentBand?.removeFromSuperview()
currentBand = newBand
self.canvas.add(currentBand)
An in-depth explanation of the Shape class is beyond the scope of this tutorial, so I won’t go into
detail. However, it’s important to note that C4 is very fast, so creating a new shape on the fly
instead of manipulating the path of the current band is an efficient process.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 67 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
.Ended
When the user removes their finger from the screen we want to re-initiate the ability to create animations.
case .Ended:
ShapeLayer.disableActions = false
Run it.
Now that you have a basic Band class, and the necessary interactions attached to the canvas, you can
test it out.
To make sure the gesture gets created, update the setup in WorkSpace to look like:
Band.swift
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 68 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Pop back over to the Band class, which is where you’ll be working for a while. The goal is to add 9
gestures in such a way that they don’t collide with one another, making it fairly easy for the user to
manipulate each object in different ways. We’ll approach this task in the following order:
1. Taps
2. Swipes
3. Pan
4. Rotation
5. Rotation Animation
Taps
There are 3 distinct tap gestures we will apply to each Band. They are:
func addTaps() {
let tt = addTapGestureRecognizer { locations, center, state in
}
addTaps()
At any point, if you don’t see your taps having an effect, it’s probably because you need to add the
last line of code in the Band setup function.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 69 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Straightforward. There are 3 distinct taps, so we create 3 a separate gesture recognizer for each one.
Single Tap
The single tap gesture needs to toggle the visibility of the object’s border. This can be done by either
changing its color to clear or by changing its width to 0.0. We’re going to go with the latter approach:
This uses the current lineWidth of the object to toggle its visibility.
Double Tap
The double tap gesture is fairly similar, however, instead of toggling a value we will toggle a color.
Triple Tap
This gesture should remove the object from the canvas. Instead of simply removing the object, we will
create an animaiton that fades and shrinks it prior to its removal.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 70 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
This step scales the object to 10% of its natural size while fading it out. When the animation completes – at
which point the object is invisible – the animation then triggers the removal of the object.
tt.numberOfTapsRequired = 3
dt.numberOfTapsRequired = 2
This makes each gesture require a unique number of touches. By default all gestures st require 1 touch,
which is why we don’t need to specify anything for st.
If you run this again you’ll notice that you can single tap without triggering the other gestures.
However, a double tap will trigger both st and dt, and a triple tap will trigger all three cases.
We’ve separated the gestures by the number of touches, now we need to separate them by only allowing
them to trigger if the others are not activated.
dt.requireGestureRecognizerToFail(tt)
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 71 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
t.requireGestureRecognizerToFail(dt)
The double tap will wait a fraction of a second to make sure it isn’t part of a triple tap. It will only
execute if tt fails.
The single tap will wait a fraction of a second to make sure it isn’t part of a double tap. It will only
execute if dt fails.
Finito. Now you can run the app and make a bunch of bands and toggle their states.
Swipes
The effect of a swipe on a band is to create a line that moves across the band in the direction of the swipe.
So, to create this interaction we need to both create lines, animate lines, AND have each gesture (there
are 4 of them) set up the line and animate it accordingly.
Creating Lines
Initializing a Line requires a tuple of Point structs. Since we’re going to create a lot of lines the function
should return a Line object.
This takes a tuple, (Point, Point) and a width (which we use to style the line). It then constructs a line
with the colors, sizing, etc., and returns it.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 72 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Animating Lines
Animating a line is trivial, it requires access to a line as well as the target position to which it will animate.
On their own, neither the create, nor animate functions do very little. Let’s add some swipes to see them in
action.
Right Swipe
The default direction for a swipe is .Right, so we can start with this case.
let w = 10.0
addSwipeGestureRecognizer { locations, center, state, direction in
let points = (Point(-w/2.0, 0), Point(-w/2.0, self.height))
let line = self.createLine(points, w: w)
self.add(line)
self.animateLine(line, to: Point(self.width+w/2.0, line.center.y))
}
The w defines the width of the line. If you want your lines to have a dynamic width you can modify
this variable with some logic. For this exercise we will leave it at 10.0
This creates a line whose points lay vertically just off the left-side of the Band. It then animates the line by
passing a new Point where the x position has changed.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 73 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
For horizontal motion the x position changes, for vertical motion the y position changes.
Simple.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 74 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Pan
Moving an object around the screen requires a gesture that can track a user’s finger tip. There are two
functions that do this: pan and longpress. Since we already have swipe gestures attached to our object
the pan gesture won’t work for us… We need a little delay to make sure that none of the 4 swipes collide
with the movement of the object. So, we use a longpress.
func addPan() {
var dxdy = Vector()
let lp = addLongPressGestureRecognizer { locations, center, state in
switch state {
case .Began:
ShapeLayer.disableActions = true
dxdy = Vector(center)
self.strokeColor = C4Pink
case .Changed:
self.origin = self.canvas.convert(center, from: self) - dxdy
case .Ended:
self.strokeColor = C4Blue
ShapeLayer.disableActions = false
default:
_ = ""
}
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 75 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
lp.minimumPressDuration = 0.1
}
1. We create a dxdy variable to track the point of a user’s touch, inside a band, relative to the top-left
corner of the shape.
2. When the press begins, we disable implicit animations, set dxdy and change the
object’s strokeColor to give a visual reference that the shape is in move mode.
3. When the user drags their finger we update the origin of the shape using dxdy as a reference
4. When the user is finished, we enable actions and set the strokeColor back to its original state.
Since we want to move the object within the canvas this is why we need to have a variable that
stores the reference. If we tried to update the object based on its own coordinate system the
shape would move out of control and very quickly zoom off screen.
Rotation
Rotating an object is as straightforward as the last step.
func addRotation() {
rotationGesture = addRotationGestureRecognizer { rotation, velocity, state in
switch state {
case .Began:
ShapeLayer.disableActions = true
case .Changed:
self.rotation = rotation
case .Ended:
ShapeLayer.disableActions = false
default:
_ = ""
}
}
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 76 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Each time the gesture changes, the shape’s rotation gets updated.
Rotation Animation
Let’s add another dimension to this rotation. If the user rotates the shape fast enough it should start
animating its rotation.
To do this we will need an animation and a bit of logic. Let’s start with the logic:
Modify the .Changed state of the rotation gesture to look like this:
case .Changed:
self.rotation = rotation
if abs(velocity) >= 10 {
self.rotationGesture?.enabled = false
self.createRotationAnimation(velocity / 10.0)
}
This checks the current velocity of the gesture, and if it is greater than 10.0 we disable the gesture and
start an animation based on the velocity’s value.
Disabling the gesture is critical here, because we only want to trigger the animaiton the first time
its velocity passes the 10.0 threshold. Also, once its animating we don’t want the user to be
able to rotate it again…
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 77 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
This uses the multiplier, which should be between 1.0 and 3.0 (it’s hard to get a rotation velocity higher
than 30), to calculate the rotation direction and the duration of the animation.
The rotation will either be - or + (clockwise or counterclockwise), so we use the following line to set the
angle:
This creates a full 360° rotation, and multiplies that by -1.0 or 1.0 depending on the value of the
multiplier.
Depending on the value of the velocity the duration of the animation, 4.0 / abs(multiplier), will be
somewhere between 4.0s and 1.33s (i.e. between 4/1.0 and 4/3.0).
func canvasStartRecording() {
startRecording = canvas.addLongPressGestureRecognizer { location, center, state in
self.startRecording?.enabled = false
let v = View(frame: self.canvas.frame)
v.backgroundColor = C4Pink
self.canvas.add(v)
a.addCompletionObserver {
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 78 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
v.removeFromSuperview()
self.recorder.start(10.0)
}
a.animate()
}
startRecording?.numberOfTouchesRequired = 3
}
self.recorder.recordingEndedAction = {
self.recorder.showPreviewInController(self)
self.startRecording?.enabled = true
}
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 79 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
3. creates a little C4 logo and puts it in the bottom corner of the canvas.
4. the zPosition = 1000 makes sure the logo is always above the other objects
Try it!
All you need to do now is try out the app, save a few vids, and share them if you want!
If you share via Twitter, please tag with @C4Framework so we can see what you’ve made!
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 80 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Bands Demo
00:36
Code
You can grab a copy of the code for this project from here
The Beginning
This tutorial introduced you to creative-coding on iOS with C4 by introducing you to some key concepts,
like: Properties, Layers, Animations and Gestures. From highly experimental interactive experiences to
polished apps, you’ve now seen a variety of works that have been created using the framework.
Throughout the writing of this tutorial we were continuously adding new features like
the locationsvariable in gestures, the ScreenRecorder and Camera objects. So, the code you’ve
been writing is the most cutting-edge release of C4. But, it’s far from complete. Now that the new Swift
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 81 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
version of the core API is stable, it’s time to start building out new components and addons. This is the
beginning of a new chapter in C4’s growth and we’re really excited that you’ve been able to see where it is
and what it can become.
Tweet ...
F I L E D U N D E R : iOS, Tutorials
TA G G E D W I T H : c4, c4framework, code, creative coding, generative, ios, iPad, iPhone, learning
by Travis
Travis is an artist, researcher and interaction designer specializing in the production of interactive
installations and creative applications. He holds an MA in Interface Culture, as well as a BSc
Interactive Arts / Interaction Design. Travis is the creator of C4.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 82 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Advertisment
If you create
interactive experiences you’ll want to be at the fourth annual INSTINT in New Orleans. Brought to you by same the team behind the always
inspiring Eyeo Festival, the event assembles an international roster of artists/makers/designers who explore the intersection of art, technology and
interaction. Read more.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 83 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Featured Jobs
Software Project Manager at Cinimod Studio — Cinimod Studio is currently looking for a Software Project Manager to lead our
creative software and 3D Art team.
Lead Front-End Developer at Gallagher & Associates — Gallagher & Associates is looking for a diversely talented Lead Frontend
Web Developer.
Creative iOS developer at Feeld — Feeld in London are looking for a Creative iOS developer with experience working with Processing,
Javascript, OF, Cinder etc.
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 84 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Research and Teaching Assistant at Film University Babelsberg Konrad Wolf — Film University Babelsberg KONRAD WOLF
follows an interdisciplinary approach to the artistic, technological, and academic teaching and research on the universal subject of film.
Assistant Professor (Tenure Track) in Sculpture and Emerging Technologies at University of Maryland Department
of Art — The Department of Art at the University of Maryland invites applications for an Assistant Professor, full-time, tenure-track faculty
position in Sculpture and Emerging Technologies to begin in August 2017.
Social
Follow @creativeapps
Newsletter
Advertisment
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 85 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Shop
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 86 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
About
© 2015 CreativeApplications.Net
Licensed under a Creative Commons License.
Sections
Blog
Magazine
Events
Shop
Jobs
Apps
Quick Links
About
Advertise
Contact
Submit Project
Membership
Tools
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 87 of 88
Creative-coding on iOS with @C4Framework – Tutorial 2020/12/06 18:14
Follow
Twitter
Facebook
Vimeo
Kickstarter
GitHub
RSS Feed
Thank you
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will
assume that you are happy with it. Ok
https://web.archive.org/web/20161115152014/https://www.creativeapplications.net/tutorials/creative-coding-on-ios-with-c4-tutorial/ Page 88 of 88