CSE 30 -- Prog 1
Due: 11:59pm Sunday, April 26, 2020 (pacific time).
Late submissions will not be accepted/graded.
Learning Objectives:
Use existing class (turtle and numpy) and practice on recursion.
Description:
Write a python code that will generate a fractal terrain,
render it as a wireframe, and create an animation.
Place your code in a file named "terrain.py", and submit on Canvas.
The primary input for the terrain will be a triangle which
defines the perimeter of the terrain.
This triangle can be hardcoded.
You will also need to specify the recursive depth, and
another parameter which describes the roughness of the terrain.
These 2 parameters may be hardcoded as well.
The method to use for generating the fractal terrain should be
the midpoint displacement method.
Your output should look similar to:
this
wiki animation.
Note that while this animation shows how a terrain varies at different
recursive depth. Its viewpoint is fixed.
In your animatiion, the recursive depth is fixed, while the viewpoint is
animated. That is, you will be looking at your terrain from different
viewpoints.
Suggested Steps:
-
The following code provides a 1D version of the same problem where a line
is iteratively subdivided using midpoint displacement to produce a
silhouette of some landscape:
https://bitesofcode.wordpress.com/2016/12/23/landscape-generation-using-midpoint-displacement/
To get used to turtle graphics, try modifying the code so that it uses turtle
graphics instead of PIL. Also you don't need to "shade" the area under
the silhoutte, although if you want to, it's easier using polygon fill
rather than drawing vertical lines. Here are a couple of sample outputs:
-
Modify the midpoint_displacement function so that it's recursive instead
of iterative.
-
Using the idea of 1D midpoint subdivision, extend it to 2D.
The starting shape is now a triangle instead of a line segment.
At each recursion level the 3 edges of a triangle are divided/displaced
at the midpoint and connected together so that a single triangle is now 4 triangles.
That is, this grows at the rate of 4^level instead of 2^level,
where level is the recursive depth.
-
Turtle is inherently 2D, but the displacements you're applying to the triangle edges
are in the 3rd dimension (z-axis). The default view when you draw (render) your
divided triangles is the top-down view, which is somewhat boring.
We are providing you with a function named "transform()" to view the world from a different
direction. The function is included in an example code for demonstrating
the usage of the function using a pre-generated recursive level 1 terrain similar to the one in the example above. Try to understand
the example carefully to use the function with your code. More details are given as comments in the code.
Create an animation of your terrain when viewed from different angles
e.g. flying around the terrain in a circular path using this function.
Resources:
There's a set of links on turtle to get you started with
graphics.
Wiki description of
numpy.
Link to source.
And the numpy homepage
which also has a tutorial.
Another tutorial
setup on colab/jupyter.
Rubric:
10 2D triangles, top down view
10 3D triangles, top down view
40 recursive subdivision vs interative subdivision
20 3D alternate view
20 3D animated view
10 extra: user interface e.g. using mouse for interactive viewpoints
-5 holes or tears in terrain
Alternative Suggested Steps - based on rubrics:
-
Assume problem is 2D. Start with a triangle,
and simply subdivide each triangle into 4 triangles by connecting
midpoints along each edge.
You can do this using itertion first if you're more comfortable with that.
Render subdivided triangles using turtle.
You'll need to maintain a list of your triangles.
-
Take each of your midpoints from previous step and displace it by
some amount along the z-axis (in/out of the screen space of 2D turtle).
So now your points are triples instead of tuples.
Render the 3D points as 2D points by simply ignoring the z-component.
-
Take your 3D points and transform them using the function that we provide you.
These will turn your 3D points into a bunch of 2D points.
Now use the same renderer from step 1.
-
Create your animated views. At a minimum,
this is just some loops to change the parameter values of
the provided function.
An easy step, if you've got the previous step done.
-
This is basically redoing your iterative version of step 1
to use recursion.
If you already did step 1 with recursion, you're done with this step.
Congrats!
Who graded your assignment based on your LAST name:
Andre Navid Assadi : A - Ch
Kyle Nagao Oda : Co - I
Mark Allamanno : J - M
Michelle Kwong : N - Sh
Singaravelavan Rajesh : Si - Z
Submission:
Submission must be done using Canvas under Prog1 as a Python file named "terrain.py".
Last modified
Monday, 27-Apr-2020 00:57:04 PDT.