I usually do something like this little sample. Calculations go in the
let bindings and new elements are conjoined into the vector.
(defn foo [n]
  (loop [v [] i 0]
    (if (= i n)
      v
      (let [x (* i i)]
        (recur (conj v x) (inc i))))))
user=> (foo 6)
[0 1 4 9 16 25]

On Jan 21, 8:07 am, WoodHacker <ramsa...@comcast.net> wrote:
> I'm converting the java code examples in Killer Game Programming in
> Java by Andrew Davison to Clojure and am having great fun doing it.
> But I've hit wall where I can't seem to get the code to work.
>
> The following code moves an animated gif strip to a java array:
>
>   public BufferedImage[] loadStripImageArray(String fnm, int number)
>   {
>     if (number <= 0) {
>       System.out.println("number <= 0; returning null");
>       return null;
>     }
>
>     BufferedImage stripIm;
>     if ((stripIm = loadImage(fnm)) == null) {
>       System.out.println("Returning null");
>       return null;
>     }
>
>     int imWidth = (int) stripIm.getWidth() / number;
>     int height = stripIm.getHeight();
>     int transparency = stripIm.getColorModel().getTransparency();
>
>     BufferedImage[] strip = new BufferedImage[number];
>     Graphics2D stripGC;
>
>     // each BufferedImage from the strip file is stored in strip[]
>     for (int i=0; i < number; i++) {
>       strip[i] =  gc.createCompatibleImage(imWidth, height,
> transparency);   <=====
>
>       // create a graphics context
>       stripGC = strip[i].createGraphics();
> <=====
>       // stripGC.setComposite(AlphaComposite.Src);
>
>       // copy image
>       stripGC.drawImage(stripIm,
>                   0,0, imWidth,height,
>                   i*imWidth,0, (i*imWidth)+imWidth,height,
>                   null);
>       stripGC.dispose();
>     }
>     return strip;
>   } // end of loadStripImageArray()
>
> The problem I'm having is with the for loop.   If I create an abject
> array of say 6 buffered images,  how do I reference the indexed image
> array to match the lines pointed to?  In other words what is the
> equivalent of strip[i] in Clojure?
>
> I'm not exactly a beginner, but this has stumped me.
>
> Bill

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to