Re: [racket-users] making games in racket

2015-12-27 Thread Taro Annual
2015年12月27日日曜日 11時39分10秒 UTC+9 Matthew Flatt:
> At Sat, 26 Dec 2015 06:52:19 -0800 (PST), Taro Annual wrote:
> > 2015年12月26日土曜日 21時54分52秒 UTC+9 Matthew Flatt:
> > > Can you try a current snapshot to see whether it eliminates pauses?:
> > > 
> > >   http://pre.racket-lang.org/
> > > 
> > > [...]
> > 
> > Sorry, it doesn't work well. Try the follows:
> 
> Can you say more about your platform, how you're running the program,
> and what the pause looks like?
> 
> On OS X 10.11 and Racket 6.3.0.10, I started the program with
> 
>  env PLTSTDERR="debug@GC error" racket pong.rkt
> 
> and I see output like
> 
>  ...
>  GC: 0:MAJ @ 111,386K(+56,166K)[+7,508K]; free 31,113K(-47,429K) 145ms @ 1521
>  GC: 0:mIn @ 113,400K(+73,411K)[+9,864K]; free 29,273K(-27,310K) 18ms @ 3536
>  GC: 0:mIn @ 92,385K(+92,464K)[+9,756K]; free 8,216K(-8,216K) 4ms @ 4125
>  GC: 0:mIn @ 92,433K(+92,416K)[+9,752K]; free 8,249K(-8,249K) 3ms @ 4705
>  GC: 0:mIn @ 92,470K(+92,379K)[+9,752K]; free 8,267K(-8,267K) 4ms @ 5295
>  GC: 0:mIn @ 92,447K(+92,402K)[+9,752K]; free 8,235K(-8,235K) 4ms @ 5898
>  GC: 0:mIn @ 92,468K(+92,381K)[+9,752K]; free 8,231K(-8,231K) 4ms @ 6485
>  GC: 0:mIn @ 92,517K(+92,331K)[+9,760K]; free 8,266K(-8,266K) 4ms @ 7050
>  GC: 0:mIn @ 92,511K(+92,337K)[+9,760K]; free 8,237K(-8,237K) 3ms @ 7599
>  GC: 0:mIn @ 92,559K(+92,290K)[+9,756K]; free 8,282K(-8,282K) 4ms @ 8181
>  GC: 0:mIn @ 92,520K(+92,328K)[+9,756K]; free 8,225K(-8,225K) 3ms @ 8767
>  GC: 0:mIn @ 92,521K(+92,328K)[+9,756K]; free 8,203K(-8,203K) 4ms @ 9355
>  GC: 0:mIn @ 92,542K(+92,307K)[+9,752K]; free 8,211K(-8,211K) 3ms @ 9929
>  GC: 0:mIn @ 92,659K(+92,190K)[+9,756K]; free 8,232K(-8,232K) 4ms @ 10501
> 
> where the "MAJ" is just before the game window shows. I'm not noticing
> pauses interactively, either. I'm only running the game for under a
> minute, though.
> 
> I see similar results when I run in DrRacket. The pauses tend to be
> longer, but usually in the 6-10ms range -- and nothing close to
> 300-500ms after the forced GC before the game starts.
> 
> 
> Thanks for your help,
> Matthew

Umm, maybe there are some problems in my code.

Taro

-- 
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] making games in racket

2015-12-26 Thread Taro Annual
2015年12月26日土曜日 21時52分36秒 UTC+9 Jay McCarthy:
> Hi Taro,
> 
> The freezes are probably garbage-collection pauses. Recently (in the
> snapshot builds) there is a new incremental GC mode that may improve
> your program.
> 
> I have a few libraries---lux and mode-lambda---that are designed for
> higher performance than 2htdp/universe and 2htdp/image but provide
> similar functionalities
> 
> Jay
> 
> On Sat, Dec 26, 2015 at 1:17 AM, Taro Annual  wrote:
> > Hi,
> >
> > I make "pong" game in big-bang(2hdp/universe).
> > But, moving a racket(not language!) by keyboard("up", "down", ...), the 
> > racket freezes in 0.3~0.5s sometimes.
> >
> > I think it is due to the beginner's platform.
> > What modules/syntaxes are used in action games in Racket language.
> >
> > Thanks,
> > Taro.
> >
> > --
> > 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.
> 
> 
> 
> -- 
> Jay McCarthy
> Associate Professor
> PLT @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> 
>"Wherefore, be not weary in well-doing,
>   for ye are laying the foundation of a great work.
> And out of small things proceedeth that which is great."
>   - D&C 64:33

