Re: [racket-users] Re: How to draw a 3D ball?

2015-07-20 Thread Mianlai Zhou
Hi,

Thanks for your answer. I meant the former, i.e., a 2D pict of a ball with
some shading to make it look 3D.
Is there any quick way to do it or I have to implement the algorithm by
myself?

Thanks again.


On Mon, Jul 20, 2015 at 8:38 AM, Jack Firth  wrote:

> On Saturday, July 18, 2015 at 7:30:42 PM UTC-7, Mianlai Zhou wrote:
> > Hi all,
> >
> >
> > I am wondering how to change the following code of a 2D circle into a 3D
> ball:
> >
> >
> > (require slideshow)
> > (colorize (filled-ellipse (* size 15) (* size 15)) "red")
> >
> >
> >
> > My intention is to make the picture look like a real ball in
> 3-dimension. Is there such
> > a function existing already in Racket?
> >
> >
> > Thank you in advance.
>
> By "3D ball" do you want a 2D pict of a ball with some shading to make it
> look 3D, or a 3D model of a ball? If it's the latter you can use the pict3d
> package (raco pkg install pict3d):
>
>
> (require pict3d)
> (sphere origin 1)
>
> If you do this in DrRacket, the repl will show a window with a 3D ball
> model in it. You can click it and use the arrow keys to change the angle
> and position you view the ball from.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] How to draw a 3D ball?

2015-07-18 Thread Mianlai Zhou
Hi all,

I am wondering how to change the following code of a 2D circle into a 3D
ball:

(require slideshow)
(colorize (filled-ellipse (* size 15) (* size 15)) "red")

My intention is to make the picture look like a real ball in 3-dimension.
Is there such
a function existing already in Racket?

Thank you in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Problem when using horizontal pane

2015-07-17 Thread Mianlai Zhou
Yes, this is exactly what I want. Thank you a lot.

-- Mianlai

On Fri, Jul 17, 2015 at 4:36 PM, Matthew Flatt  wrote:

