Haskell converting list of points into string

Viewed 1080

I am working on the assignment and I need some help. This is the last part but I am really struggling with it, don't know how to approach. Here's the problem:

Add a function render which takes an image and returns a string that, if printed, would give the diagrammatic representation of the image as illustrated below (making sure to include the one point border around all sides of the image). As an example, render t should return

".|...\n.xxx.\n-+x--\n.|...\n"

(where the points in the image are denoted 'x', the origin is denoted '+', and the horizontal and vertical axes are denoted '-' and '|' respectively):

.|...
.xxx.
-+x--
.|...

(String we produce by render t function can be printed by doing putStr (render t) to achieve above result).

image and t is just this:

type Point = (Int,Int)
type Image = [Point]
t :: Image
t=[(0,1),(1,0),(1,1),(2,1)]

To start off, I will need another function since it can't all be done in render. I know to look at max/min values of y and x to get boundaries, and I have a function for that. I also have a function which will insert newline into the string after every n characters.

2 Answers
Related