Graphic Designing - Turtle Graphics - Haskell - LOGO Programming Assessment Answer

Download Solution Order New Solution
Internal Code: 6CIEA

Graphic Designing Assessment Answer

Assignment Task:

Turtle Graphics Haskell

In this assignment, you will explore another way of thinking about graphics, inspired by the robotic “turtles” that some of you might associate with the LOGO programming language. You can think of the turtle as a machine with a pen, that sits on a sheet of paper. As it moves around the page, it drags the pen along the paper to draw pictures. You will be writing Haskell to generate instructions for a virtual turtle, and writing more Haskell to interpret these instructions into a CodeWorld Picture. Task 1: 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 n s 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. Task 2: 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). Task 3A: Sierpinski’s Triangle - Direct Drawing (COMP1100 only) Sierpinski’s Triangle is a famous fractal (self-similar structure). We can generate approximations to Sierpinski’s Triangle using the following rules:
  • 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.
2019/4/15 Assignment 2: Turtle Graphics - Assignments - Programming as Problem Solving (including Advanced) [2019&nbsp;S1] We can draw approximations to Sierpinski’s triangle using our turtle system (click for larger versions): Task 3: 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. Task 3B: L-Systems (COMP1130 only: 40 marks) 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- 2019/4/15 Assignment 2: Turtle Graphics - Assignments - Programming as Problem Solving (including Advanced) [2019&nbsp;S1] Systems, and are comprised of three parts:
  • 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.
Task 4:
  1. Define machinery for describing and interpreting L-Systems in src/Turtle.hs:
A type LSystem a that represents L-Systems over some alphabet type. A value of this type should hold a system’s initial string and production rule. Hint: (->) is a type constructor like Maybe or [], so functions can appear inside a data declaration. A function interpretLSystem :: LSystem a -> Int -> [a]. interpretLSystem sys n should expand the L-System sys to depth n. If n < 0, raise an error.
  1. Use your L-System machinery to generate an approximation to Sierpinski’s Triangle, according to the rules given in the example above. In src/Turtle.hs, define:
A type SierpinskiAlphabet representing the alphabet for the example L-System; A value sierpinskiSystem :: LSystem SierpinskiAlphabet that implements the Sierpinski L-System described above; and A function sierpinski :: Int -> Double -> [TurtleCommand] which generates the commands to draw an approximation to Sierpinski’s Triangle. sierpinski n d should expand sierpinskiSystem to depth n, and convert the resulting string into turtle commands. When interpreting F and G from the L-System, drive the turtle forward d units.
  1. Use your L-System machinery to produce your own picture. Find (or invent) an L-System which can be interpreted to produce a picture that pleases you. Define:
Task 5: Replace the example tests with tests of your own. The tests that you write should show that the Haskell code you’ve written in Tasks 1-3 is working correctly. Task 6: Ensure that your code is written in good Haskell style. Technical Report (COMP1100: 15 marks; COMP1130: 20 marks) You should write a concise technical report. An excellent report will: demonstrate conceptual understanding of all major functions, and how they interact when the program as a whole runs; explain your design process, including your assumptions, and the reasons behind choices you made; discuss how you tested your program, and in particular why your tests give you confidence that your code is correct; and be well formatted without spelling or grammar errors.
This Graphic Designing Assessment has been solved by our Graphic Designing 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.