Jump to content

assignment need help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Stevie

Stevie

    Newbie

  • Members
  • Pip
  • 4 posts
How to write a function double :: Transform which doubles the size of the image in both horizontal and vertical way. How abou half size? Thank you.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
This was NOT a tutorial. Now then, what language do you need this in, and what reading have you done on the subject?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Stevie

Stevie

    Newbie

  • Members
  • Pip
  • 4 posts
I am doing Haskell Programming now. I know that picture is made up of pixels RGB and in order to double the size, i have to replace each pixels with four pixels. But i am not sure how to pit this into code.

#4
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Sorry Stevie, I've been working all this week and I just haven't had much time to make a good response to your question, which I wanted you to actually generalize the function so that you didn't just double the size of the image, you were able to scale it or shrink it to any size (which would be preferable, and also a bit more complex). But anyway, it's actually pretty easy to double the size of a list, which is basically all you're trying to do anyway. Do this:
doubleSize []    = []
doubleSize (x:xs) = x : x : doubleSize xs
There you go, that should double the number of elements in the list in their according positions no matter what the list is (it need not be pixels). You can also do my suggestion of keeping to functions like foldl:
doubleSize = foldl1 (/x -> (++) [x, x])
That's probably a little less efficient to be honest, but DTSTTCPW, right? Also you might want to make that strictly evaluated.

Oh, and moved to General Programming.
Wow I changed my sig!

#5
Stevie

Stevie

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks ZekeDragon... i will try to figure out how does this work.....