Skip to content

Commit 16fdcb0

Browse files
committed
Graphics chapter - adding description about using mouseMoved in ofSketch
1 parent 2ba6001 commit 16fdcb0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

chapters/intro_to_graphics/chapter.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,9 @@ Pretty hypnotizing? If we turn up the `clearAlpha`, we will turn down the smear.
874874
875875
Now we've got two parameters that drastically change the visual experience of our spirals, specifically: `timeScale` of noise and `clearAlpha` of the trail effect. Instead of manually tweaking their values in the code, we can use the mouse position to independently control the values during run time. Horizontal position can adjust the `clearAlpha` while vertical position can adjust the `timeScale`. This type of exploration of parameter settings is super important (especially when making generative graphics), and using the mouse is handy if we've got one or two parameters to explore.
876876
877-
[`mouseMoved(int x, int y )`](http://openframeworks.cc/documentation/application/ofBaseApp.html#!show_mouseMoved "mouseMoved Documentation Page") runs anytime the mouse moves (in our app). We can use it to change our parameters, but we need them to be global first. Delete the code that defines `timeScale` and `clearAlpha` locally in `draw()` and add them to the header. Initialize the values in `setup()` to `100` and `0.5` respectively. Then add these to `mouseMoved(...)`:
877+
[`mouseMoved(int x, int y )`](http://openframeworks.cc/documentation/application/ofBaseApp.html#!show_mouseMoved "mouseMoved Documentation Page") runs anytime the mouse moves (in our app). We can use this function to change our parameters. Like with `mousePressed(...)`, if you are using project generator, you'll find this with your mouse functions in your `.cpp` file. If you are using ofSketch, you might not see this function, but it's easy to add. See the [ofSketch file](https://github.com/openframeworks/ofBook/blob/master/chapters/intro_to_graphics/code/3_ii_Rotating_and_Scaling.sketch) for this section.
878+
879+
Before we use this function, we need to make our parameters global in their scope. Delete the code that defines `timeScale` and `clearAlpha` locally in `draw()` and add them to the header. Initialize the values in `setup()` to `100` and `0.5` respectively. Then add these to `mouseMoved(...)`:
878880
879881
```cpp
880882
clearAlpha = ofMap(x, 0, ofGetWidth(), 0, 255); // clearAlpha goes from 0 to 255 as the mouse moves from left to right

0 commit comments

Comments
 (0)