2015-08-12 0:22 GMT+02:00 Thomas Morley <thomasmorle...@gmail.com>: > Hi Paul, > > 2015-08-11 17:36 GMT+02:00 Paul Morris <p...@paulwmorris.com>: > >> >> Nice! Much simpler. I’ve updated the LSR snippet with your simpler code. >> I also changed it so that the circle is moved so it is centered on the >> square, which helps show the need for the function (as opposed to >> centered-stencil). >> >> http://lsr.di.unimi.it/LSR/Item?id=1009 >> >> Let me know if there are any further revisions to make. > > I'm still not happy with the example, because the second stencil, the > circle, is centered already. > Below, you could replace the line between the ;;;; with 'stil-b' and > would still get the same output. > > #(define (center-stencil-on-stencil axis stil-a stil-b) > "Return a copy of stencil @var{stil-b} that has been > moved so it is centered on stencil @var{stil-a} on > @var{axis}. @var{axis} is 0 for X axis, 1 for Y axis." > (ly:stencil-translate-axis > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > (ly:stencil-aligned-to stil-b axis CENTER) > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > (interval-center (ly:stencil-extent stil-a axis)) > axis)) > > The advantage of this coding is that it will work, whether the stencil > is centered or not!! > Therefore I'd extent the example: > > square = > #(make-connected-path-stencil > '((0 0) (4 0) (4 4) (0 4) (0 0)) > 0.4 1 1 #f #f) > > green-square = > #(stencil-with-color (make-filled-box-stencil '(0 . 2) '(0 . 2)) green) > > circle = > #(stencil-with-color (make-circle-stencil 1 0.3 #f) green) > > \markup \line { > \stencil #(ly:stencil-add square circle) > " " > \stencil #(ly:stencil-add square (center-stencil-on-stencil X square circle)) > " " > \stencil #(ly:stencil-add square (center-stencil-on-stencil Y square circle)) > " " > \stencil #(ly:stencil-add > square > (center-stencil-on-stencil Y square > (center-stencil-on-stencil X square circle))) > } > > \markup \line { > \stencil #(ly:stencil-add square green-square) > " " > \stencil #(ly:stencil-add square (center-stencil-on-stencil X square > green-square)) > " " > \stencil #(ly:stencil-add square (center-stencil-on-stencil Y square > green-square)) > " " > \stencil #(ly:stencil-add > square > (center-stencil-on-stencil Y square > (center-stencil-on-stencil X square green-square))) > } > > > As a thought I extended the coding to get the possibility of a > centered stencil in both directions in one go: > > > #(define (center-stencil-on-stencil axis stil-a stil-b) > "Return a copy of stencil @var{stil-b} that has been > moved so it is centered on stencil @var{stil-a} on > @var{axis}. @var{axis} is 0 for X axis, 1 for Y axis. > @var{axis} may be set @code{#t}, moving the new stencil:
read: in both directions > in directions" > (if (and (boolean? axis) axis) > (ly:stencil-translate > (centered-stencil stil-b) > (cons > (interval-center (ly:stencil-extent stil-a X)) > (interval-center (ly:stencil-extent stil-a Y)))) > (ly:stencil-translate-axis > (ly:stencil-aligned-to stil-b axis CENTER) > (interval-center (ly:stencil-extent stil-a axis)) > axis))) > > test = > #(define-scheme-function (parser location stil-1 stil-2) > (ly:stencil? ly:stencil?) > #{ > \markup > \override #'(word-space . 3) > \line { > \stencil #(ly:stencil-add stil-1 stil-2) > \stencil #(ly:stencil-add stil-1 > (center-stencil-on-stencil X stil-1 stil-2)) > \stencil #(ly:stencil-add stil-1 > (center-stencil-on-stencil Y stil-1 stil-2)) > \stencil #(ly:stencil-add stil-1 > (center-stencil-on-stencil #t stil-1 stil-2)) > } > #}) > > square = > #(make-connected-path-stencil > '((0 0) (4 0) (4 4) (0 4) (0 0)) > 0.4 1 1 #f #f) > > green-square = > #(stencil-with-color (make-filled-box-stencil '(0 . 2) '(0 . 2)) green) > > circle = > #(stencil-with-color (make-circle-stencil 1 0.3 #f) green) > > \test #square #circle > \test #square #green-square > > > Though, it's probably overdone. > What do you think? > > > Cheers, > Harm _______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user