[racket-users] Animation-problem

2016-12-04 Thread Janiho
Hello!

The animation in this Pet Shop boys music video (LINK: 
https://www.youtube.com/watch?v=lNLkcOqQSBM (very good song btw!))

gave me a inspiration try to make it with the Racket.

I'm very novice using the Racket, so I got to dead-end early.
 

I get this far:

(require 2htdp/universe)
(require 2htdp/image)


(define SUPER (overlay (text "SUPER" 105 (make-color (random 255)
(random 255)
(random 255)))

   (circle 200 "solid" (make-color (random 255)
(random 255)
(random 255)


SUPER

--

This code does one figure. Now the problem is how I can make them in a row and 
changing colors at the same time. I just don't understand how to get different 
figures in racket's memory. 

Any advices, what might be the easiest way to do it? Using 
map/foldl/place-image -commands maybe? 
 

-- 
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] Animation-problem

2016-12-04 Thread Daniel Prager
Hi Janiho

This should help get you get going ...

The function big-bang takes minimally:
*  an initial "state of the world",
* a function that  that takes the current world state and evolves it with
every tick of a notional clock, and
* a function that takes the state of the world and draws it.

In this case there's no dependence on the existing state, so the function
random-state ignores what is passed in, but it has the necessary form to
work with big-bang.

Exercise: add a counter to the world state that increments with every tick,
and show this as a number in the top-left corner of the animated image.

Dan


#lang racket

(require 2htdp/universe)
(require 2htdp/image)

(struct world (foreground background))

(define (random-color)
  (make-color (random 255) (random 255) (random 255)))

(define (random-state current)
  (world (random-color) (random-color)))

(define (SUPER state)
  (overlay (text "SUPER" 105 (world-foreground state))
   (circle 200 "solid" (world-background state

(big-bang (random-state null)
  (on-tick random-state 0.3) ; change the image every 0.3 seconds
  (to-draw SUPER))

-- 
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] Re: Language-provided bindings and arrows in DrRacket

2016-12-04 Thread Dupéron Georges
Le dimanche 4 décembre 2016 04:18:44 UTC+1, Robby Findler a écrit :
> The fully expanded form of the original program doesn't have a require
> that brings in displayln?

Indeed, if I use (#%require lng) the arrows get drawn.

However, the body can require libraries which shadow some of the 
language-provided bindings, e.g. (require type-expander) shadows some of the 
bindings imported by #lang typed/racket. I therefore use (#%require (only lng)) 
to make sure the lng module is available, without creating potential conflicts 
with other required modules.

I was hoping there would be some trick similar to disappeared-use and 
disappeared-bindings that would help me solve this problem. I suppose I could 
apply a 'disappeared-binding property to the "racket/base" on the second line, 
using a list containing every binding imported by the "module language".

-- 
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] Re: Language-provided bindings and arrows in DrRacket

2016-12-04 Thread Dupéron Georges
I think I found a solution which allows me to inject the (#%require lng) 
without causing conflicts with other required module: applying an extra scope 
to the whole body makes the other (require) forms more specific, and they can 
shadow bindings imported by (#%require lng).

Here is the modified "MyLang.rkt":

#lang racket
(provide (rename-out [my-module-begin #%module-begin]))
(define-syntax (my-module-begin stx)
  (syntax-case stx ()
[(_ real-lang body)
 (syntax-case (local-expand #'(module m real-lang body) 'top-level (list)) 
()
   [(module nm lng (#%plain-module-begin . body2))
#`(#%plain-module-begin
 (#%require lng)
 . #,((make-syntax-introducer) #'body2))])]))

And here's an example file using it:

(module m "MyLang.rkt"
  ;; delegates to this language:
  typed/racket/base
  ;; body:
  (begin
(require racket/set)
(displayln ;; arrow successfully drawn to typed/racket/base
 (set  ;; arrow successfully drawn to racket/set
  "Hello"

Without the extra scope, I would get this error because racket/set shadows 
these bindings imported by typed/racket/base:

module: identifier already imported from a different source in:
  for/set
  racket/set
  typed/racket/base

My problem seems solved, but if this extra-scope trick has some unwanted 
consequences, I would definitely want to hear about them!

-- 
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] Language-provided bindings and arrows in DrRacket

2016-12-04 Thread Alex Knauth

> On Dec 4, 2016, at 10:27 AM, Dupéron Georges  
> wrote:
> 
> I think I found a solution which allows me to inject the (#%require lng) 
> without causing conflicts with other required module: applying an extra scope 
> to the whole body makes the other (require) forms more specific, and they can 
> shadow bindings imported by (#%require lng).

A nested scope seems like the correct solution. The macro expander does 
something similar with module body's, but it creates a pair of scopes for the 
body. I'm not sure whether you would need to do the same...

http://www.cs.utah.edu/plt/scope-sets/general-macros.html#%28part._.Modules_and_.Phases%29
 


I can't see any unwanted consequences of this approach, but I also don't know 
much about how scopes work with requires.

Alex Knauth

> Here is the modified "MyLang.rkt":
> 
> #lang racket
> (provide (rename-out [my-module-begin #%module-begin]))
> (define-syntax (my-module-begin stx)
>  (syntax-case stx ()
>[(_ real-lang body)
> (syntax-case (local-expand #'(module m real-lang body) 'top-level (list)) 
> ()
>   [(module nm lng (#%plain-module-begin . body2))
>#`(#%plain-module-begin
> (#%require lng)
> . #,((make-syntax-introducer) #'body2))])]))

> My problem seems solved, but if this extra-scope trick has some unwanted 
> consequences, I would definitely want to hear about them!


-- 
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] Reducing Program Startup Time

2016-12-04 Thread Matthias Felleisen


> On Dec 3, 2016, at 9:40 PM, Dupéron Georges  
> wrote:
> 
> A few ideas:
> 
> 1) Loading a lot of modules can be slow. You are already avoiding that by 
> using racket/base and racket/gui/base, so that's good, but it already takes 
> me 0.5s just to require these :-( . I don't know it there is much to do about 
> this.


Also consider lazy require. 

-- 
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] Reducing Program Startup Time

2016-12-04 Thread Lehi Toskin
Dupéron Georges I did what you suggested and placed a displayln at the 
beginning. There's a wait time between when I execute the program and then 
everything happens all at once - the displayln occurs at the same time as when 
the GUI spawns.

> On Sunday, December 4, 2016 at 10:05:23 AM UTC-8, Matthias Felleisen wrote:
> 
> Also consider lazy require.

That actually seems to make it run slower.

$ time ./ivy -V
Ivy 1.2

real0m2.414s
user0m2.288s
sys 0m0.119s

versus

$ time /usr/bin/ivy -V
Ivy 1.2

real0m1.955s
user0m1.796s
sys 0m0.147s

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