Jay,

Thank you. I'll try these.

Taro

-- 
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] making games in racket

2015-12-26 Thread Taro Annual
2015年12月26日土曜日 21時54分52秒 UTC+9 Matthew Flatt:
> At Fri, 25 Dec 2015 22:17:21 -0800 (PST), Taro Annual wrote:
> > I make "pong" game in big-bang(2hdp/universe).
> > But, moving a racket(not language!) by keyboard("up", "down", ...), the 
> > racket 
> > freezes in 0.3~0.5s sometimes.
> > 
> > I think it is due to the beginner's platform.
> > What modules/syntaxes are used in action games in Racket language.
> 
> It sounds like you're seeing pauses related to garbage collection. The
> current pre-release version of Racket includes improvements aimed
> specifically at this problem.
> 
> Can you try a current snapshot to see whether it eliminates pauses?:
> 
>   http://pre.racket-lang.org/
> 
> The program should run better within DrRacket. For best results,
> though, you may need to run outside of DrRacket (either by starting the
> program with `racket` on the command line or by choosing "Create
> Executable" in DrRacket's "Racket" menu).
> 
> If the pauses are still not eliminated in the current snapshot, I'm
> interested to take a closer look at your program.
> 
> Thanks,
> Matthew

Matthew,

Sorry, it doesn't work well. Try the follows:

---source code---

#lang racket
(require 2htdp/universe 2htdp/image point-free)
;(require lux mode-lambda)

; Tennis for two
;
; [Original Version]
; https://kyorohiro.gitbooks.io/doc_scratch/content/tennis_of_two/index.html

(struct world (player1 player2 ball) #:transparent)
(struct ball (x y dx dy) #:transparent)
(struct player (y keycnt) #:transparent)

(define BALL-IMAGE (circle 10 "solid" "orange"))
(define RACKET1-IMAGE (rectangle 5 100 "solid" "red"))
(define RACKET2-IMAGE (rectangle 5 100 "solid" "blue"))

(define (direction x)
  (cond ((= x 0) 0)
((> x 0) 1)
(else -1)))
(define (saturate x a b) (max a (min b x)))
(define (from-to? x a b) (and (>= x a) (<= x b)))

(define (on-tick-func w)
  (let ((player1 (world-player1 w)) (player2 (world-player2 w))
(ball1 (world-ball w)))
(let ((y1 (player-y player1)) (keycnt1 (player-keycnt player1))
  (y2 (player-y player2)) (keycnt2 (player-keycnt player2))
  (x (ball-x ball1)) (y (ball-y ball1))
  (dx (ball-dx ball1)) (dy (ball-dy ball1)))
  (let* ((n?x (+ x dx)) (n?y (+ y dy))
 (top1 (- y1 50)) (btm1 (+ y1 50))
 (top2 (- y2 50)) (btm2 (+ y2 50))
 (collision1 (and (from-to? 50 n?x x)
  (or (from-to? y top1 btm1)
  (from-to? n?y top1 btm1
 (collision2 (and (from-to? 550 x n?x)
  (or (from-to? y top2 btm2)
  (from-to? n?y top2 btm2
 (nx (cond (collision1 (max n?x 50))
   (collision2 (min n?x 550))
   (else n?x)))
 (ny (saturate n?y 0 400))
 (ndx (cond (collision1 (abs dx))
(collision2 (- (abs dx)))
(else dx)))
 (ndy (cond ((<= y 0) (abs dy))
((>= y 400) (- (abs dy)))
(else dy)))
 (next-player1
  (player
   (saturate (+ y1 (* (direction keycnt1) 10)) 50 350)
   (- keycnt1 (direction keycnt1
 (next-player2
  (player
   (saturate (+ y2 (* (direction keycnt2) 10)) 50 350)
   (- keycnt2 (direction keycnt2
 (next-ball (ball nx ny ndx ndy)))
(when collision1 (display "collision1"))
(when collision2 (display "collision2"))
(world next-player1 next-player2 next-ball)
  
(big-bang
  (world (player 200 0) (player 200 0) (ball 300 200 -5. 2.5))

  {on-key
   (lambda (w key)
 (case key
   [("up")   (world (world-player1 w)
(player (player-y (world-player2 w)) -10)
(world-ball w))]
   [("down") (world (world-player1 w)
(player (player-y (world-player2 w)) 10)
(world-ball w))]
   [("a")(world (player (player-y (world-player1 w)) -10)
(world-player2 w)
(world-ball w))]
   [("z")(world (player (player-y (world-player1 w)) 10)
(world-player2 w)
(world-ball w))]
   [("b")(display w)
 w]
   [else w]))}

  {on-release
   (lambda (w key)
 (world (player (player-y (world-player1 w)) 0)
(player (player-y (world-player2 w)) 0)
(world-ball w)))}

  {on-tick on-tick-func}

  {on-draw
   (lambda (w)

[racket-users] making games in racket

2015-12-25 Thread Taro Annual
Hi,

I make "pong" game in big-bang(2hdp/universe).
But, moving a racket(not language!) by keyboard("up", "down", ...), the racket 
freezes in 0.3~0.5s sometimes.

I think it is due to the beginner's platform.
What modules/syntaxes are used in action games in Racket language.

Thanks,
Taro. 

-- 
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] Try Racket is ABORTING.

2015-12-18 Thread Taro Annual
2015年12月18日金曜日 23時26分40秒 UTC+9 John Berry:
> Kicked the server. Seems to work now. 
> 
> 
> 
> On Fri, Dec 18, 2015 at 3:57 PM, Taro Annual  wrote:
> over
> 
> 
> 
> --
> 
> 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...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

Thank you. I went there because I want to try Drawing Modules. Try Racket can 
be used them.

ex. (circle 10) or
(require 2htdp/image) (circle 10 "solid" "blue")

-- 
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] Try Racket is ABORTING.

2015-12-18 Thread Taro Annual
over

-- 
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] Try Racket is ABORTED.

2015-12-18 Thread Taro Annual
over.

-- 
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] Re: How to put image background?

2015-12-16 Thread Taro Annual
2015年12月16日水曜日 1時43分03秒 UTC+9 Alejandro López:
> I want to know how to put a background image in a viewport

In graphic use, I recommend 2htdp/image library.
If you need to treat .bmp or .png so on, you can paste the file images into 
your code.
(Dr. Racket's menubar, select [Insert] - [Insert Image...])

-- 
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] about rackjure

2015-12-12 Thread Taro Annual
2015年12月13日日曜日 2時21分21秒 UTC+9 Alex Knauth:
> > On Dec 12, 2015, at 9:18 AM, Taro Annual  wrote:
> 
> > In racket libraries, rackjure module looks usable.
> > But, rackjure's threading(~>) denys lambda.
> > 
> > 
> > #lang rackjure
> > 
> >> (#fn(map sqr %) '(1 2))
> > '(1 4)
> >> (~> '(1 2) #fn(map sqr %))
> > [Error] lambda: not an identifier, identifier with default, or keyword in: 
> > (1 2)
> 
> This will work if you use (~> '(1 2) [#fn(map sqr %)]).
> 
> Or, if you use the `~>` from the point-free package instead, (~> '(1 2) 
> #fn(map sqr %)) works fine. In the point-free package, ~> is a function, so 
> it works with values (i.e. functions) instead of not-quite-expressions.
> 
> >> (define (sqrlst lst) (map sqr lst))
> >> (~> '(1 2) sqrlst)
> > '(1 4)
> > 
> > 
> > In this case, what is the suitable solution?
> > Thank you for reading.
> > 
> > Taro

Thanks, Alex.

I'll use point-free and srfi/26 module.

#lang racket
(require point-free srfi/26)

(define (distance lst)
  (~> lst
  (cut map sqr <>)
  (cut apply + <>)
  sqrt))

> (distance '(3 4))
5

-- 
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] about rackjure

2015-12-12 Thread Taro Annual
Hi,

I want to make method chains like this:


#lang racket

(define (pipe init . procs)
  (foldl (lambda (x y) (x y)) init procs))

(pipe '(3 4)
  (lambda (l) (map sqr l))
  (lambda (l) (apply + l))
  sqrt)

5


In racket libraries, rackjure module looks usable.
But, rackjure's threading(~>) denys lambda.


#lang rackjure

> (#fn(map sqr %) '(1 2))
'(1 4)
> (~> '(1 2) #fn(map sqr %))
[Error] lambda: not an identifier, identifier with default, or keyword in: (1 2)
> (define (sqrlst lst) (map sqr lst))
> (~> '(1 2) sqrlst)
'(1 4)


In this case, what is the suitable solution?
Thank you for reading.

Taro

-- 
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] about REALM OF RACKET

2015-12-11 Thread Taro Annual
2015年12月11日金曜日 22時15分20秒 UTC+9 Ben Greenman:
> A is close, but the problem just wants the number of guesses -- not their 
> values. In your example, the right value to display is 5.
> 
> 
> On Fri, Dec 11, 2015 at 7:35 AM, Taro Annual  wrote:
> Everyone,
> 
> 
> 
> Hi, I'm reading "REALM OF RACKET" and can't understand the following question.
> 
> 
> 
> 
> 
> [p.89 / Chapter 5  Chapter Challenges - Medium]
> 
> 
> 
> Change the Guess My Number game so that it displays the number of guesses the 
> program takes to find the player's number. Hint: you might need to change the 
> data used to represent the world's state.
> 
> 
> 
> 
> 
> I guess the next two meanings about the above:
> 
> 
> 
> A: displays the history of guess numbers
> 
>  ex) (start 1 100) and I thought 53 -> (50) -> (50 75) -> (50 75 62) -> (50 
> 75 62 56) -> (50 75 62 56 53)
> 
> 
> 
> B: displays the guess number and "It's your number, isn't it?" in the end 
> instead of "End"
> 
> 
> 
> 
> 
> Taro
> 
> 
> 
> --
> 
> 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...@googlegroups.com.
> 
> For more options, visit https://groups.google.com/d/optout.

I see very well. Thank you, Ben!

-- 
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] about REALM OF RACKET

2015-12-11 Thread Taro Annual
Everyone,

Hi, I'm reading "REALM OF RACKET" and can't understand the following question.


[p.89 / Chapter 5  Chapter Challenges - Medium]

Change the Guess My Number game so that it displays the number of guesses the 
program takes to find the player's number. Hint: you might need to change the 
data used to represent the world's state.


I guess the next two meanings about the above:

A: displays the history of guess numbers
 ex) (start 1 100) and I thought 53 -> (50) -> (50 75) -> (50 75 62) -> (50 75 
62 56) -> (50 75 62 56 53)

B: displays the guess number and "It's your number, isn't it?" in the end 
instead of "End"


Taro

-- 
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] Re: Formatting Function

2015-10-15 Thread Taro Annual
2015年10月13日火曜日 3時28分13秒 UTC+9 George Neuner:
> On Mon, 12 Oct 2015 12:28:56 -0400, Deren Dohoda
>  wrote:
> 
> >Probably racket/format is what you need to look at.
> >http://docs.racket-lang.org/reference/strings.html#%28mod-path._racket%2Fformat%29
> 
> 
> Or  SRFI 48:
> 
> http://docs.racket-lang.org/srfi/srfi-std/srfi-48.html
> 
> racket/format is more capable, but the SRFI fomat may be simpler to
> use if you are just looking for something like C printf().
> 
> George

Thank you, Daren.
Thank you, George.

I'm just busy this week and I'm not willing to ignore.

Taro

-- 
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] Formatting Function

2015-10-12 Thread Taro Annual
Hi,

Please tell me the way of the following in racket?

In C,
printf("%02d", 2);

In Common Lisp,
(format t "~2,'0D" 2)

-- 
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.