Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Cinder Creative Coding Cookbook
Cinder Creative Coding Cookbook

Cinder Creative Coding Cookbook: If you know C++ this book takes your creative potential to a whole other level. The practical recipes show you how to create interactive and visually dynamic applications using Cinder which will excite and delight your audience.

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Cinder Creative Coding Cookbook

Chapter 2. Preparing for Development

In this chapter, we will cover:

  • Setting up a GUI for tweaking parameters

  • Saving and loading configurations

  • Making a snapshot of the current parameter state

  • Using MayaCamUI

  • Using 3D space guides

  • Communicating with other software

  • Preparing your application for iOS

Introduction


In this chapter, we will introduce several simple recipes that can be very useful during the development process.

Setting up a GUI for tweaking parameters


Graphical User Interface (GUI) is often required for controlling and tuning your Cinder application. In many cases, you spend more time tweaking the application parameters to achieve the desired result than writing the code. It is true especially when you are working on some generative graphics.

Cinder provides a convenient and easy-to-use GUI via the InterfaceGl class.

Getting ready

To make the InterfaceGl class available in your Cinder application, all you have to do is include one header file.

#include "cinder/params/Params.h"

How to do it…

Follow the steps given here to add a GUI to your Cinder application.

  1. Let's start with preparing different types of variables within our main class, which we will be manipulating using the GUI.

    float mObjSize;
    Quatf mObjOrientation;
    Vec3f mLightDirection;
    ColorA mColor;
  2. Next, declare the InterfaceGl class member like this:

    params::InterfaceGl mParams;
  3. Now we move to the setup method and initialize our GUI window passing...

Saving and loading configurations


Many applications that you will develop operate on input parameters set by the user. For example, it could be the color or position of some graphical elements or parameters used to set up communication with other applications. Reading configurations from external files is necessary for your applications. We will use a built-in Cinder support for reading and writing XML files to implement the configuration persistence mechanism.

Getting ready

Create two configurable variables in the main class: the IP address and the port of the host we are communicating with.

string mHostIP;
int mHostPort;

How to do it...

Now we will implement the loadConfig and saveConfig methods and use them to load the configuration on application startup and save the changes while closing.

  1. Include the two following additional headers:

    #include "cinder/Utilities.h"
    #include "cinder/Xml.h"
  2. We will prepare two methods for loading and saving the XML configuration file.

    void MainApp::loadConfig()...

Making a snapshot of the current parameter state


We will implement a simple but useful mechanism for saving and loading the parameters' states. The code used in the examples will be based on the previous recipes.

Getting ready

Let's say we have a variable that we are changing frequently. In this case, it will be the color of some element we are drawing and the main class will have the following member variable:

ColorA mColor;

How to do it...

