Author Archives: efe

Book review: Cinder – Begin Creative Coding

Being one of the youngest and most powerful creative coding libraries, Cinder is a complex and elegant toolkit written in C++. Due the professional nature of its implementation, it is also one of the hardest to learn. This book will guide the reader from setting up a basic Cinder project to create graphics using OpenGL and Cairo, create sound playbacks and the use of user events.
Targeted for artists and designers, the book hides all the complex C++ technical details in order to introduce the user to specific topics. Each chapter is precise and concise, addressing specific technical problems with a direct and friendly language. For instance,
Chapter 8 has a nice introduction to 3D and how matrix stacks work. Although a little opaque, the chapter tackles the complex topic of OpenGL in a friendly way.
The book opens with a definition of creative coding and how to setup the library. It also makes a clear distinction between the use Cinder on mac and on windows. Chapter 2 gives a general overview of what the library is capable of doing.
Chapter 3 is an introduction to the development IDE and Cinder native tool ‘TinderBox’.
Chapters 4 to 8 deal with the topic of computer graphics. Chapter 9 and 10 provide a final overview to the use of sound files and events.The book finishes with an useful appendix of the Cinder types, a valuable technical resource for the beginner.
Leaving the reader at the gates of boost, STL, GLSL and elsewhere, this book is an interesting incorporation to the emerging creative c++ coding literature.

I think this book is a starting point for beginners willing to jump into to huge ocean of c++. I would recommend getting along a good c++ and openGL reference, patience to handle the IDE and lot of good will. The experience will pay back!

Link to the book:

https://www.packtpub.com/begin-creative-coding-with-cinder/book

Generic study # 2 and vectors

One of the most common bottlenecks I have experienced when porting processing sketches into iOS/OFW is the way to pass vectors into classes. There is a good share of discussion if passing by object, reference or pointer is the best option. The answer to that question relies deeply in the context of the porting and the usability of the whole project.

In my case, I like my good share of vector pointers for my particle/chaos systems. So I decided to write a very small example of how to pass vectors of pointers as references. Notice the huge amount of notes! C++ is a huge jungle so forget about unique ways of reaching a result. You can notice, for instance, that my constructor has a different way to assign the vectors. Also that the function that applies arithmetic to the vector can be called directly from the main loop or from the class itself. Matter of taste. Finally, I declared the class generically (maybe our particles systems might have different types).

#include <iostream>
#include <vector>
#include "PassVector.h"

using namespace std;

int main(int argc, const char * argv[])
{
    vector<int*>randomValuesA;
    vector<int*>randomValuesB;
    
    PassVector<int> mPassVector;
    
    for(unsigned int i=0;i<10;i++){
        randomValuesA.push_back(new int(rand()%100));
        randomValuesB.push_back(new int(rand()%100));
    }
    
    mPassVector = PassVector<int>(randomValuesA,randomValuesB);
    //passing the values from the main loop//////////////////////////////
    //mPassVector.addTheReferences(randomValuesA, randomValuesB);
    mPassVector.addTheReferences();
    
    return 0;
}

The PassVector class. It is generic!

#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class PassVector{
public:
    
    PassVector(){
        
    }
    
    PassVector(vector<T*>&_vecA,vector<T*>&_vecB):vecA(_vecA),vecB(_vecB){
        //if you are more into the java-ish style
        //vecA = _vecA;
        //vecB = _vecB;
    }
    
    ~PassVector(){
        
    }
    
    //create new vectors containing info related with speed, physics and etc
    //you might want to use iterators for calling functions here
    void addTheReferences(){
        for(unsigned int i=0;i<vecA.size();i++){
            addedVectorsAsReferences.push_back(new T(addPoinerValues(vecA[i], vecB[i])));
            cout<<"adding the value "<<*addedVectorsAsReferences[i]<<" at index "<<i<<endl;
        }
    }
    
    /*
     //passing the values directly from the main loop
    void addTheReferences(vector<T*>&v1,vector<T*>&v2){
        for(unsigned int i=0;i<v1.size();i++){
            addedVectorsAsReferences.push_back(new T(addPoinerValues(v1[i], v2[i])));
            cout<<"adding the value "<<*addedVectorsAsReferences[i]<<" at index "<<i<<endl;
        }
    }
     */
    
    //this function for any pointer arithmetic 
    T addPoinerValues(T* x, T* y){
        return *x + *y;//+,/,-, %
    }
    
    vector<T*>vecA;
    vector<T*>vecB;
    //new values
    vector<T*>addedVectorsAsReferences;
    
};

