You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapters/OOPs!/chapter.md
+10-8
Original file line number
Diff line number
Diff line change
@@ -26,12 +26,14 @@ Every class has two files: a header file, also known as declarations file with t
26
26
A very easy way of knowing what these two files do is to think of the header file (.h) as a recipe, a list of the main ingredients of your cookie. The implementation file (.cpp) is what we're going to do with them, how you mix and work them to be the perfect cookie!
27
27
So let's see how it works:
28
28
29
-
First of all, let's create the two class files:
30
-
If you're using Xcode as your IDE (it stands for Integrated Development Environment), select the src folder and left Click (or CTRL + click), on the pop-up menu select 'New File' and you'll be taken to a new window menu, choose the appropriate platform you're developing for (OS X or iOS) and select C++ class and finally choose a name (we used 'Ball'). You'll automatically see the two files in your 'src' folder: 'Ball.h' and 'Ball.cpp'.
31
-
If you are using Code::Blocks create a new project from empty one given inside the "examples" directory (or check out the ProjectGenerator). Copy the folder "empty" and rename it to "OOP". Change into this new directory, copy the "emptyExample" and rename it to "ball1". Inside the "ball1" directory rename "emptyExample.workspace" to "ball1.workspace" and "emptyExample.cbp" to "ball1.cbp". Now you have a dedicated directory and a dedicated project to play around with. Open "ball1.cbp" with Code:: Blocks, right-click on the "emptyExample" workspace, select "Properties" (last entry in the list) and change the title of the project. The "src" directory in your project contains all the files you need to edit in this chapter. Add two new files inside the 'src' directory by either using 'File'->'New'->'Empty File' or pressing Tab+Ctrl+N. One file should be named 'Ball.h' and the other 'Ball.cpp'.
32
-
Now let's edit your class header (.h) file. Feel free to delete all its contents and let's start from scratch:
33
-
Declare a class in the header file (.h). In this case, the file name should be Ball.h.
34
-
Follow the code below and type into your own Ball.h file, please note the comments I've included to guide you along.
29
+
First of all, let's create the two class files: `Ball.h` and `Ball.cpp` and place these in the project's `src` folder.
30
+
31
+
If you're using Xcode as your IDE (it stands for Integrated Development Environment), select the src folder and left Click (or CTRL + click), on the pop-up menu select 'New File' and you'll be taken to a new window menu, choose the appropriate platform you're developing for (OS X or iOS) and select C++ class and finally choose a name (we used 'Ball'). You'll automatically see the two files in your `src` folder: `Ball.h` and `Ball.cpp`.
32
+
33
+
If you are using other IDEs it should be quite similar.
34
+
35
+
Declare a class in the header file (.h). In this case, the file name should be `Ball.h`.
36
+
Follow the code below and type into your own `Ball.h` file, please note the comments I've included to guide you along.
35
37
36
38
```cpp
37
39
#ifndef _BALL // if this class hasn't been defined, the program can define it
@@ -66,7 +68,7 @@ The 'if statement' (#ifndef) is a way to prevent the repetition of header files
66
68
67
69
We will now create a class for a ball object. This ball will have color, speed and direction properties: it will move across the screen and bounce against the wall. Some of these properties we will create with randomized attributes but we'll be careful to create the right logic for its motion behaviors.
68
70
69
-
Here's how you can write the class Ball.cpp file, the implementation file:
71
+
Here's how you can write the class `Ball.cpp` file, the implementation file:
Copy file name to clipboardExpand all lines: chapters/intro_to_graphics/chapter.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Graphics
5
5
6
6
This chapter builds off of the *C++ Basics* and *Setup and Project Structure* chapters, so if you aren't familiar with basic C++ and creating openFrameworks projects, check out those chapters first.
7
7
8
-
In sections 1 and 2, we will create "paintbrushes" where the mouse is our brush and our code defines how our brush makes marks on the screen. In section 3, we will explore something called "coordinate system transformations" to create hypnotizing, spiraling rectangles. Source code for the projects is linked at the end of each section. If you feel lost at any point, don't hesitate to look at the completed code! You can check out the whole collection of code [here](https://github.com/openframeworks/ofBook/tree/master/chapters/intro_to_graphics/code) - both for standard development structure (Xcode, Code::Blocks, etc.) and for ofSketch.
8
+
In sections 1 and 2, we will create "paintbrushes" where the mouse is our brush and our code defines how our brush makes marks on the screen. In section 3, we will explore something called "coordinate system transformations" to create hypnotizing, spiraling rectangles. Source code for the projects is linked at the end of each section. If you feel lost at any point, don't hesitate to look at the completed code! You can check out the whole collection of code [here](https://github.com/openframeworks/ofBook/tree/master/chapters/intro_to_graphics/code) - both for standard development structure (Xcode, QtCreator, Visual Studio, etc.) and for ofSketch.
9
9
10
10
If you are following along using ofSketch, great! There are a couple things to note. Coding in ofSketch is a bit different than coding in other Xcode, Code::Blocks, etc. 1) There will be a few points where variables are added to something called a header file (`.h`). When you see those instructions, that means you should put your variables above your `setup()` function in ofSketch. 2) You'll want to use `ofSetWindowShape(int width, int height)` in `setup()` to control the size of your application. 3) Some of the applications you write will save images to your computer. You can find them in your ofSketch folder, by looking for `ofSketch/data/Projects/YOUR_PROJECT_NAME/bin/data/`.
0 commit comments