The main goals of this lab are to:
Do these exercises TrigProblems.pdf.
Below are several basic examples which illustrate how trig functions can be used to generate wave-like images and oscillating motion. Try running them and changing the values of various parameters.
YOUR GOAL IS TO DEVELOP AN INTUITIVE UNDERSTANDING OF WHAT TRIG FUNCTIONS ARE AND HOW THEY CAN BE USED
IN ALGORITHMIC ART!
When done, you will be asked to turn in several of the images/sketches and to create one of your own.
Program 1: Trig Function Example #1 - Plot angle along x-axis. Try changing the values of amplitude, frequency, and phase - what happens? | |
|
![]() |
Can you modify the above code to obtain the following images? Before you begin, try to express in words how these images differ from the image above, e.g. the amplitude is smaller/greater/varying or the frequency is smaller/greater/varying, or is a loop is used to generate a sequence of whatever. Once you can explain what is different, try making that change in the code to see if you are right.
![]() | ![]() |
![]() | ![]() |
![]() | ![]() |
![]() |
![]() |
Program 2: Trig Function Example #2 - Plot in polar coordinates.
Do you see why does this code creates a circle and the code above creates a wave? What happens if you change the radius? What happens if you replace angle < 360 with angle < 180? How do you get an arc in the top rather than the bottom? What happens if you replace point(x,y) with line(0,0,x,y)? | |
| ![]() |
Can you modify the above code to obtain the following images? Before you begin, try to express in words how these differ from the image above, e.g. the radius is smaller/greater/varying or the angle is smaller/greater/varying, or is a loop is used to generate a sequence of whatever. Once you can explain what is different, try making that change in the code to see if you are right.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Program 3: Trig Function Example #3 - Using trig functions to set the color
Based on your knowledge of sin and cos, what are the largest and smallest possible values of val = 1 + cos(x)*sin(y)? Here, val is being used to set the stroke color. Why do you need to add the 1? What would be the stroke component otherwise? To have a better idea of what this code does, try running the simpler case where val is 1 + cos(radians(y)) instead of 1 + cos(radians(x))*sin(radians(y))? What about if you set val to 1 + sin(radians(y))? Once you understand the simpler cases, can you explain what the code below does? | |
| ![]() |
Can you modify the above code to obtain the following images?
![]() |
![]() |
![]() |
The program below is similar to Program 3 except that it allows of you to change the frequency interactively (press the 'a' or 's' key).
Program 4: Trig Function Example #4 - Setting the color using the amplitude interactively
Why does the image change as it does when you increase or decrease the frequency? Try changing val as in Prgram 3 to see what happens. | |
| ![]() |
Trig functions can also be used to warp images.
Program 5: Trig Function Example #5 - Image Warp
Look up PImage in the Processing reference to see what the function get() does. The code below doesn't change the image. However see what happens when you uncomment lines 1-3 and delete line 4. You will need to use your own image. Use one that will show the warp clearly. How do you chance the parameters so that you increase the warping? | |
| ![]() |
![]() |
![]() |
![]() |
![]() |
How do you modify the above code to obtain warping along a different axis?
![]() |
![]() |
hop pattern:![]() warped hop pattern: ![]() |
Program 6: Trig Function Example #6 - Oscillating Motion
Run the code and try to figure out why this does what it does. | |
| ![]() |
At the beginning of class on Wed, March 5, be prepared to :