Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
drawing a chess-board with seesaw ...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jim - FooBar();  
View profile  
 More options Aug 9 2012, 4:37 am
From: "Jim - FooBar();" <jimpil1...@gmail.com>
Date: Thu, 09 Aug 2012 09:37:48 +0100
Local: Thurs, Aug 9 2012 4:37 am
Subject: drawing a chess-board with seesaw ...
Hey all,

Spent most of yesterday trying to draw a chessboard on a paintable
canvas, however I'm stuck after drawing the lines of the grid...I mean
the grid is there but its all one colour (the background colour of the
panel)! The fn that draws the lines is simply this:

(defn draw-grid [c g]
   (let [w (width c)
         h (height c)]
     (doseq [x (range 0 w 50)]
       (.drawLine g x 0 x h))
     (doseq [y (range 0 h 50)]
         (.drawLine g 0 y w y))))

Does anyone have any suggestions as to how to do the black-white
alteration on the grid? I know how to do it imperatively using loop(s)
and a couple of flags but I'm really struggling to tweak the 'draw-grid'
accordingly to paint the colours as well...

Any seesaw gurus? -> please help...

cheers,
Jim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stathis Sideris  
View profile  
 More options Aug 9 2012, 5:08 am
From: Stathis Sideris <side...@gmail.com>
Date: Thu, 9 Aug 2012 02:08:42 -0700 (PDT)
Local: Thurs, Aug 9 2012 5:08 am
Subject: Re: drawing a chess-board with seesaw ...

How about drawing all the rectangles with .fillRect()<http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#fillR...>and before each call alternate between black and white by calling
.setColor()<http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#setCo...>.
You can alternate between the colours by taking the first of the following
seq every time you set the color:

(cycle [java.awt.Color.black java.awt.Color.white])

Stathis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim - FooBar();  
View profile  
 More options Aug 9 2012, 6:17 am
From: "Jim - FooBar();" <jimpil1...@gmail.com>
Date: Thu, 09 Aug 2012 11:17:01 +0100
Local: Thurs, Aug 9 2012 6:17 am
Subject: Re: drawing a chess-board with seesaw ...

On 09/08/12 10:08, Stathis Sideris wrote:

> How about drawing all the rectangles with .fillRect()
> <http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#fillR...>
> and before each call alternate between black and white by calling
> .setColor()
> <http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#setCo...>.
> You can alternate between the colours by taking the first of the
> following seq every time you set the color:

> (cycle [java.awt.Color.black java.awt.Color.white])

> Stathis

Geia sou Stathi,

If I understood correctly, you propose filling rectangles instead of
drawing lines...that is a good idea but how would I alternate the colors
using 'cycle'? 'cycle' returns a infinitely cycled lazy-seq of the
provided collection. Whenever i call 'first' on it I get the same value
back...they are not alternating! Have I misunderstood? thanks for
bothering btw... :-)

Jim (Dimitris)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim - FooBar();  
View profile  
 More options Aug 9 2012, 6:23 am
From: "Jim - FooBar();" <jimpil1...@gmail.com>
Date: Thu, 09 Aug 2012 11:23:41 +0100
Local: Thurs, Aug 9 2012 6:23 am
Subject: Re: drawing a chess-board with seesaw ...

On 09/08/12 11:17, Jim - FooBar(); wrote:

aaa ok sorry...you mean having it as doseq binding...that makes sense! I
apologise for rushing...

Jim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim - FooBar();  
View profile  
 More options Aug 9 2012, 6:53 am
From: "Jim - FooBar();" <jimpil1...@gmail.com>
Date: Thu, 09 Aug 2012 11:53:52 +0100
Local: Thurs, Aug 9 2012 6:53 am
Subject: Re: drawing a chess-board with seesaw ...
On 09/08/12 11:23, Jim - FooBar(); wrote:

> aaa ok sorry...you mean having it as doseq binding...that makes sense!
> I apologise for rushing...

> Jim

No I can't put 'cycle' inside a doseq cos its trying to consume it!

Jim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Powell  
View profile  
 More options Aug 9 2012, 7:00 am
From: David Powell <djpow...@djpowell.net>
Date: Thu, 9 Aug 2012 12:00:23 +0100
Local: Thurs, Aug 9 2012 7:00 am
Subject: Re: drawing a chess-board with seesaw ...
You can try using the multi-input version of map to knit your data
together with some other, potentially infinite, sequence:

  (map vector items (cycle [black white]))

It returns something like this:

  ([item1 black] [item2 white] [item3 black] [item4 white])

Then you can use doseq over that, using destructuring to pick apart
the items and colours and do something appropriate with each of them.

--
Dave

On Thu, Aug 9, 2012 at 11:53 AM, Jim - FooBar(); <jimpil1...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim - FooBar();  
View profile  
 More options Aug 9 2012, 7:29 am
From: "Jim - FooBar();" <jimpil1...@gmail.com>
Date: Thu, 09 Aug 2012 12:29:12 +0100
Local: Thurs, Aug 9 2012 7:29 am
Subject: Re: drawing a chess-board with seesaw ...
On 09/08/12 12:00, David Powell wrote:

> You can try using the multi-input version of map to knit your data
> together with some other, potentially infinite, sequence:

>    (map vector items (cycle [black white]))

> It returns something like this:

>    ([item1 black] [item2 white] [item3 black] [item4 white])

> Then you can use doseq over that, using destructuring to pick apart
> the items and colours and do something appropriate with each of them.

Thanks Dave that is pretty clever and looks very idiomatic! I managed to
get what I by using your suggestion:

(defn draw-grid2 [d g]
   (let [w (width d)
         h (height d)
         tiles (map vector (for [x (range 0 w 50)
                                 y (range 0 h 50)] [x y])
                           (cycle [java.awt.Color/WHITE
                                   java.awt.Color/BLACK]))]
     (doseq [[[x y] c] tiles]
        (.setColor g c)
        (.fillRect g x y 50 50)) ))

Thanks a lot! It looked impossible to achieve without mutation, indices
and counting pixels!!!

Jim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stathis Sideris  
View profile  
 More options Aug 9 2012, 8:40 am
From: Stathis Sideris <side...@gmail.com>
Date: Thu, 9 Aug 2012 05:40:29 -0700 (PDT)
Local: Thurs, Aug 9 2012 8:40 am
Subject: Re: drawing a chess-board with seesaw ...

Yeah, sorry Dimitri, I wasn't very clear :-) I meant that if you were going
to do it recursively you would be using the first element of the seq, and
you would be passing the (rest) of the seq to the subsequent recursive
call. Very elegant solution!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »