Your SlideShare is downloading. ×
A Gentle Introduction to openFrameworks
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

A Gentle Introduction to openFrameworks

4,990

Published on

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

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

Published in: Technology, Self Improvement
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,990
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
106
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. a gentle introduction to openFrameworks Becky Stewart becky@theleadingzero.com beckystewart on slideshare
  • 2. 2 rules for this session
  • 3. If you ever feel overwhelmed with information, feel free to say
  • 4. If you ever feel overwhelmed with information, feel free to say “Just tell me what to type.”
  • 5. 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
  • 6. 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.”
  • 7. what we will cover
  • 8. • 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.
  • 9. The magic behindProcessing and Arduino
  • 10. Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 11. Interactive Development Environment (IDE)Code You’ve Instructions for Written ? Computer Compiler Executable Program + (e.g. .exe or .app) Linker + Loader
  • 12. An IDE like Processing orArduino includes• text editor• compiler and linker• other tools to help you
  • 13. openFrameworks does not have it’s own IDE.On Mac you use XCode.
  • 14. To learn oF you need to know 3 things:• How to use an IDE• How to write C++ code• How to use openFrameworks libraries
  • 15. 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.
  • 16. oF anatomy
  • 17. openFrameworks apps addons libsmyapps addonsExamples examples polygonExample polygonExample.xcodeproj
  • 18. ExerciseOpen polygonExample and run it.
  • 19. Why do we have 3 files?
  • 20. main.cpptestApp.cpp testApp.h
  • 21. testApp.cpp and testApp.h
  • 22. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated mushrooms, 800g-1kg/1¾-2¼lb dried spaghetti drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 23. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated mushrooms, 800g-1kg/1¾-2¼lb dried spaghetti drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 24. 2 tbsp olive oil or sun-dried tomato oil from the jar 1 tsp dried oregano or a small handful of fresh leaves, chopped 6 rashers of smoked streaky bacon, chopped 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped Drizzle balsamic vinegar 3 garlic cloves, crushed 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated mushrooms, 800g-1kg/1¾-2¼lb dried spaghetti drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 25. 2 tbsp olive oil or sun-dried tomato oil from 1 tsp dried oregano or a small handful of the jar 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef Salt and freshly ground black pepper 2 large glasses of red wine A good handful of fresh basil leaves, torn 2x400g cans chopped tomatoes into small pieces 1x290g jar antipasti marinated mushrooms, 800g-1kg/1¾-2¼lb dried spaghetti drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 26. 2 tbsp olive oil or sun-dried tomato oil from 1 tsp dried oregano or a small handful of the jar 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef The units used to describe the amount 2 large glasses of red wine Salt and freshly ground black pepper A good handful of fresh basil leaves, torn of the ingredients varies according to 2x400g cans chopped tomatoes 1x290g jar antipasti marinated mushrooms, into small pieces 800g-1kg/1¾-2¼lb dried spaghetti the culture of the person cooking. drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 27. 2 tbsp olive oil or sun-dried tomato oil from 1 tsp dried oregano or a small handful of the jar 6 rashers of smoked streaky bacon, We would be very irritated if fresh leaves, chopped chopped there was an ingredient needed, 1 tsp dried thyme or a small handful of fresh leaves, chopped 2 large onions, chopped 3 garlic cloves, crushed that wasn’t included here. Drizzle balsamic vinegar 12-14 sun-dried tomato halves, in oil 1kg/2¼lb lean minced beef The units used to describe the amount 2 large glasses of red wine Salt and freshly ground black pepper A good handful of fresh basil leaves, torn of the ingredients varies according to 2x400g cans chopped tomatoes 1x290g jar antipasti marinated mushrooms, into small pieces 800g-1kg/1¾-2¼lb dried spaghetti the culture of the person cooking. drained Lots of freshly grated parmesan, to serve 2 fresh or dried bay leaves1. 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 It’s easier to follow the directions when mushrooms, bay leaves, oregano, thyme and balsamic vinegar. you don’t have to list the amounts of2. 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 ingredients within the directions. sauce over a gentle heat for 1-1½ hours until its 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 black http://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
  • 28. Processing float x; float y; float width; float height; x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 29. Processing float x; float y; ingredients or variables float width; float height; x = 150; y = 100; width = 90; height = 80; ellipse(x, y, width, height);
  • 30. Processing float x; float y; ingredients or variables float width; float height; x = 150; y = 100; width = 90; directions or algorithm height = 80; ellipse(x, y, width, height);
  • 31. Processing data type float x; float y; ingredients or variables float width; float height; x = 150; y = 100; width = 90; directions or algorithm height = 80; ellipse(x, y, width, height);
  • 32. Processing data type variable name float x; float y; ingredients or variables float width; float height; x = 150; y = 100; width = 90; directions or algorithm height = 80; ellipse(x, y, width, height);
  • 33. Declaration vs InitialisationAs in a recipe, ingredients needto be listed at the top so youknow what to buy.In code, it’s so the compilerknows how much memory toreserve. This is called declaring.
  • 34. Declaration vs InitialisationAs in a recipe, ingredients needto be listed at the top so youknow what to buy.In code, it’s so the compilerknows how much memory toreserve. This is called declaring. int myInt; Reserve space for an int
  • 35. Declaration vs InitialisationAs in a recipe, ingredients need We don’t have to know whatto be listed at the top so you value will be stored in myIntknow what to buy. right away.In code, it’s so the compiler We can choose a value later.knows how much memory to This is called initialising.reserve. This is called declaring. int myInt; Reserve space for an int
  • 36. Declaration vs InitialisationAs in a recipe, ingredients need We don’t have to know whatto be listed at the top so you value will be stored in myIntknow what to buy. right away.In code, it’s so the compiler We can choose a value later.knows how much memory to This is called initialising.reserve. This is called declaring. int myInt; myInt = 15; Reserve space for Store the value 15 in the an int space reserved for myInt 15
  • 37. Need to declare before or at the same timeas initialisation.
  • 38. Need to declare before or at the same timeas initialisation.myInt = 3;int myInt;
  • 39. Need to declare before or at the same timeas initialisation.myInt = 3; int myInt;int myInt; myInt = 3;
  • 40. Need to declare before or at the same timeas initialisation.myInt = 3; int myInt;int myInt; myInt = 3; Can’t use a variable before it is initialised.
  • 41. 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.int myInt;myInt = myInt + 7;
  • 42. 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.int myInt; int myInt = 3;myInt = myInt + 7; myInt = myInt + 7;
  • 43. To create a variable1.Decide what the data type should be. float int char
  • 44. To create a variable1.Decide what the data type should be. to create a float type float int char
  • 45. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int char
  • 46. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char
  • 47. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules.
  • 48. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules. float scale; int redValue; char finalMark;
  • 49. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;
  • 50. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;3.If you already know what the value of that variable is, then go ahead and set the value.
  • 51. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;3.If you already know what the value of that variable is, then go ahead and set the value. float scale = 0.5; int redValue = 199; char finalMark = ‘B’;
  • 52. To create a variable1.Decide what the data type should be. to create a float type float to create an int type int to create a char type char2.Decide on a name for your variable. Remember the rules. float scale; you get to choose int redValue; the name char finalMark;3.If you already know what the value of that variable is, then go ahead and set the value. if you don’t know the float scale = 0.5; value yet, stop at step 2. int redValue = 199; but remember to end char finalMark = ‘B’; each line with a ;
  • 53. In Processing, the declarations are at the topof the file.In openFrameworks, the declarations are in aseparate file (testApp.h, the header file).This file is included in main.cpp.
  • 54. main functions
  • 55. Every program has a main function.It’s the starting point.It’s hidden in Processing, but exposed inopenFrameworks in main.cpp.Defines: the window size ofAppGlutWindow window; ofSetupOpenGL(&window, 1024,768, OF_WINDOW); and your application class ofRunApp( new testApp());
  • 56. ExerciseCreate 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.
  • 57. openFrameworks
  • 58. • Really similar functionality as Processing.• Fully documented here:• http://www.openframeworks.cc/documentation
  • 59. ExerciseOpen your new empty project.Create a purple circle in the center of the window.Move the center of the circle to where you clickwithin the window.
  • 60. Why do I use oF over Processing?• Speed• Accessibility of low level information• Debugger• C++• Version control
  • 61. what is OOP?it sounds sticky
  • 62. main.cpp myApp myApp.cpp myApp.hoscHandler.h textButton.h oscHandler textButtonoscHandler.cpp textButton.cpp
  • 63. main.cpp myOtherApp myOtherApp.cpp myOtherApp.hoscHandler.h textButton.h oscHandler textButtonoscHandler.cpp textButton.cpp

×