a gentle introduction to openframeworks

Post on 12-May-2015

5.026 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

The basics of openFrameworks within the context of Arduino and Processing. From a session at the ITP Camp 2011.

TRANSCRIPT

a gentle introduction to openFrameworks

Becky Stewartbecky@theleadingzero.combeckystewart on slideshare

2 rules for this session

If you ever feel overwhelmed with information, feel free to say

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

If you ever want to know more or know why, feel free to say

If you ever feel overwhelmed with information, feel free to say

“Just tell me what to type.”

If you ever want to know more or know why, feel free to say

“I want to know more.”

what we will cover

• How is openFrameworks different from Processing?

• The structure of oF.

• Basic C++ concepts to get you going.

• Create a new openFrameworks application.

• Add your own variables and functions.

The magic behind Processing and Arduino

Code You’ve Written

Instructions for Computer?

Executable Program (e.g. .exe or .app)

Compiler +

Linker +

Loader

Code You’ve Written

Instructions for Computer?

Executable Program (e.g. .exe or .app)

Interactive Development

Environment (IDE)

Compiler +

Linker +

Loader

An IDE like Processing or Arduino includes

• text editor

•compiler and linker

•other tools to help you

openFrameworks does not have it’s own IDE.

On Mac you use XCode.

To learn oF you need to know 3 things:

• How to use an IDE

• How to write C++ code

• How to use openFrameworks libraries

To learn oF you need to know 3 things:

• How to use an IDE

• How to write C++ code

• How to use openFrameworks libraries

By far the easiest part.

oF anatomy

addons

openFrameworks

examples

polygonExample.xcodeproj

polygonExample

addonsExamplesmyapps

libsapps

Exercise

Open polygonExample and run it.

Why do we have 3 files?

main.cpp

testApp.cpp

testApp.h

testApp.cpp and testApp.h

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

The units used to describe the amount of the ingredients varies according to

the culture of the person cooking.

1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.

2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.

3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868

2 tbsp olive oil or sun-dried tomato oil from the jar

6 rashers of smoked streaky bacon, chopped

2 large onions, chopped

3 garlic cloves, crushed

1kg/2¼lb lean minced beef

2 large glasses of red wine

2x400g cans chopped tomatoes

1x290g jar antipasti marinated mushrooms, drained

2 fresh or dried bay leaves

1 tsp dried oregano or a small handful of fresh leaves, chopped

1 tsp dried thyme or a small handful of fresh leaves, chopped

Drizzle balsamic vinegar

12-14 sun-dried tomato halves, in oil

Salt and freshly ground black pepper

A good handful of fresh basil leaves, torn into small pieces

800g-1kg/1¾-2¼lb dried spaghetti

Lots of freshly grated parmesan, to serve

We would be very irritated if there was an ingredient needed,

that wasn’t included here.

It’s easier to follow the directions when you don’t have to list the amounts of

ingredients within the directions.

The units used to describe the amount of the ingredients varies according to

the culture of the person cooking.

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

Processing

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

Processing

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

Processing

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

data typeProcessing

float x;float y;float width;float height;

x = 150;y = 100;width = 90;height = 80;

ellipse(x, y, width, height);

ingredients or variables

directions or algorithm

data type variable name

Processing

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

int myInt;

Reserve space for an int

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

We don’t have to know what value will be stored in myInt right away.

We can choose a value later. This is called initialising.

int myInt;

Reserve space for an int

Declaration vs InitialisationAs in a recipe, ingredients need to be listed at the top so you know what to buy.

In code, it’s so the compiler knows how much memory to reserve. This is called declaring.

We don’t have to know what value will be stored in myInt right away.

We can choose a value later. This is called initialising.

int myInt;

Reserve space for an int

myInt = 15;

Store the value 15 in the space reserved for myInt

15

Need to declare before or at the same time as initialisation.

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

Can’t use a variable before it is initialised.

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

int myInt;myInt = myInt + 7;

Can’t use a variable before it is initialised.

Need to declare before or at the same time as initialisation.

myInt = 3;int myInt;

int myInt; myInt = 3;

int myInt = 3;myInt = myInt + 7;

int myInt;myInt = myInt + 7;

Can’t use a variable before it is initialised.

To create a variable

1.Decide what the data type should be.

floatintchar

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

to create an int type

To create a variable

1.Decide what the data type should be.

floatintchar

to create a float type

to create an int type

to create a char type

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

you get to choose the name

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

you get to choose the name

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

float scale = 0.5;int redValue = 199;char finalMark = ‘B’;

you get to choose the name

To create a variable

1.Decide what the data type should be.

2.Decide on a name for your variable. Remember the rules.

3.If you already know what the value of that variable is, then go ahead and set the value.

floatintchar

to create a float type

to create an int type

to create a char type

float scale;int redValue;char finalMark;

float scale = 0.5;int redValue = 199;char finalMark = ‘B’;

if you don’t know the value yet, stop at step 2. but remember to end

each line with a ;

you get to choose the name

In Processing, the declarations are at the top of the file.

In openFrameworks, the declarations are in a separate file (testApp.h, the header file).

This file is included in main.cpp.

main functions

Every program has a main function.

It’s the starting point.

It’s hidden in Processing, but exposed in openFrameworks in main.cpp.

Defines:the window size

ofAppGlutWindow window;ofSetupOpenGL(&window, 1024,768, OF_WINDOW);

and your application classofRunApp( new testApp());

Exercise

Create a copy of emptyExample in your myapps folder.

Rename the folder and .xcodeproj file.

Open the project.

Rename the target.

Make sure it builds and runs.

openFrameworks

• Really similar functionality as Processing.

• Fully documented here:

• http://www.openframeworks.cc/documentation

Exercise

Open your new empty project.

Create a purple circle in the center of the window.

Move the center of the circle to where you click within the window.

• Speed

• Accessibility of low level information

• Debugger

• C++

• Version control

Why do I use oF over Processing?

what is OOP? it sounds sticky

myApp

oscHandler textButton

myApp.cpp myApp.h

main.cpp

oscHandler.cpp

oscHandler.h

textButton.cpp

textButton.h

oscHandler textButton

oscHandler.cpp

oscHandler.h

textButton.cpp

textButton.h

myOtherApp

myOtherApp.cpp myOtherApp.h

main.cpp

top related