Saint Louis University |
Computer Science 144
|
Dept. of Math & Computer Science |
Topic: Strings
Related Reading:
Portions of Ch. 5 and Ch. 8
Due:
11:00am, Thursday, April 30, 2015
Note that homework assignments should be submitted in class as hard copy (although you are welcome to test your solutions with Processing, given that both problems are very tangible programming challenges).
For this assignment, you must work individually.
Please make sure you adhere to the policies on academic integrity in this regard.
Preface: With understanding of the relevant documentation, you should be able to predict the results for these questions, but you may also choose to try some of these out in Processing to determine the outcome.
The book's stock market visualizer made use of Processing's
map()
function, which is used to extrapolate a value that was
originally expressed within one range, to its corresponding
value in another range. (See for example its use on page 169.)
Its formal signature, as discussed in
Processing's
online reference, is
float map(float value, float start1, float stop1, float start2, float stop2)
As an example, the call
Your task, once you understand the desired behavior, is to provide a self-contained implementation of such a map function. The body of your function implementation should not include any calls to other functions, but instead should revert to the underlying arithmetic to determine the answer.
Hint: Consider the absolute gap between start1 and stop1, the gap between start2 and stop2, and the gap between value and start1.
When demonstrating recursion in lecture, we left a parting
challenge to implement what is known as Sierpinski's Triangle.
For this homework question, we wish to have you complete that
challenge. You do not need to provide the complete Processing
program in your solution; we are only interested in your
implementation of a recursive function
drawTriangle() having the following signature:
void drawTriangle(float x0, float y0, float x1, float y1, float x2, float y2)
For simplicity, you may assume that those points are oriented so
that (x0,y0) is the top vertex of the triangle, that (x1,y1) is
the bottomleft vertex, and (x2,y2) is the bottomright vertex.