<br><br>
<div class="gmail_quote">On Mon, Aug 3, 2009 at 6:38 AM, CK Kashyap <span dir="ltr">&lt;<a href="mailto:ck_kashyap@yahoo.com">ck_kashyap@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div style="FONT-FAMILY: times new roman,new york,times,serif; FONT-SIZE: 12pt">
<div style="FONT-FAMILY: times new roman,new york,times,serif; FONT-SIZE: 12pt">Thanks Sebastian,<br>ppm module is indeed very useful. So, I guess my question then just boils down to, how can I write a function to mimic the setPixel function -&gt;<br>
<br>Basically, a blank white image would look like this  (as per ppm module)<br>[ <br>   [ (255, 255, 255)  , (255, 255, 255) , (255, 255, 255) ] ,  -- 3 columns of row 1<br>   [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255)  ]    --- 3 columns of row 2<br>
]<br><br>setPixel x y r g b when called like this - setPixel 0,0,255,0,0<br><br>[ <br>   [ (255, 0, 0)  , (255, 255, 255) , (255, 255, 255) ] ,  -- 3 columns of row 1<br>   [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255)  ]    --- 3 columns of row 2<br>
]<br><br>What would be a good way to implement such a function?<br></div></div></div></blockquote>
<div> </div>
<div>Well you could start by writing a function like:</div>
<div> </div>
<div>adjustElem :: Int -&gt; ( a -&gt; a ) -&gt; [a] -&gt; [a]</div>
<div> </div>
<div>That would basically apply a function to a specific element in a list (indexed by the first parameter). Look at splitAt in Data.List, it may be useful. </div>
<div>Then you can use this in a nested way, by calling adjustElem to modify the row you&#39;re interested in, and the function you pass in to adjust that row would in turn call adjustElem on the specific pixel in that row).</div>

<div> </div>
<div>However, this may be very slow. If you don&#39;t care about speed it&#39;ll work fine, but if you really do want to build up an image by successive single-pixel modifications, you should consider first using an Array and accumArray, this will be much faster as internally accumArray can use a mutable array (while the external interface is still pure).</div>

<div> </div>
<div> </div>
<div>Sebastian</div></div>