2013/9/3 Rachael Thomas Carlson <rachael.thomas.carl...@gmail.com>:
> Hello All:
>
> I am attempting to draw a hexagon with a number inside of it using markup.
>
> The attached png is essentially what I am attempting.  This is to be used in
> a TabStaff.  I am not worried about the whiteout = ##f in the png.  I just
> simply can't seem to figure out how to create a hexagon such as in the png.
> Though, again, it would be optimal to create this within a markup
> environment.
>
> I am able to modify the TabNoteHead stencil.  That is not the problem. I
> just need to figure out how to create a hexagon with a number inside of it
> using markup.
>
> Any ideas?
>
> Rachael



Hi Rachael,

Torsten once posted the code below in the german LilyPond-forum

\version "2.14.2"

#(define-markup-command (draw-n-agon layout props corners radius arg)
  (number? number? markup?)
  #:category graphic
  #:properties ((thickness 1))
  (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
               thickness))
         (alpha-step (if (= corners 0) 99 (/ (* 2 PI) (abs corners))))
         (alpha-start (if (>= radius 0) (/ alpha-step 2) 0))
         (polypoints
          (let loop ((alpha alpha-start))
            (if (> alpha (* 2 PI))
                '()
                (cons (* (abs radius) (sin alpha)) (cons (- 0 (* (abs
radius) (cos alpha)))
                   (loop (+ alpha alpha-step)))))))
         (m (interpret-markup layout props arg))
         (x-ext (ly:stencil-extent m X))
         (y-ext (ly:stencil-extent m Y)))
    (ly:stencil-add m
      (ly:stencil-translate
         (if (equal? polypoints '())
            (ly:make-stencil (list 'circle radius th #f))
            (ly:make-stencil `(polygon ',polypoints  ,th #f)))
         (cons (/ (cdr x-ext) 2) (/ (cdr y-ext) 2))))))


% TEST:

\header { tagline = ##f }
\paper { ragged-last-bottom = ##f }

\markup \draw-n-agon #100 #-4 "3"

\relative c' {
  \override Score.RehearsalMark #'padding = #4

% gleichseitige Dreiecke
  s1  \mark \markup \draw-n-agon #3 #4 "3"
  s  \mark \markup \draw-n-agon #3 #4 "33"
  s  \mark \markup \draw-n-agon #3 #-4 "3"
  s  \mark \markup \draw-n-agon #3 #-4 "33"
  s  \mark \markup \draw-n-agon #3 #4 \draw-n-agon #3 #-4 "3"
  s  \mark \markup \draw-n-agon #3 #4 \draw-n-agon #3 #-4 "33"
  s \break

% Quadrate
  s  \mark \markup \draw-n-agon #4 #3 "4"
  s  \mark \markup \draw-n-agon #4 #3 "44"
  s  \mark \markup \draw-n-agon #4 #-3 "4"
  s  \mark \markup \draw-n-agon #4 #-3 "44"
  s  \mark \markup \draw-n-agon #4 #3 \draw-n-agon #4 #-3 "4"
  s  \mark \markup \draw-n-agon #4 #3 \draw-n-agon #4 #-3 "44"
  s \break

% gleichseitige Pentagone
  s  \mark \markup \draw-n-agon #5 #2.5 "5"
  s  \mark \markup \draw-n-agon #5 #2.5 "55"
  s  \mark \markup \draw-n-agon #5 #-2.5 "5"
  s  \mark \markup \draw-n-agon #5 #-2.5 "55"
  s  \mark \markup \draw-n-agon #5 #2.5 \draw-n-agon #5 #-2.5 "5"
  s  \mark \markup \draw-n-agon #5 #2.5 \draw-n-agon #5 #-2.5 "55"
  s  \break

% gleichseitige Hexagone
  s  \mark \markup \draw-n-agon #6 #2.5 "6"
  s  \mark \markup \draw-n-agon #6 #2.5 "66"
  s  \mark \markup \draw-n-agon #6 #-2.5 "6"
  s  \mark \markup \draw-n-agon #6 #-2.5 "66"
  s  \break

% gleichseitige Heptagone
  s  \mark \markup \draw-n-agon #7 #2.5 "7"
  s  \mark \markup \draw-n-agon #7 #2.5 "77"
  s  \mark \markup \draw-n-agon #7 #-2.5 "7"
  s  \mark \markup \draw-n-agon #7 #-2.5 "77"
  s  \break

% gleichseitige Oktagone
  s  \mark \markup \draw-n-agon #8 #2.5 "8"
  s  \mark \markup \draw-n-agon #8 #2.5 "88"
  s  \mark \markup \draw-n-agon #8 #-2.5 "8"
  s  \mark \markup \draw-n-agon #8 #-2.5 "88"
  s  \break

% Kreise
  s  \mark \markup \draw-n-agon #0 #2.5 "0"
  s  \mark \markup \draw-n-agon #0 #2.5 "00"

% Kombinationen Quadrat und Dreieck
  s  \mark \markup \draw-n-agon #4 #2.5 \draw-n-agon #3 #5.5 "9"
  s  \mark \markup \draw-n-agon #4 #2.5 \draw-n-agon #3 #5.5 "99"
  s  \mark \markup \draw-n-agon #4 #5 \lower #1.5 \draw-n-agon #3 #3.5 "9"
  s  \mark \markup \draw-n-agon #4 #5 \lower #1.5 \draw-n-agon #3 #3.5 "99"
  s  \break

% Kombinationen Dreieck und Kreis
  s  \mark \markup \draw-n-agon #0 #1.9 \draw-n-agon #3 #4.5 "9"
  s  \mark \markup \draw-n-agon #0 #1.9 \draw-n-agon #3 #4.5 "99"
  s  \mark \markup \draw-n-agon #0 #2.5 \draw-n-agon #3 #3.5 "9"
  s  \mark \markup \draw-n-agon #0 #2.5 \draw-n-agon #3 #3.5 "99"
  s  \mark \markup \draw-n-agon #0 #3.5 \draw-n-agon #3 #3.5 "9"
  s  \mark \markup \draw-n-agon #0 #3.5 \draw-n-agon #3 #3.5 "99"
  s  \mark \markup \draw-n-agon #0 #4 \draw-n-agon #3 #3.5 "9"
  s  \mark \markup \draw-n-agon #0 #4 \draw-n-agon #3 #3.5 "99"
  s  \break

% Kombinationen Quadrat und Kreis
  s  \mark \markup \draw-n-agon #0 #2 \draw-n-agon #4 #4 "9"
  s  \mark \markup \draw-n-agon #0 #2 \draw-n-agon #4 #4 "99"
  s  \mark \markup \draw-n-agon #0 #2.5 \draw-n-agon #4 #3 "9"
  s  \mark \markup \draw-n-agon #0 #2.5 \draw-n-agon #4 #3 "99"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #4 #3 "9"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #4 #3 "99"
  s  \mark \markup \draw-n-agon #0 #3.5 \draw-n-agon #4 #3 "9"
  s  \mark \markup \draw-n-agon #0 #3.5 \draw-n-agon #4 #3 "99"
  s  \break

% Kombinationen Pentagon und Kreis
  s  \mark \markup \draw-n-agon #0 #2 \draw-n-agon #5 #3.5 "9"
  s  \mark \markup \draw-n-agon #0 #2 \draw-n-agon #5 #3.5 "99"
  s  \mark \markup \draw-n-agon #0 #2.4 \draw-n-agon #5 #3 "9"
  s  \mark \markup \draw-n-agon #0 #2.4 \draw-n-agon #5 #3 "99"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #5 #3 "9"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #5 #3 "99"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #5 #2.5 "9"
  s  \mark \markup \draw-n-agon #0 #3 \draw-n-agon #5 #2.5 "99"
  s  \break



% lustige Zwischenstufen
  s  \mark \markup \draw-n-agon #2.7 #3 "A"
  s  \mark \markup \draw-n-agon #2.8 #-3 "B"
  s  \mark \markup \draw-n-agon #3.2 #-3 "C"
  s  \mark \markup \draw-n-agon #4.2 #3 "D"
  s  \mark \markup \draw-n-agon #4.6 #3 "E"
  s  \mark \markup \draw-n-agon #5.4 #3 "F"
  s  \mark \markup \override #'(thickness . 7) \draw-n-agon #3 #3
\raise #0.5 \bold \sans "!"
  \bar "|."

}


Hope it's still working (didn't test it with newer versions)


Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to