4
CS1010S, Semester II, 2013/2014—Mission 2 1 National University of Singapore School of Computing CS1010S: Programming Methodology Semester II, 2013/2014 Mission 2 Rune Paintings Start date: 30 January 2014 Due: 5 February 2014, 23:59 Background After passing through the two doors in your previous mission, you arrive in a large spacious hall with no visible exits except for a large hole in the ceiling from which a bright light illuminate the entire hall. In one corner, you find 2 raised terminal with an interface similar to the empty spaces you found on the doors. You can barely see the first letters on their interfaces - R and I. This mission has two tasks. Task 1a: Fractal (5 marks) On the terminals, you see the symbols glow - reminiscent of the previous rooms. Yet they represented all the complexities that came before them in simple elegant patterns. It will be well for you to comprehend the similarities and differences. Write a function fractal that takes as arguments a rune and an integer n> 0. It should generate the rune below by means of a recursive process with the following command: show(fractal(make_cross(rcross_bb), 3)) To determine that your function is correct for n> 3, check that the same command with n =7 draws:

Mission 02

Embed Size (px)

DESCRIPTION

dfdf

Citation preview

Page 1: Mission 02

CS1010S, Semester II, 2013/2014—Mission 2 1

National University of SingaporeSchool of Computing

CS1010S: Programming MethodologySemester II, 2013/2014

Mission 2Rune Paintings

Start date: 30 January 2014Due: 5 February 2014, 23:59

Background

After passing through the two doors in your previous mission, you arrive in a largespacious hall with no visible exits except for a large hole in the ceiling from which abright light illuminate the entire hall. In one corner, you find 2 raised terminal with aninterface similar to the empty spaces you found on the doors. You can barely see thefirst letters on their interfaces - R and I.

This mission has two tasks.

Task 1a: Fractal (5 marks)

On the terminals, you see the symbols glow - reminiscent of the previous rooms. Yetthey represented all the complexities that came before them in simple elegant patterns.It will be well for you to comprehend the similarities and differences.

Write a function fractal that takes as arguments a rune and an integer n > 0. It shouldgenerate the rune below by means of a recursive process with the following command:

show(fractal(make_cross(rcross_bb), 3))

To determine that your function is correct for n > 3, check that the same command withn = 7 draws:

Page 2: Mission 02

CS1010S, Semester II, 2013/2014—Mission 2 2

You should check that your function will perform correctly for any arbitary number ofdraws that is 3 or above.

Task 1b: Fractal - Iteration (5 marks)

Write a function fractal iter that takes in the same arguments as fractal but it willgenerate the output in an iterative way this time.

The function should generate the same rune as the recursive one by replacing fractalwith fractal iter in your test functions.

Page 3: Mission 02

CS1010S, Semester II, 2013/2014—Mission 2 3

Figure 1: (Left) dual fractal with 3 layers (Right) dual fractal with 7 layers

Task 1c: Dual Fractals (5 marks)

Write a function dual fractal that takes as arguments 2 runes and an integer n > 0.It should generate the rune below by means of a recursive process with the followingcommand:

show(dual_fractal(make_cross(rcross_bb), make_cross(nova_bb), 3))

The first rune is used for every odd layers in the fractal starting from the largest rune,whereas the second rune is used for every even layers in the fractal.

You should check that your function will perform correctly for any arbitary number ofdraws that is 3 or above.

Task 1d: Dual Fractals - Iteration (5 marks)

Write a function dual fractal iter that takes in the same arguments as dual fractalbut it will generate the output in an iterative way.

The function should generate the same rune as the recursive one by replacing dual fractalwith dual fractal iter in your test functions.

Note: In the template file all functions are defined as some function(params). Itdoesn’t mean that all functions take in only one parameter. It’s your job to figure outwhat parameters should each function take and replace params accordingly.

Page 4: Mission 02

CS1010S, Semester II, 2013/2014—Mission 2 4

Task 2: Egyptian (10 marks)

As your eyes slowly adjusted to the room, several paintings that were hidden by thedarkness reveal themselves. They exuded the same runes in the terminal but with anintricate repeating pattern. Almost like the Egyptian paintings you read in a book before.Perhaps this is where they make them.

Observing a nearest painting, you notice that it exhibits 5 repeating patterns on everyedge with the centre hollow filled with the same pattern:

However, there are other paintings that sports different numbers of repeating patterns.Write a function egyptian that takes n as an argument and creates runic patternsshown on these Egyptian paintings with different numbers of repetitions at the edges,where n ≥ 3.

In particular, the above picture can be created with:show(egyptian(make_cross(rcross_bb), 5))

Furthermore, note that the orientation of all images should remain the same as theoriginal. See Figure 2 for more examples.

(a) show(egyptian(make cross(rcross bb),9)) (b) show(egyptian(nova bb, 9))

Figure 2: More examples. (a) is the same as previous example but with n = 9, (b) demonstratesthat the original pattern (e.g. nova bb) should not be rotated.