> At Fri, 17 Jul 2015 15:16:34 +0800, Mianlai Zhou wrote:
> > I have the following code:
> >
> > #lang racket
> >
> > (require slideshow racket/class racket/gui/base)
> >
> > (define my-frame (new frame% [label "My chess"]
> >   [width 300] [height 391]
> >   [alignment '(center center)] ))
> >
> > (define my-canvas
> >   (new (class canvas%
> >  (super-new [parent my-frame])
> >  [define/override (on-paint)
> >(define my-dc (send my-canvas get-dc))
> >(send my-dc clear)
> >((make-pict-drawer (colorize (circle 225) "red")) my-dc 20
> > 20)
> > ]
> >  [define/override (on-char ch)
> >(define key (send ch get-key-code))
> >(if (eq? key 'release) (send my-canvas on-paint) null)
> >  ]
> >  )))
> >
> > (new button% [parent my-frame]  [label "Replay"] )
> > (new button% [parent my-frame] [label "Save"] )
> >  (new button% [parent my-frame] [label "Load"] )
> >
> > (send my-frame show #t)
> >
> >
> > which runs perfectly with no error. However, I want to add two new
> bottons
> > "Play" and "Draw" on the left and right of the button "Replay". I tried
> to
> > use
> > horizontal-pane, changing the last several lines in the code as:
> >
> > (define my-pane (new horizontal-pane% [parent my-frame] [alignment
> '(center
> > center)] ))
> >
> > (new button% [parent my-pane]  [label "Play"] )
> > (new button% [parent my-pane]  [label "Replay"] )
> > (new button% [parent my-pane]  [label "Draw"] )
> >
> > (new button% [parent my-frame] [label "Save"] )
> > (new button% [parent my-frame] [label "Load"] )
> >
> > (send my-frame show #t)
> >
> > However, this is not what I wanted. The area of horizontal pane
> > is obviously too large, and it makes the three buttons too distant
> > from the two buttons below, also it shadows the main area above.
> > Is there a way to minimize the width of the horizontal pane such that
> > the outlook is the same as if not using it (the original code pasted
> above)?
>
> I think you want to make the panel have a non-stretchable height:
>
>  (define my-pane (new horizontal-pane%
>   [parent my-frame]
>   [alignment '(center center)]
>   [stretchable-height #f]))
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Problem when using horizontal pane

2015-07-17 Thread Mianlai Zhou
Hi all,

I have the following code:

#lang racket

(require slideshow racket/class racket/gui/base)

(define my-frame (new frame% [label "My chess"]
  [width 300] [height 391]
  [alignment '(center center)] ))

(define my-canvas
  (new (class canvas%
 (super-new [parent my-frame])
 [define/override (on-paint)
   (define my-dc (send my-canvas get-dc))
   (send my-dc clear)
   ((make-pict-drawer (colorize (circle 225) "red")) my-dc 20
20)
]
 [define/override (on-char ch)
   (define key (send ch get-key-code))
   (if (eq? key 'release) (send my-canvas on-paint) null)
 ]
 )))

(new button% [parent my-frame]  [label "Replay"] )
(new button% [parent my-frame] [label "Save"] )
 (new button% [parent my-frame] [label "Load"] )

(send my-frame show #t)


which runs perfectly with no error. However, I want to add two new bottons
"Play" and "Draw" on the left and right of the button "Replay". I tried to
use
horizontal-pane, changing the last several lines in the code as:

(define my-pane (new horizontal-pane% [parent my-frame] [alignment '(center
center)] ))

(new button% [parent my-pane]  [label "Play"] )
(new button% [parent my-pane]  [label "Replay"] )
(new button% [parent my-pane]  [label "Draw"] )

(new button% [parent my-frame] [label "Save"] )
(new button% [parent my-frame] [label "Load"] )

(send my-frame show #t)

However, this is not what I wanted. The area of horizontal pane
is obviously too large, and it makes the three buttons too distant
from the two buttons below, also it shadows the main area above.
Is there a way to minimize the width of the horizontal pane such that
the outlook is the same as if not using it (the original code pasted above)?

Thanks for your help in advance.

Mianlai

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] drawing with canvas

2015-06-22 Thread Mianlai Zhou
Hi people,

I am wondering why this segment of code failed to work:

; don't work
#lang racket

(require slideshow racket/class racket/gui/base)

(define my-frame (new frame% [label "my frame"]
 [width 300] [height 300]
 [alignment '(center center)] ))

(define my-canvas
  (new canvas% [parent my-frame]
  ))

(define my-dc (send my-canvas get-dc))

(draw-pict (circle 60) my-dc 40 40)


(send my-frame show #t)

While the following codes *do* work:

; do work
#lang racket

(require slideshow racket/class racket/gui/base)

(define my-frame (new frame% [label "my frame"]
 [width 300] [height 300]
 [alignment '(center center)] ))

(define my-canvas
  (new canvas% [parent my-frame]
   [paint-callback (lambda (self dc)
  (draw-pict (circle 60) dc 40 40)

   )]
  ))

(send my-frame show #t)

Is there anyway to avoid using redefining paint-callback to draw one or more
pictures on the canvas, as in the first example?

Thanks in advance for your answer,

Mianlai

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Doing pattern matching by reader macro

2015-05-21 Thread Mianlai Zhou
Your answer is perfect. Thanks a lot! I sent you a private message already
to have some further discussion.

Mianlai

On Thu, May 21, 2015 at 12:43 PM, Alexander D. Knauth 
wrote:

> Here’s one way to do something like that with a macro:
>
> https://github.com/AlexKnauth/define-match-spread-out/blob/master/define-match-spread-out/main.rkt
> And using it:
>
> https://github.com/AlexKnauth/define-match-spread-out/blob/master/define-match-spread-out/tests/test.rkt
>
>
> On May 18, 2015, at 9:39 AM, Mianlai Zhou 
> wrote:
>
> Hi Matthias,
>
> Thanks for answer. However, this is not what I wanted:
>
> I want to persist that I can write the code below (where "define" can be
> changed to other name):
>
> (define (f #t) 2)
> (define (f #f) 3)
> (define (f _) 0)
>
> to do what I want to do.
>
> So how should I define my "define" in order to do it? Your answer is
> perfect but it is a different form
> from my original code above.
>
> Could you give me an answer? Thanks.
>
> M.
>
> On Mon, May 18, 2015 at 9:20 PM, Matthias Felleisen 
> wrote:
>
>>
>> #lang racket
>>
>> (define/match (f n)
>>   [(#t) 2]
>>   [(#f) 3]
>>   [(_) 0])
>>
>> (list (f #t) (f #f) (f "where's my homework"))
>>
>>
>> On May 18, 2015, at 9:04 AM, Mianlai Zhou 
>> wrote:
>>
>> > Hi Racketeers,
>> >
>> > I am a new user of Racket.
>> >
>> > I would want to be able to write the following segment of code:
>> >
>> > (define (f #t) 2)
>> > (define (f #f) 3)
>> > (define (f  _) 0)
>> >
>> > My intention is to define a function f, such that given an argument #t
>> it will produce 2, or in
>> > case given an argument #f it will produce 3. For any other value (shown
>> by underscore), it
>> > will give 0. This is done by pattern matching.
>> >
>> > Obviously, I cannot do this straightforward, because in current Racket
>> the definitions in the
>> > prior lines will be overshadowed by definitions given in the lines
>> after. Moreover, I cannot give
>> > the real values of argument, #t, #f and underscore, directly. If I do
>> want to write the code as
>> > shown above, probably I have to use reader macro. The question now is,
>> how to do it? How to
>> > implement a pattern-matching-style syntax by means of reader macro?
>> >
>> > Thank you all for helping me, a real new beginner in Racket language.
>> >
>> > M.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to racket-users+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Doing pattern matching by reader macro

2015-05-18 Thread Mianlai Zhou
Hi Matthias,

Thanks for answer. However, this is not what I wanted:

I want to persist that I can write the code below (where "define" can be
changed to other name):

(define (f #t) 2)
(define (f #f) 3)
(define (f _) 0)

to do what I want to do.

So how should I define my "define" in order to do it? Your answer is
perfect but it is a different form
from my original code above.

Could you give me an answer? Thanks.

M.

On Mon, May 18, 2015 at 9:20 PM, Matthias Felleisen 
wrote:

>
> #lang racket
>
> (define/match (f n)
>   [(#t) 2]
>   [(#f) 3]
>   [(_) 0])
>
> (list (f #t) (f #f) (f "where's my homework"))
>
>
> On May 18, 2015, at 9:04 AM, Mianlai Zhou 
> wrote:
>
> > Hi Racketeers,
> >
> > I am a new user of Racket.
> >
> > I would want to be able to write the following segment of code:
> >
> > (define (f #t) 2)
> > (define (f #f) 3)
> > (define (f  _) 0)
> >
> > My intention is to define a function f, such that given an argument #t
> it will produce 2, or in
> > case given an argument #f it will produce 3. For any other value (shown
> by underscore), it
> > will give 0. This is done by pattern matching.
> >
> > Obviously, I cannot do this straightforward, because in current Racket
> the definitions in the
> > prior lines will be overshadowed by definitions given in the lines
> after. Moreover, I cannot give
> > the real values of argument, #t, #f and underscore, directly. If I do
> want to write the code as
> > shown above, probably I have to use reader macro. The question now is,
> how to do it? How to
> > implement a pattern-matching-style syntax by means of reader macro?
> >
> > Thank you all for helping me, a real new beginner in Racket language.
> >
> > M.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Doing pattern matching by reader macro

2015-05-18 Thread Mianlai Zhou
Hi Racketeers,

I am a new user of Racket.

I would want to be able to write the following segment of code:

(define (f #t) 2)
(define (f #f) 3)
(define (f  _) 0)

My intention is to define a function f, such that given an argument #t it
will produce 2, or in
case given an argument #f it will produce 3. For any other value (shown by
underscore), it
will give 0. This is done by pattern matching.

Obviously, I cannot do this straightforward, because in current Racket the
definitions in the
prior lines will be overshadowed by definitions given in the lines after.
Moreover, I cannot give
the real values of argument, #t, #f and underscore, directly. If I do want
to write the code as
shown above, probably I have to use reader macro. The question now is, how
to do it? How to
implement a pattern-matching-style syntax by means of reader macro?

Thank you all for helping me, a real new beginner in Racket language.

M.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.