COMP1100 : Drawing Shapes - Interpreting Turtle Commands - Sierpinski’s Triangle - Direct Drawing - Computer Science Assessment Answer

Download Solution Order New Solution
Subject Code: COMP1100

Computer Science Assessment Answer

Assignment Task: Task 1: Drawing Shapes (10 marks) To draw a (CodeWorld) Picture with turtle graphics, we need two things: the commands to draw, and a way of interpreting those commands. In this task, you will define some functions that generate lists of turtle commands. When you have built the interpreter in Task 2, these functions will be a source of test data that you can use to check your interpreter. Your Task Define the following two functions in src/Turtle.hs:triangle:: Double -> [TurtleCommand] Returns a list of commands that will draw an equilateral triangle with side length equal to the argument. The turtle should finish with the same position and facing as when it started. • polygon:: Int -> Double -> [TurtleCommand] polygon ns should return a list of commands that will draw a regular n-sided polygon, with side length equal to s. The turtle should finish with the same position and facing as when it started. If n < 3, raise an error. Hints • You won’t yet have an interpreter to test your generated [TurtleCommand] results. You can read ahead to the section on Unit Tests and write tests for these functions, or try working through a list of commands with a ruler and graph paper. • Try drawing a regular triangle, square or regular hexagon on a sheet of graph paper. Then place your pen on one corner and pretend that it is the turtle. What commands do you have to tell your turtle to make it trace the figure you drew on the graph paper? • The two points above are very similar, but work in opposite directions: the first one is asking you to check the result of your code by interpreting the results literally. The second point is looking at a correct result and asking yourself “what needed to happen to produce this?”. Being able to think in both directions is very useful. Task 2: Interpreting Turtle Commands Lists of TurtleCommand values are just data but are useful because we can interpret them into a (CodeWorld) Picture. This is morally the same as the programming you are doing right now - a .hs file is just textual data, but becomes more useful because we can interpret it as a Haskell program. The difference is only in degree, not kind. Your Task Define a function runTurtle:: [TurtleCommand] -> Picture in src/Turtle.hs, which interprets the [TurtleCommand] according to the rules laid out in the “Turtles and the TurtleCommand” section above. Assume that the turtle starts at (0, 0), facing north (straight up), with the pen down (on the paper). If you have completed this task correctly, the test pattern you get by pressing C in the test program will look like this (click for larger version): Computer Science Task 3A: Sierpinski’s Triangle - Direct Drawing (COMP1100 only: 25 marks) Sierpinski’s Triangle is a famous fractal (self-similar structure). We can generate approximations to Sierpinski’s Triangle using the following rules: 1. An approximation at depth 1 is a single equilateral triangle. 2. An approximation at depth n is made up of three approximations at depth n - 1, with their side length reduced by half. These approximations are arranged to cover the original triangle. We can draw approximations to Sierpinski’s triangle using our turtle system (click for larger versions): computer Science Assessment Your Task Define a function Sierpinski:: Int -> Double -> [TurtleCommand] in src/Turtle.hs, which generates the necessary commands to draw an approximation to Sierpinski’s Triangle. The first argument specifies the depth, and the second specifies the side length. The turtle should finish with the same position and facing as when it started. Hints • Be very clear in your mind about what happens at each level. Trace out a path for the turtle on graph paper, using the diagrammed behaviour as a guide. Actual drawing only happens at depth 1, and the other levels of the recursion position the turtle without drawing. • It’s very important that the turtle finishes with the same position and facing as when it started because that’s how you know where it will be when you come out of a recursive call. • If you get stuck, try writing out the steps for drawing a depth-2 approximation without recursion (but following the diagram closely), then look for subsequences that look like the instructions to draw a depth-1 approximation. Task 3B: L-Systems During his study of filamentous fungi and other simple biological structures, Hungarian biologist Astrid Lindenmayer invented a type of formal language that can model their development. These languages have come to be called L-Systems, and are comprised of three parts: 1. An alphabet of symbols. 2. An initial string, consisting of symbols from that alphabet. 3. A production rule which we apply to every symbol, to derive the next generation. If our rule does not mention a symbol, we send that symbol to itself.
This Computer Science Assessment has been solved by our Computer Science experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.