Re: [racket-dev] 2htdp/image Feature Suggestion
Thanks. I always use DrRacket for editing racket code. Jos. > -Original Message- > From: Greg Hendershott [mailto:greghendersh...@gmail.com] > Sent: domingo, 29 de junio de 2014 5:55 > To: Jos Koot > Cc: dev; jja.k...@gmail.com > Subject: Re: [racket-dev] 2htdp/image Feature Suggestion > > On Mon, Jun 23, 2014 at 9:44 PM, Jos Koot wrote: > > style. Writing this, the idea comes up in my mind that it > should be possible > > to do some transformations to the recommended style by > means of redex. Or > > may be by means of syntax-case while limiting the > transformers to the > > desired level of expansion. Both instuments are interesting > enough for me to > > give it a try. If I am able to do something usefull in this > sense, you'll > > hear of me, but give me some time, please. > > If you use Emacs, check out Ryan's sexp-rewrite mode. IIUC he's > implemented `syntax-parse`-like functionality in Elisp: > > https://github.com/rmculpepper/sexp-rewrite > > > p.s. In a similar spirit, but for Clojure, and IIUC implemented > leveraging paredit: > > https://github.com/clojure-emacs/clj-refactor.el _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Mon, Jun 23, 2014 at 9:44 PM, Jos Koot wrote: > style. Writing this, the idea comes up in my mind that it should be possible > to do some transformations to the recommended style by means of redex. Or > may be by means of syntax-case while limiting the transformers to the > desired level of expansion. Both instuments are interesting enough for me to > give it a try. If I am able to do something usefull in this sense, you'll > hear of me, but give me some time, please. If you use Emacs, check out Ryan's sexp-rewrite mode. IIUC he's implemented `syntax-parse`-like functionality in Elisp: https://github.com/rmculpepper/sexp-rewrite p.s. In a similar spirit, but for Clojure, and IIUC implemented leveraging paredit: https://github.com/clojure-emacs/clj-refactor.el _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 27, 2014, at 5:29 PM, Robby Findler wrote: > I've generally tried to keep the image arguments last to make nested > compositions of functions easier to read. Since we have to keep frame > for backwards compatibilities reasons regardless, I don't think we > need to worry about making color-frame's color argument optional. > > Robby Makes sense. Thanks for the explanation! -Kevin _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
I've generally tried to keep the image arguments last to make nested compositions of functions easier to read. Since we have to keep frame for backwards compatibilities reasons regardless, I don't think we need to worry about making color-frame's color argument optional. Robby On Fri, Jun 27, 2014 at 12:38 PM, Kevin Forchione wrote: > > On Jun 22, 2014, at 9:42 PM, Robby Findler > wrote: > >> Thanks! I've added these two functions. >> >> Robby >> >> On Sun, Jun 22, 2014 at 12:26 PM, Kevin Forchione wrote: >>> >>> On Jun 21, 2014, at 5:02 PM, Robby Findler >>> wrote: >>> >>> What do you think about a variant on center-crop called crop/align >>> that accepts a width, a height, an image, and an x-place and a >>> y-place? >>> >>> That would seem to fit better into the library the way it's currently >>> constructed. >>> >>> For working around the frame issue, how about just a color-frame >>> function that controls the color for now? >>> >>> >>> I agree! That’s even better in terms of use and simplicity. >>> >>> -Kevin > > One question about color-frame’s arguments. I’ve played with it in the latest > push, and it’s > > (color-frame color image) > > with color being first and required. Would it be better to have it 2nd and > default to ‘black, so that by default color-frame reduces to frame? > > -Kevin > _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 22, 2014, at 9:42 PM, Robby Findler wrote: > Thanks! I've added these two functions. > > Robby > > On Sun, Jun 22, 2014 at 12:26 PM, Kevin Forchione wrote: >> >> On Jun 21, 2014, at 5:02 PM, Robby Findler >> wrote: >> >> What do you think about a variant on center-crop called crop/align >> that accepts a width, a height, an image, and an x-place and a >> y-place? >> >> That would seem to fit better into the library the way it's currently >> constructed. >> >> For working around the frame issue, how about just a color-frame >> function that controls the color for now? >> >> >> I agree! That’s even better in terms of use and simplicity. >> >> -Kevin One question about color-frame’s arguments. I’ve played with it in the latest push, and it’s (color-frame color image) with color being first and required. Would it be better to have it 2nd and default to ‘black, so that by default color-frame reduces to frame? -Kevin _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
FWIW, I think this is what the style guide would recommend. I found the transformation to be pretty straightforward, except that I had to rename on occurrence of 'H' to 'H2'. (I didn't try to test it, tho!) Robby (define (make-natural->rearrangement L (EQ? equal?)) (define N (nr-of-rearrangements L EQ?)) (λ (K) (let rearrange ((L L) (K K) (N N) (result '())) ; Look for the K-th rearrangement of L and put it's elements in result. (cond [(null? L) result] [else (let pseudo-rotate ((H L) (T '()) (K K)) ; Look in subsequent pseudorotations. (define E (car H)) (define H2 (cdr H)) (cond [(member E T EQ?) ; Skip pseudorotation if it's car already was car of a previous one. (pseudo-rotate H2 (cons E T) K)] [else (define M (/ (* N (count-occurrences E L EQ?)) (length L))) ; M is the nr of rearrangements of (append H T) ; computed by means of a recurrent relation. (cond [(< K M) ; The rearrangement is in this pseudorotation. (rearrange (append H2 T) K M (cons E result))] [else ; The rearrangement is not in this pseudorotation. ; Look in the following pseudorotation, but decrease K by the ; nr of rearrangements of the skipped pseudorotation. (pseudo-rotate H2 (cons E T) (- K M))])]))] _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
Hi Robby Replacing if by cond is very stylisch indeed. Nowadays I use cond more than if, especially if it is nested or if I need internal definitions in one or more of the alternatives. Replacing the outer named let by a reference to a function defined outside of the procedure is not too difficult, I think. I have tried to follow the recommendations strictly for this piece of code, especially avoiding the nesting of all let-forms (named or unnamed) of which this piece of code has four levels, two named and two unnamed. When I try that for all levels, I introduce bugs. Don't understand me wrong. I do appreciate the recommendations. In fact the style interests me much. I see the advantages of cooperators using the same style. Writing this, the idea comes up in my mind that it should be possible to do some transformations to the recommended style by means of redex. Or may be by means of syntax-case while limiting the transformers to the desired level of expansion. Both instuments are interesting enough for me to give it a try. If I am able to do something usefull in this sense, you'll hear of me, but give me some time, please. Thanks for your reaction, Jos PS Within DrRacket transformation to the recommended indentation is almost trivial. 'Almost', for in some cases additional newlines may be neceessary. And there is pretty-print, of course. > -Original Message- > From: Robby Findler [mailto:ro...@eecs.northwestern.edu] > Sent: martes, 24 de junio de 2014 2:12 > To: Jos Koot > Cc: Asumu Takikawa; Kevin Forchione; dev@racket-lang.org; > jja.k...@gmail.com > Subject: Re: [racket-dev] 2htdp/image Feature Suggestion > > I think that the prefer-define-over-let applies only to the first let > in this program. > > The style guide also would recommend 'cond' over 'if' here, but it > becomes very very important to do that only if there were nested > 'let's or 'begin's or the like and you don't have that. > > Robby > > On Mon, Jun 23, 2014 at 12:32 PM, Jos Koot wrote: > > In the recommendations of > http://docs.racket-lang.org/style/index.html it is > > recommended to use (internal or module top-level) define > rather than named > > let. > > I use named let a lot. How would you rewrite the following? > For me it is > > rather difficult to make the change without loosing track > of the scope of > > the variables. I also have a rather distinct way of indenting. > > > > #lang racket > > > > #| > > A rearrangement of a list L is a list with the same elements as L, > > but possibly in another order. > > Proc make-natural->rearrangement takes a list L and returns a proc. > > Let N be the number of distinct rearrangements of L. > > The returned proc takes an index K less than N and returns the K-th > > distinct rearrangement of L. Two rearrangements R0 and R1 > are distinct if > > (not (andmap EQ? R0 R1)). > > EQ? must be an equivalence relation on the elements of L. > > > > E = element > > H = head of L > > T = tail of L (append H T) = L > > K = index > > N = nr of distinct rearrangements of L. > > |# > > > > (define (make-natural->rearrangement L (EQ? equal?)) > > (let ((N (nr-of-rearrangements L EQ?))) > > (lambda (K) > >(let rearrange ((L L) (K K) (N N) (result '())) > > ; Look for the K-th rearrangement of L and put it's > elements in result. > > (if (null? L) result > > (let pseudo-rotate ((H L) (T '()) (K K)) > > ; Look in subsequent pseudorotations. > > (let ((E (car H)) (H (cdr H))) > >(if (member E T EQ?) > > ; Skip pseudorotation if it's car already was car > of a previous one. > > (pseudo-rotate H (cons E T) K) > > (let ((M (/ (* N (count-occurrences E L EQ?)) (length L > > ; M is the nr of rearrangements of (append H T) > > ; computed by means of a recurrent relation. > > (if (< K M) > > ; The rearrangement is in this pseudorotation. > > (rearrange (append H T) K M (cons E result)) > > ; The rearrangement is not in this pseudorotation. > > ; Look in the following pseudorotation, but > decrease K by the > > ; nr of rearrangements of the skipped pseudorotation. > > (pseudo-rotate H (cons E T) (- K M > > > > (define (nr-of-rearrangements L EQ?) ...) > > (define (count-occcurrences E L EQ?) ...) > > > >> -Original Message- > >> From: dev [mailto:dev-boun...@racket-lang.org] On Behalf Of > >> Asumu Taki
Re: [racket-dev] 2htdp/image Feature Suggestion
I think that the prefer-define-over-let applies only to the first let in this program. The style guide also would recommend 'cond' over 'if' here, but it becomes very very important to do that only if there were nested 'let's or 'begin's or the like and you don't have that. Robby On Mon, Jun 23, 2014 at 12:32 PM, Jos Koot wrote: > In the recommendations of http://docs.racket-lang.org/style/index.html it is > recommended to use (internal or module top-level) define rather than named > let. > I use named let a lot. How would you rewrite the following? For me it is > rather difficult to make the change without loosing track of the scope of > the variables. I also have a rather distinct way of indenting. > > #lang racket > > #| > A rearrangement of a list L is a list with the same elements as L, > but possibly in another order. > Proc make-natural->rearrangement takes a list L and returns a proc. > Let N be the number of distinct rearrangements of L. > The returned proc takes an index K less than N and returns the K-th > distinct rearrangement of L. Two rearrangements R0 and R1 are distinct if > (not (andmap EQ? R0 R1)). > EQ? must be an equivalence relation on the elements of L. > > E = element > H = head of L > T = tail of L (append H T) = L > K = index > N = nr of distinct rearrangements of L. > |# > > (define (make-natural->rearrangement L (EQ? equal?)) > (let ((N (nr-of-rearrangements L EQ?))) > (lambda (K) >(let rearrange ((L L) (K K) (N N) (result '())) > ; Look for the K-th rearrangement of L and put it's elements in result. > (if (null? L) result > (let pseudo-rotate ((H L) (T '()) (K K)) > ; Look in subsequent pseudorotations. > (let ((E (car H)) (H (cdr H))) >(if (member E T EQ?) > ; Skip pseudorotation if it's car already was car of a previous one. > (pseudo-rotate H (cons E T) K) > (let ((M (/ (* N (count-occurrences E L EQ?)) (length L > ; M is the nr of rearrangements of (append H T) > ; computed by means of a recurrent relation. > (if (< K M) > ; The rearrangement is in this pseudorotation. > (rearrange (append H T) K M (cons E result)) > ; The rearrangement is not in this pseudorotation. > ; Look in the following pseudorotation, but decrease K by the > ; nr of rearrangements of the skipped pseudorotation. > (pseudo-rotate H (cons E T) (- K M > > (define (nr-of-rearrangements L EQ?) ...) > (define (count-occcurrences E L EQ?) ...) > >> -----Original Message- >> From: dev [mailto:dev-boun...@racket-lang.org] On Behalf Of >> Asumu Takikawa >> Sent: lunes, 23 de junio de 2014 7:35 >> To: Kevin Forchione >> Cc: dev@racket-lang.org >> Subject: Re: [racket-dev] 2htdp/image Feature Suggestion >> >> On 2014-06-22 20:27:21 -0700, Kevin Forchione wrote: >> >Thanks! Is there any documentation or guide on which >> *styles* to prefer in >> >writing Racket code? I find myself scratching my head at >> times in these >> >matters! >> >> In recent Racket distributions and online docs there's now a style >> manual: >> >> http://docs.racket-lang.org/style/index.html >> >> Cheers, >> Asumu >> _ >> Racket Developers list: >> http://lists.racket-lang.org/dev > > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
In the recommendations of http://docs.racket-lang.org/style/index.html it is recommended to use (internal or module top-level) define rather than named let. I use named let a lot. How would you rewrite the following? For me it is rather difficult to make the change without loosing track of the scope of the variables. I also have a rather distinct way of indenting. #lang racket #| A rearrangement of a list L is a list with the same elements as L, but possibly in another order. Proc make-natural->rearrangement takes a list L and returns a proc. Let N be the number of distinct rearrangements of L. The returned proc takes an index K less than N and returns the K-th distinct rearrangement of L. Two rearrangements R0 and R1 are distinct if (not (andmap EQ? R0 R1)). EQ? must be an equivalence relation on the elements of L. E = element H = head of L T = tail of L (append H T) = L K = index N = nr of distinct rearrangements of L. |# (define (make-natural->rearrangement L (EQ? equal?)) (let ((N (nr-of-rearrangements L EQ?))) (lambda (K) (let rearrange ((L L) (K K) (N N) (result '())) ; Look for the K-th rearrangement of L and put it's elements in result. (if (null? L) result (let pseudo-rotate ((H L) (T '()) (K K)) ; Look in subsequent pseudorotations. (let ((E (car H)) (H (cdr H))) (if (member E T EQ?) ; Skip pseudorotation if it's car already was car of a previous one. (pseudo-rotate H (cons E T) K) (let ((M (/ (* N (count-occurrences E L EQ?)) (length L ; M is the nr of rearrangements of (append H T) ; computed by means of a recurrent relation. (if (< K M) ; The rearrangement is in this pseudorotation. (rearrange (append H T) K M (cons E result)) ; The rearrangement is not in this pseudorotation. ; Look in the following pseudorotation, but decrease K by the ; nr of rearrangements of the skipped pseudorotation. (pseudo-rotate H (cons E T) (- K M (define (nr-of-rearrangements L EQ?) ...) (define (count-occcurrences E L EQ?) ...) > -Original Message- > From: dev [mailto:dev-boun...@racket-lang.org] On Behalf Of > Asumu Takikawa > Sent: lunes, 23 de junio de 2014 7:35 > To: Kevin Forchione > Cc: dev@racket-lang.org > Subject: Re: [racket-dev] 2htdp/image Feature Suggestion > > On 2014-06-22 20:27:21 -0700, Kevin Forchione wrote: > >Thanks! Is there any documentation or guide on which > *styles* to prefer in > >writing Racket code? I find myself scratching my head at > times in these > >matters! > > In recent Racket distributions and online docs there's now a style > manual: > > http://docs.racket-lang.org/style/index.html > > Cheers, > Asumu > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 23, 2014, at 12:03 PM, Kevin Forchione wrote: > I’ve only skimmed the manual so far, but see it doesn’t address one of my > questions: whether and when to favor functions such as first/rest/empty?, > etc., over the Lisp-y car/cdr/null?, etc. I have noticed that some of these > functions are list-specific and perhaps they’re to be preferred when working > specifically with lists? Whenever naturally possible. (In syntax, you can't use them.) _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 22, 2014, at 10:35 PM, Asumu Takikawa wrote: > On 2014-06-22 20:27:21 -0700, Kevin Forchione wrote: >> Thanks! Is there any documentation or guide on which *styles* to prefer in >> writing Racket code? I find myself scratching my head at times in these >> matters! > > In recent Racket distributions and online docs there's now a style > manual: > > http://docs.racket-lang.org/style/index.html > > Cheers, > Asumu That’s just what the doctor ordered :) I’ve only skimmed the manual so far, but see it doesn’t address one of my questions: whether and when to favor functions such as first/rest/empty?, etc., over the Lisp-y car/cdr/null?, etc. I have noticed that some of these functions are list-specific and perhaps they’re to be preferred when working specifically with lists? -Kevin_ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On 2014-06-22 20:27:21 -0700, Kevin Forchione wrote: >Thanks! Is there any documentation or guide on which *styles* to prefer in >writing Racket code? I find myself scratching my head at times in these >matters! In recent Racket distributions and online docs there's now a style manual: http://docs.racket-lang.org/style/index.html Cheers, Asumu _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
Thanks! I've added these two functions. Robby On Sun, Jun 22, 2014 at 12:26 PM, Kevin Forchione wrote: > > On Jun 21, 2014, at 5:02 PM, Robby Findler > wrote: > > What do you think about a variant on center-crop called crop/align > that accepts a width, a height, an image, and an x-place and a > y-place? > > That would seem to fit better into the library the way it's currently > constructed. > > For working around the frame issue, how about just a color-frame > function that controls the color for now? > > > I agree! That’s even better in terms of use and simplicity. > > -Kevin _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 21, 2014, at 3:22 PM, Matthias Felleisen wrote: > > Thanks. We will need to figure out how to accommodate keywords in a > teachpack. > > In the meantime, write frame like this: > > (define (frame-2 img > #:frame-color (frame-color 'black) > #:background-color (background-color 'transparent) > #:frame-offset (frame-offset 0) > #:frame-x-offset (frame-x-offset frame-offset) > #:frame-y-offset (frame-y-offset frame-offset)) > (define width (+ (image-width img) frame-x-offset)) > (define height (+ (image-height img) frame-y-offset)) > (overlay (rectangle width height 'outline frame-color) > (center-crop width height img) > (rectangle width height 'solid background-color))) > > Prefer define over let. -- Matthias > Thanks! Is there any documentation or guide on which “styles” to prefer in writing Racket code? I find myself scratching my head at times in these matters! -Kevin_ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
On Jun 21, 2014, at 5:02 PM, Robby Findler wrote: > What do you think about a variant on center-crop called crop/align > that accepts a width, a height, an image, and an x-place and a > y-place? > > That would seem to fit better into the library the way it's currently > constructed. > > For working around the frame issue, how about just a color-frame > function that controls the color for now? I agree! That’s even better in terms of use and simplicity. -Kevin_ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
What do you think about a variant on center-crop called crop/align that accepts a width, a height, an image, and an x-place and a y-place? That would seem to fit better into the library the way it's currently constructed. For working around the frame issue, how about just a color-frame function that controls the color for now? Robby Robby On Sat, Jun 21, 2014 at 1:42 PM, Kevin Forchione wrote: > Hi guys, > I’ve been working with 2htdp/image and been struck by its monitor-oriented > coordinate system and its image-centric perspective, both of which have > proven a rich bed for new tools. I’ve found these two functions have been > useful to me and might be useful for others. I’ve particularly found them > useful as my racket sessions use the “white on black” color schemes, and with > my eyesight a pixel’s contrast makes a difference. > > The center-crop function facilitates the image-cntric perspective of the > library by centering the cropping rectangle on the image center. The frame > function replaces the library’s existing function with one that does the same > thing, but also provides parameters for setting the pixel frame coloring, > background coloring within the frame, and x/y offsets that work with > center-crop to expand or shrink the framing of the image. > > ;; center-crop: width height image -> image? > ;; crops image in a rectangle of width x height whose center is image center. > (define (center-crop width height img) > (crop (- (quotient (image-width img) 2) (quotient width 2)) > (- (quotient (image-height img) 2) (quotient height 2)) > width > height > img)) > > ;; frame: image frame-option ... -> image? > ;; Returns an image just like image, except with a frame-color'd, single > pixel frame > ;; around the bounding box of the image. The background-color indicates the > color > ;; inside the frame over which the image is laid. If an offset is provided it > ;; indicates a center-crop in that dimension. A positive value extends the > crop > ;; beyond the image bounding box, a negative value center-crops the image > within > ;; the bounding box. > (define (frame img >#:frame-color (frame-color 'black) >#:background-color (background-color 'transparent) >#:frame-offset (frame-offset 0) >#:frame-x-offset (frame-x-offset frame-offset) >#:frame-y-offset (frame-y-offset frame-offset)) > (let ([width (+ (image-width img) frame-x-offset)] > [height (+ (image-height img) frame-y-offset)]) > (overlay (rectangle width height 'outline frame-color) > (center-crop width height img) > (rectangle width height 'solid background-color > > -Kevin > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] 2htdp/image Feature Suggestion
Thanks. We will need to figure out how to accommodate keywords in a teachpack. In the meantime, write frame like this: (define (frame-2 img #:frame-color (frame-color 'black) #:background-color (background-color 'transparent) #:frame-offset (frame-offset 0) #:frame-x-offset (frame-x-offset frame-offset) #:frame-y-offset (frame-y-offset frame-offset)) (define width (+ (image-width img) frame-x-offset)) (define height (+ (image-height img) frame-y-offset)) (overlay (rectangle width height 'outline frame-color) (center-crop width height img) (rectangle width height 'solid background-color))) Prefer define over let. -- Matthias On Jun 21, 2014, at 2:42 PM, Kevin Forchione wrote: > Hi guys, > I’ve been working with 2htdp/image and been struck by its monitor-oriented > coordinate system and its image-centric perspective, both of which have > proven a rich bed for new tools. I’ve found these two functions have been > useful to me and might be useful for others. I’ve particularly found them > useful as my racket sessions use the “white on black” color schemes, and with > my eyesight a pixel’s contrast makes a difference. > > The center-crop function facilitates the image-cntric perspective of the > library by centering the cropping rectangle on the image center. The frame > function replaces the library’s existing function with one that does the same > thing, but also provides parameters for setting the pixel frame coloring, > background coloring within the frame, and x/y offsets that work with > center-crop to expand or shrink the framing of the image. > > ;; center-crop: width height image -> image? > ;; crops image in a rectangle of width x height whose center is image center. > (define (center-crop width height img) > (crop (- (quotient (image-width img) 2) (quotient width 2)) >(- (quotient (image-height img) 2) (quotient height 2)) >width >height >img)) > > ;; frame: image frame-option ... -> image? > ;; Returns an image just like image, except with a frame-color'd, single > pixel frame > ;; around the bounding box of the image. The background-color indicates the > color > ;; inside the frame over which the image is laid. If an offset is provided it > ;; indicates a center-crop in that dimension. A positive value extends the > crop > ;; beyond the image bounding box, a negative value center-crops the image > within > ;; the bounding box. > (define (frame img > #:frame-color (frame-color 'black) > #:background-color (background-color 'transparent) > #:frame-offset (frame-offset 0) > #:frame-x-offset (frame-x-offset frame-offset) > #:frame-y-offset (frame-y-offset frame-offset)) > (let ([width (+ (image-width img) frame-x-offset)] >[height (+ (image-height img) frame-y-offset)]) >(overlay (rectangle width height 'outline frame-color) > (center-crop width height img) > (rectangle width height 'solid background-color > > -Kevin > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
[racket-dev] 2htdp/image Feature Suggestion
Hi guys, I’ve been working with 2htdp/image and been struck by its monitor-oriented coordinate system and its image-centric perspective, both of which have proven a rich bed for new tools. I’ve found these two functions have been useful to me and might be useful for others. I’ve particularly found them useful as my racket sessions use the “white on black” color schemes, and with my eyesight a pixel’s contrast makes a difference. The center-crop function facilitates the image-cntric perspective of the library by centering the cropping rectangle on the image center. The frame function replaces the library’s existing function with one that does the same thing, but also provides parameters for setting the pixel frame coloring, background coloring within the frame, and x/y offsets that work with center-crop to expand or shrink the framing of the image. ;; center-crop: width height image -> image? ;; crops image in a rectangle of width x height whose center is image center. (define (center-crop width height img) (crop (- (quotient (image-width img) 2) (quotient width 2)) (- (quotient (image-height img) 2) (quotient height 2)) width height img)) ;; frame: image frame-option ... -> image? ;; Returns an image just like image, except with a frame-color'd, single pixel frame ;; around the bounding box of the image. The background-color indicates the color ;; inside the frame over which the image is laid. If an offset is provided it ;; indicates a center-crop in that dimension. A positive value extends the crop ;; beyond the image bounding box, a negative value center-crops the image within ;; the bounding box. (define (frame img #:frame-color (frame-color 'black) #:background-color (background-color 'transparent) #:frame-offset (frame-offset 0) #:frame-x-offset (frame-x-offset frame-offset) #:frame-y-offset (frame-y-offset frame-offset)) (let ([width (+ (image-width img) frame-x-offset)] [height (+ (image-height img) frame-y-offset)]) (overlay (rectangle width height 'outline frame-color) (center-crop width height img) (rectangle width height 'solid background-color -Kevin _ Racket Developers list: http://lists.racket-lang.org/dev