Graphing Functions
If you wanted to graph a function on graph paper by hand, you would typically build a table of x
and y
values, plot each of those points on your graph paper, and then use your artistic skills to create smooth lines joining the points. The closer together each of your points was, the easier it would be connect the dots. Graphing an equation in Processing works much the same way, except when Processing tries to connect the dots, it will only use perfectly straight lines. To get something that looks like a smooth curve, you will need to approximate it with many very short line segments.
Using a window size of 400x400, graph the following functions.
- \[y = \frac{1}{2} x + 40\]
- \[y = x^2\]
- \[y = 100 \sin(\frac{x}{10})\]
- Choose your own function and graph it.