Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
LilyPond wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Color Gradient using Postscript
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Lilypond has no way of creating color gradients. This markup function duplicates the path markup, converts it to postscript and uses postscript's rectclip to crop the duplicates, then colors each one a step to create a smooth gradient. The variable 'res' defines the resolution of the gradient. A larger number here makes the gradient smoother, but takes longer to compile. Bigger gradients and larger paths will need a larger resolution to look smooth. It has NOT been tested with relative path commands. <lilypond version="2.24.0"> #(define path->ps (lambda (cmds) (apply string-append (map (lambda (f) (string-append (apply string-append (append (map (lambda (e) (string-append (number->string (exact->inexact e)) " ")) (cdr f)) (cons (symbol->string (car f)) '()))) " ")) cmds)))) #(define-markup-command (gradient-path layout props startr startg startb endr endg endb path res) (number? number? number? number? number? number? list? integer?) (let* ((ps (path->ps path)) (markup-test (ly:text-interface::interpret-markup layout props (markup #:line (#:path 0.1 path)))) (xextnt (ly:stencil-extent markup-test X)) (yextnt (ly:stencil-extent markup-test Y)) (xlen (- (cdr xextnt) (car xextnt))) (ylen (- (cdr yextnt) (car yextnt))) (xstep (/ xlen res)) (rshadestep (/ (- endr startr) res)) (gshadestep (/ (- endg startg) res)) (bshadestep (/ (- endb startb) res)) (xlist (iota res (car xextnt) xstep)) (xextls (map (lambda (e) (cons e xlen)) xlist)) (rshadelist (iota res startr rshadestep)) (gshadelist (iota res startg gshadestep)) (bshadelist (iota res startb bshadestep)) (mkps (map (lambda (a) (markup #:line (#:postscript (string-append (number->string (exact->inexact (car a))) " -1000 " (number->string (exact->inexact (- (cdr a) (car a)))) " 2000 rectclip " ps " fill")))) xextls)) (colored (map (lambda (a r g b) (markup #:line (#:with-color (list r g b) a))) (reverse mkps) rshadelist gshadelist bshadelist)) (finalmkp (reduce make-combine-markup empty-markup colored))) (interpret-markup layout props finalmkp))) samplePath = #'((moveto 0 0) (lineto -10 10) (lineto 10 10) (lineto 10 -10) (curveto -50 -50 -50 50 -10 0) (closepath)) \markup \translate #'(40 . -20) %% \with-dimensions is needed to return a nice image in LSR \with-dimensions #'(-40 . 10) #'(-20 . 15) { \gradient-path #1 #0 #0 #0 #0 #1 #samplePath #100 } </lilypond> [[Category:Non-music]] [[Category:Symbols and glyphs]] [[Category:Paper and layout]] [[Category:Tweaks and overrides]] [[Category:Syntax and expressions]]
Summary:
Please note that all contributions to LilyPond wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Meta:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Color Gradient using Postscript
Add topic