I'm stuck attempting to complete an assignment. It's the last question of the assignment, and I've been going at it for a while now with little progress. I need to turn an Image into an ASCII graph, where
type Point = (Int, Int)
type Image = [Point]
I have to write a function which takes an Image and returns a String. The output should be something like ".|...\n.xxx.\n-+x--\n.|...\n", which when outputted using putStr looks like
.|...
.xxx.
-+x--
.|...
With the origin denoted by +, the axes | and --, and the points 'x'.
The graph should always have a 1 point border around the coordinates, so when I'm printing the graph I need to be aware of the bounds of the coordinates. I have a function to get these.
I've also written a function, split, which takes a String and an integer, and inserts \n at every nth interval. The way I was thinking of solving the question was creating a blank graph with the correct positions for the axes, and then passing the blank graph to a new function to insert the points.
Can anyone assist me with this? Apologies if it's vague, I can provide any more details you may require.
Here are some things to think about:
type to call this an FImage. Think of such functions as your primary objects (remember, functions are first class citizens).FImage. Note that you do not need any bounds for that. Isn’t that great?FImage and a Point, and produces an FImage that has the x in the right position.FImage and bounds, produce the final String. You may want to use List comprehensions here.foldl or a foldr, both will work (if the types match).Happy learning!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With