happy coding!

Maison Lumière preview

We are preparing the interactive installation ‘Maison Lumière’ for the Lighthouse Festival at Korzo Theater. So far so good, it has been a very enjoyable process.
The installation allows you to tweet and the letters to be displayed as part of a ‘wind’ moving the letters all over the place. Also you can control the ‘shape’ of the wind with a kinect input that we are still calibrating (hand detection can be really seriously tricky!).
On the visual side, I decided to use scattering light as the installation will be projected over the huge glass gate at the entrance of the theater. We want to provide the metaphor of ‘welcome to the lighthouse’. The ‘leaves’ of the design remind me of origami giving a very childish and playful feeling to it.

Generic study # 1

More and more I study the Cinder architecture more I am amazed how well written it is and how nice c++ can be when used properly. I strongly suggest any creative cpp coder to go and open the guts of our friend, there are some revealing lessons waiting there.
Two things in Cinder architecture that I love the most are generics and shared pointers. The later would require to speak about Boost (which itself is amazing and huuuuuuuuge). Generics are nice and useful. They can be tricky when mixed with iterators and some other STL facilities but in general are quite straight forward to implement and they can save loads of code when writing classes with flexible data types. So here a small small study on that, very simple but useful to start exploring this side of c++.

#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

template <typename T>
class Adder{
	public:
	Adder(){}
	Adder(T _x, T _y):x(_x), y(_y){}
	~Adder(){}
	
	T addValue(){
		return x+y;
	}
	
	T restValue(){
		return x-y;
	}
	
	protected:
	T x,y;
	
};


template <typename T>
class AdderRef{
	public:
	AdderRef();
	AdderRef(const T &_x, const T &_y):x(_x),y(_y){}
	~AdderRef(){}
	
	T addValueRef(){
		return x+y;
	}
	
	protected:
	T x, y;
};

template <typename T>
class RandomNumber{
	public:
	RandomNumber(){}
	~RandomNumber(){}
	
	void setValue(){
		number = (T) random() % (T)50;
	}
	
	
	T getValue(){
		return number;
	}

	
	protected:
	T number;
};

template <typename T>
class NumberIter{
	public:
	NumberIter(){}
	~NumberIter(){}
	
	void createNumbers(){
		for(unsigned int i=0; i<10; i++){
			RandomNumber<T> number;
			number.setValue();
			mNumbers.push_back(number);
		}
	}
	
	
	void printNumbers(){
		for(rIter r = mNumbers.begin(); 
		r != mNumbers.end(); ++r){
			cout<<r->getValue()<<endl;
		}
	}
	
	protected:
	std::vector< RandomNumber<T> > mNumbers;
	typedef typename std::vector< RandomNumber<T> >::iterator  rIter;

	
};



////////////////////////////////////////////
//main loop

int main(){
	
	int x = 10;
	int y = 20;
	
	Adder<int> mAdder(10,20);
	AdderRef<int> mAdderRef(x,y);
	
	cout<<"this is adding the values: "<<mAdder.addValue()<<endl;
	cout<<"this is the adding with references: "<<mAdderRef.addValueRef()<<endl;
	
	//testing the random number generator
	
	RandomNumber<int> mNumber;
	mNumber.setValue();
	cout<<mNumber.getValue()<<endl;



	NumberIter<int> mNumberIter;
	mNumberIter.createNumbers();
	mNumberIter.printNumbers();
	
	
	
	return 0;
}

Notice that there is not a generic+pointers example. That is topic for later and which will include an intro to our dear friends the smart pointers.

Is this the first step for a c++ Frankenstein->mix well Cinder, OFW and et al!

Page 1 of 512345