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 eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781849518710
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 23, 2013
Length: 352 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518710
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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.