We will use a built-in XML parser and the fileDrop event handler.

  1. We have to include the following additional headers:

    #include "cinder/params/Params.h"
    #include "cinder/ImageIo.h"
    #include "cinder/Utilities.h"
    #include "cinder/Xml.h"
  2. First, we implement two methods for loading and saving parameters:

    void MainApp::loadParameters(std::string filename)
    {
      try {
        XmlTree doc( loadFile( fs::path(filename) ) );
        XmlTree &generalNode = doc.getChild( "general" );
    
            mColor.r = generalNode.getChild("ColorR").getValue<float>();
            mColor.g...

Using MayaCamUI


We are going to add to your 3D scene a navigation facility known to us since we modelled a 3D software. Using MayaCamUI, you can do this with just a few lines of code.

Getting ready

We need to have some 3D objects in our scene. You can use some primitives provided by Cinder, for example:

gl::drawColorCube(Vec3f::zero(), Vec3f(4.f, 4.f, 4.f));

A color cube is a cube with a different color on each face, so it is easy to determine the orientation.

How to do it...

Perform the following steps to create camera navigation:

  1. We need the MayaCam.h header file:

    #include "cinder/MayaCamUI.h"
  2. We also need some member declarations in the main class:

    CameraPersp  mCam;
    MayaCamUI    mMayaCam;
  3. Inside the setup method, we are going to set up the camera's initial state:

    mCam.setPerspective(45.0f, getWindowAspectRatio(), 0.1, 10000);
    mMayaCam.setCurrentCam(mCam);
  4. Now we have to implement three methods:

    void MainApp::resize( ResizeEvent event )
    {
        mCam = mMayaCam.getCamera();
        mCam.setAspectRatio(getWindowAspectRatio...

Using 3D space guides


We will try to use built-in Cinder methods to visualize some basic information about the scene we are working on. It should make working with 3D space more comfortable.

Getting ready

We will need the MayaCamUI navigation that we have implemented in the previous recipe.

How to do it...

We will draw some objects that will help to visualize and find the orientation of a 3D scene.

  1. We will add another camera besides MayaCamUI. Let's start by adding member declarations to the main class:

    CameraPersp     mSceneCam;
    int             mCurrentCamera;
  2. Then we will set the initial values inside the setup method:

    mCurrentCamera = 0;
        
    mSceneCam.setEyePoint(Vec3f(0.f, 5.f, 10.f));
    mSceneCam.setViewDirection(Vec3f(0.f, 0.f, -1.f) );
    mSceneCam.setPerspective(45.0f, getWindowAspectRatio(), 0.1, 20);
  3. We have to update the aspect ratio of mSceneCamera inside the resize method:

    mSceneCam.setAspectRatio(getWindowAspectRatio());
  4. Now we will implement the keyDown method that will switch between two...

Communicating with other software


We will implement an example communication between two Cinder applications written in Cinder to illustrate how we can send and receive signals. Each of these two applications can be replaced by a non-Cinder application very easily.

We are going to use the Open Sound Control (OSC) messaging format, which is dedicated for communication between wide ranges of multimedia devices over the network. OSC uses UDP protocol, providing flexibility and performance. Each message consists of URL-like addresses and arguments of integer, float, or string type. The popularity of OSC makes it a great tool for connecting different environments or applications developed with different technologies over the network or even on the local machine.

Getting ready

While downloading the Cinder package we are also downloading four primary blocks. One of them is the osc block located in the blocks directory. First, we will add a new group to our XCode project root and name it Blocks,...

How it works...


We have implemented the sender application that sends the position of the mouse via OSC protocol. Those messages, with the address /obj/position, can be received by any non-Cinder OSC application implemented in many other frameworks and programming languages. The first argument in the message is the x axis position of the mouse and the second argument is the y axis position. Both are of the float type.

In our case, the application that receives messages is another Cinder application that draws a filled circle at exactly the same position where you point it in the sender application window.

There's more...


That was just a short example of the possibilities that OSC offers. This simple communication method can be applied even in very complex projects. OSC works great when several devices are working as independent units. But at some point, data coming from them is processed; for example, frames coming from the camera can be processed by the computer vision software and results sent over the network to another machine projecting the visualization. Implementation on top of the UDP protocol gives not only performance, because of the fact that transmitting data is faster than using TCP, but also implementation is much simpler without a connection handshake.

Broadcast

You can send OSC messages to all the hosts on your network by setting a broadcast address as a destination host: 255.255.255.255. For example, in case of subnets, you can use 192.168.1.255 .

Tip

If you have problems with compilation under Mac OS X 10.7 because of a linker error, try to set Inline Methods Hidden to No in...

See also


You can find more information about OSC implementations by checking out the following links.

OSC in Flash

To support receiving and sending OSC messages in your ActionScript 3.0 code you can use the following library: http://bubblebird.at/tuioflash/

OSC in Processing

To support OSC protocol in your Processing sketch you can use following library: http://www.sojamo.de/libraries/oscP5/

OSC in openFrameworks

To support receiving and sending OSC messages in your openFrameworks project, you can use the ofxOsc add-on: http://ofxaddons.com/repos/112

OpenSoundControl Protocol

You can find more information about OSC protocol and related tools at its official site: http://opensoundcontrol.org/.

Preparing your application for iOS


The big benefit of using Cinder is the resulting multiplatform code. In most cases, your application can be compiled on Windows, Mac OS X, and iOS without significant modifications.

Getting ready

If you want to run your applications on iOS devices, you will need to register as an Apple Developer and purchase the iOS Developer Program.

How to do it...

After registering yourself as an Apple Developer or purchasing the iOS Developer Program, you can create an initial XCode project for iOS using Tinderbox.

  1. After running Tinderbox you have to set Target to Cocoa Touch.

  2. It will generate a project structure for you, supporting iOS events that are specific for multitouch screens.

    We can use events for multiple touches and for easy access to accelerometer data. The main difference between touch and mouse events is that there can be more than one active touch points while there is only one mouse cursor. Because of that, each touch session has an ID that can be read from...

Left arrow icon Right arrow icon

Key benefits

  • Learn powerful techniques for building creative applications using motion sensing and tracking
  • Create applications using multimedia content including video, audio, images, and text
  • Draw and animate in 2D and 3D using fast performance techniques

Description

Cinder is one of the most exciting frameworks available for creative coding. It is developed in C++ for increased performance and allows for the fast creation of visually complex, interactive applications."Cinder Creative Coding Cookbook" will show you how to develop interactive and visually dynamic applications using simple-to-follow recipes.You will learn how to use multimedia content, draw generative graphics in 2D and 3D, and animate them in compelling ways. Beginning with creating simple projects with Cinder, you will use multimedia, create animations, and interact with the user.From animation with particles to using video, audio, and images, the reader will gain a broad knowledge of creating applications using Cinder.With recipes that include drawing in 3D, image processing, and sensing and tracking in real-time from camera input, the book will teach you how to develop interesting applications."Cinder Creative Coding Cookbook" will give you the necessary knowledge to start creating projects with Cinder that use animations and advanced visuals.

Who is this book for?

This book is for artists, designers, and programmers who have previous knowledge of C++, but not necessarily of Cinder.

What you will learn

  • Process and analyze images and draw graphics in 2D or 3D
  • Create applications that use multimedia content including video, images, audio, and text
  • Draw and render particles to create powerful simulations
  • Animate using tweens, timeline, paths, and cameras
  • Create interesting animations with particle systems and physics
  • Interact with the user by tracking and sensing from the camera in real-time
  • Generate audio and create sound visualizations

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 23, 2013
Length: 352 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518703
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 23, 2013
Length: 352 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518703
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 117.97
Processing 2: Creative Coding Hotshot
€37.99
Mastering openFrameworks: Creative Coding Demystified
€37.99
Cinder Creative Coding Cookbook
€41.99
Total 117.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Getting Started Chevron down icon Chevron up icon
Preparing for Development Chevron down icon Chevron up icon
Using Image Processing Techniques Chevron down icon Chevron up icon
Using Multimedia Content Chevron down icon Chevron up icon
Building Particle Systems Chevron down icon Chevron up icon
Rendering and Texturing Particle Systems Chevron down icon Chevron up icon
Using 2D Graphics Chevron down icon Chevron up icon
Using 3D Graphics Chevron down icon Chevron up icon
Adding Animation Chevron down icon Chevron up icon
Interacting with the User Chevron down icon Chevron up icon
Sensing and Tracking Input from the Camera Chevron down icon Chevron up icon
Using Audio Input and Output Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(14 Ratings)
5 star 50%
4 star 28.6%
3 star 21.4%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Efrain Astudillo Jan 11, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book you can learn a lot with the basic theory that contains it. It's really easy to learn and very well explain with images. Believe me, you won't bore with this book
Amazon Verified review Amazon
john Jul 07, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Hi , i just want to start by a thankful to the author for his book. I'm new to Cinder, already i've done some projects with Processing and OpenFrameworks. This book is a very good starting point. In the first chapters everything is describe to start with cinder : make a new project ( for OSX WINDOWS , IOS). Then it work's like a real cookbook , " what you wanna do today :) ? " so you can jump between the chapters to make what you want ( and there is a lot of things, more than i could thought) . I've read some of chapter a this time and i discovered a powerful environment and great tips and workflow process .Each chapter is constructed with a "how to" , the part where you write the code with some little explanation of the different parts so you start with the magic and it's good to learn then a "how it works" to explain the code with subtlety and for the end some stuff to have More Fun with this code !!!!So what i think ? I recommended this book for anybody who wants to start or got an advanced level with Cinder.
Amazon Verified review Amazon
Thomas Helzle Jun 20, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I work with 3D for 20+ years, have coded in C and C++, Processing and other langauages and recently found out about Cinder through the work of Robert Hodgin (http://roberthodgin.com/) who's a real master of the art.The framework appealed to me, the available tutorials are very well written and inspiring...But you may know the moment when you understood the basics and the principles, but suddenly find out when you try to create your own projects, that you don't have the right questions to ask? You want to do something specific but are not sure yet where to look. The main cinder documentation beyond the tutorials and basic explanations is rather nerdy: namespaces, classes, files... so there's a serious gap between the tutorials and this main part.I know I can hack myself through this (and did so in the past), learn a lot by trial and error about things I never imagined, but it will take me a rather long time and sometimes this time would be better spent on other work.Enter stage left: "Cinder Creative Coding Cookbook" :-)On the cinder forum, the book was offered for review. I read the chapter list and it read basically like everything I wanted to do with Cinder - Not bad. So I applied and got the book.Now I can be pretty critical with books. Often they seem to be written for dummies or repeat themself all the time or overexplain stuff. I get impatient with such books really fast. ;-)No such things here: There isn't even a "hello world" example (which is a good sign IMO).From the first lines of code, you are expected to know what common stuff does and how things work in general programming.And right from the first chapter you do useful things: create your application files with Tinderbox, respond to mouse, key and touch input, deal with drag and drop, resize the window adjusting your content and use resources on windows and OSX/iOS. And that's just the first chapter of 12!The book continues at the same pace showing how to create a GUI, save and load parameters and presets as XML, use 3D space. In the third chapter you already use OpenCV to track features and recognize faces in images...It's well written, short and to the point, perfect for people like me who want to create right away without going through explanations what variables are...So to my great pleasure, I can wholeheartedly recommend this book to people coming from processing or other frameworks that have a general understanding of coding and audio-visual art, but want to take the next step with this very powerful C++ library.And that Cinder is worth your while was nicely proven some days ago, when it won the first "Innovation Grand Prix" at the "Cannes Lions International Festival of Creativity".Have fun creating!
Amazon Verified review Amazon
Sarith Demuni Jul 30, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The title of this book is exactly what it is -- a cookbook -- and boy is it delicious.That said, I would definitely follow the advice in the product description -- I think this book is a great buy for a beginner, but maybe don't crack it open until after you've spent a few months with creative coding (and C++).BUT -- if you've spent a good amount of time playing with other creative coding frameworks like Processing or openFrameworks, this book is a fantastic run-through of how Cinder handles things. More importantly, and wonderfully, it's chock full of great (general) creative coding recipes. Literally every single lesson is useful in some way and the ideas here are easily translatable to any creative coding language or framework. The book also manages to cut right to the good stuff after some of the intro materials which, as a post-beginner, I really appreciate.
Amazon Verified review Amazon
SuJo Jul 16, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Creative Coding Cookbook[...]I absolutely LOVED reading this book! I really enjoy the cause and effect style the author uses. When you a presented with an issue and given the work around it really helps cement your knowledge. All of the examples in the book are all usable and you can adapt them as you learn more.I like to keep my reviews short and simple but this book really is worth the cost!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.