soegaard / metapict Goto Github PK
View Code? Open in Web Editor NEWA graphics library for producing Racket picts in a MetaPost/TikZ style.
Home Page: http://soegaard.github.io/metapict/
A graphics library for producing Racket picts in a MetaPost/TikZ style.
Home Page: http://soegaard.github.io/metapict/
MetaPict ======== A graphics library for producing beautiful pictures using Racket. MetaPict programs mimic the MetaPost/TikZ style known in LaTeX circles. The documentation is available here: https://soegaard.github.io/docs/metapict/metapict.html Please report any errors - including grammatical and spelling errors. I'd like to have a collection of user-contributed examples, so consider sharing any MetaPict programs you write. Installation ============ The easiest way to install MetaPict is to use the Package Manager in DrRacket. After opening the Package Manager (from the "File" menu) click the "Available from Catalog" tab. That tab lists all packages available from pkgs.racket-lang.org. Now enter metapict in the filter. The MetaPict package is now easy to spot. Click the line with metapict and then click the "Install" button. You will see that the package manager downloads metapict, compiles it, and, generates the documentation. The last bit - generating the documentation - takes a while for MetaPict due to the large amount of images used in the examples. The documentation builder will give a few warnings similar to: raco setup: WARNING: undefined tag in <pkgs>/metapict/metapict/scribblings/metapict.scrbl: raco setup: ((lib "metapict/main.rkt") --) ... raco setup: ((lib "metapict/main.rkt") above) ... These are harmless - they mean that I need improve the documentation at some point. Any other errors, I'd like to hear about. /soegaard Examples ======== Old note (is this still needed?): Run the examples directly in DrRacket, but do this first: - In the menu "Language" choose the item "Choose Language" - Click "Show Details" - Remove the tick in "Populate Compiled Directories"
Introduce textsize and textscale.
And textcolor ?
(with-window (window -2 2 -2 2)
(draw (curve (path: (pt -1 0) down .. (pt 1 0) .. down (pt -1 1) .. (pt -1 0)))))
https://docs.racket-lang.org/metapict/index.html#%28part._example-rgb-triangle%29
(require file/convertible racket/draw racket/gui)
cannot instantiate `racket/gui/base' a second time in the
same process
and
brushgradient: arity mismatch;
Check whether MetaPost calculates the same curve.
(curve (pt u 0) up .. (pt (- u) 0) down -- cycle)
After installing metapick through the racket package manager, I get
raco setup: --- summary of errors ---
raco setup: error: during making for <pkgs>/metapict/metapict
raco setup: .racket/7.1/pkgs/metapict/metapict/geometry.rkt:334:18: read-syntax: expected `)` to close `(` on line 198, found instead `]`
raco setup: compiling: <pkgs>/metapict/metapict/geometry.rkt
raco setup: error: during making for <pkgs>/metapict/metapict
raco setup: open-input-file: cannot open module file
raco setup: module path: /home/blerner/.racket/7.1/pkgs/metapict/metapict/cubic-equation.rkt
raco setup: path: /home/blerner/.racket/7.1/pkgs/metapict/metapict/cubic-equation.rkt
raco setup: system error: no such file or directory; rktio_err=3
raco setup: compiling: <pkgs>/metapict/metapict/hom.rkt
drracket install: packages installed, although setup reported errors
I'm using Racket 7.1, fwiw, but these don't seem to be Racket-version-specific...
I was wondering if there was a way to create objects from existing SVG images, or any existing converter that would allow me to create new functions from SVG files?
For reference, I'm trying to see if MetaPict can be useful for creating system architecture diagrams, particularly using the AWS Architecture Icons, which they provide in SVG format.
I've only just started looking at metapict and racket, and its been many years since I wrote any lisp code at all, so while I'm willing to dive in and try make this work myself, I wanted to check if there were any existing ways before I wasted my time
Link to knot.cc in Asymptote that show how to compute a path.
Fix draw-box-and-pointer-diagram to handle this case.
(margin
5 (draw (shared ([a (cons 1 a)]
[b (cons c a)]
[c (list 2)]
[d (list a b c d)])
(draw-box-and-pointer-diagram
d #:labels (hash a "a" b "b" c "c" d "d")))))
The following snippet has some bad window dimensions
#lang racket
(require metapict)
(with-window (window 100 100 100 100)
(draw (curve origo -- (pt 10 10))))
Running it gives /: division by zero
.
The build log still runs a few files as tests.
Fix it.
Today when I tried to upgrade metapict using raco pkg update metapict
, I got the following error:
raco setup: error: during making for <pkgs>/metapict/metapict/examples
raco setup: open-input-file: cannot open module file
raco setup: module path: /home/hadi/.racket/7.5/pkgs/metapict/metapict/crop.rkt
raco setup: path: /home/hadi/.racket/7.5/pkgs/metapict/metapict/crop.rkt
raco setup: system error: no such file or directory; rktio_err=3
raco setup: compiling: <pkgs>/metapict/metapict/examples/racket-logo.rkt
Hello !
Great project, must definitely use it someday!
Not sure this is worth an issue, but I checked your demo at https://soegaard.github.io/blog/metapict/, and noticed the following typo: you feel the overlap of the two arrow heads is TWO large
-> you feel the overlap of the two arrow heads is TOO large
quick question, can you draw arrows halfway a path?
Can you draw something similar to this? This would be super useful.
vphph-t2.pdf
(intersection-point unitcircle (curve origo -- (pt* 100 (pt 1 1))))
(pt 0.7071067811865506 0.7071067811865446)
(intersection-point unitcircle (curve origo -- (pt* 100 (pt 1 1))))
(pt 0.7071067811865506 0.7071067811865446)
(time (intersection-point unitcircle (curve origo -- (pt* 10 (pt 1 1)))))
cpu time: 5 real time: 5 gc time: 0
(pt 0.7071067811865479 0.707106781186547)
(time (intersection-point unitcircle (curve origo -- (pt* 100 (pt 1 1)))))
cpu time: 39 real time: 61 gc time: 0
(pt 0.7071067811865506 0.7071067811865446)
(time (intersection-point unitcircle (curve origo -- (pt* 1000 (pt 1 1)))))
cpu time: 316 real time: 331 gc time: 56
(pt 0.707106781186573 0.7071067811865221)
(time (intersection-point unitcircle (curve origo -- (pt* 10000 (pt 1 1)))))
cpu time: 3581 real time: 3769 gc time: 551
(pt 0.7071067811870169 0.7071067811860783)
(time (intersection-point unitcircle (curve origo -- (pt* 100000 (pt 1 1)))))
cpu time: 28672 real time: 30157 gc time: 4298
(pt 0.707106781189409 0.707106781183686)
See 1 and 2 below:
$ racket --version
Welcome to Racket v6.1.1.2.
$ git clone [email protected]:soegaard/metapict.git
Cloning into 'metapict'...
remote: Counting objects: 1147, done.
remote: Total 1147 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1147/1147), 2.26 MiB | 2.14 MiB/s, done.
Resolving deltas: 100% (737/737), done.
Checking connectivity... done.
$ raco pkg install --link metapict
raco setup: version: 6.1.1.2 [3m]
raco setup: installation name: development
raco setup: variants: 3m
raco setup: main collects: /Users/greg/src/plt/racket/racket/collects
raco setup: collects paths:
raco setup: /Users/greg/src/plt/racket/racket/collects
raco setup: main pkgs: /Users/greg/src/plt/racket/racket/share/pkgs
raco setup: pkgs paths:
raco setup: /Users/greg/src/plt/racket/racket/share/pkgs
raco setup: /Users/greg/src/plt/racket/racket/share/devel-pkgs
raco setup: /Users/greg/Library/Racket/development/pkgs
raco setup: links files:
raco setup: /Users/greg/src/plt/racket/racket/share/links.rktd
raco setup: /Users/greg/src/plt/racket/racket/share/devel-pkgs/links.rktd
raco setup: /Users/greg/Library/Racket/development/links.rktd
raco setup: main docs: /Users/greg/src/plt/racket/racket/doc
raco setup: --- updating info-domain tables ---
raco setup: updating: /Users/greg/src/plt/racket/racket/share/info-cache.rktd
raco setup: --- pre-installing collections ---
raco setup: --- installing foreign libraries ---
raco setup: --- installing shared files ---
raco setup: --- compiling collections ---
raco setup: --- parallel build using 8 jobs ---
raco setup: 7 making: <pkgs>/metapict/metapict
raco setup: 6 making: <pkgs>/racket-index/scribblings/main
raco setup: 6 making: <pkgs>/racket-index/scribblings/main/private
raco setup: 6 making: <pkgs>/racket-index/scribblings/main/user
raco setup: 7 making: <pkgs>/metapict/metapict/debug
raco setup: 7 making: <pkgs>/metapict/metapict/debug-foo
raco setup: 7 making: <pkgs>/metapict/metapict/debug-foo/foo
raco setup: 7 making: <pkgs>/metapict/metapict/examples
raco setup: 7 making: <pkgs>/metapict/metapict/extras
raco setup: 7 making: <pkgs>/metapict/metapict/metapost-examples
raco setup: 7 making: <pkgs>/metapict/metapict/scribblings
raco setup: 7 making: <pkgs>/metapict/metapict/texts
raco setup: --- creating launchers ---
raco setup: --- installing man pages ---
raco setup: --- building documentation ---
raco setup: 1 running: <pkgs>/metapict/metapict/scribblings/metapict.scrbl
raco setup: WARNING: undefined tag in <pkgs>/metapict/metapict/scribblings/metapict.scrbl:
raco setup: (mod-path "metapict/pict")
raco setup: (mod-path "metapict/draw")
raco setup: ((lib "metapict/main.rkt") --)
raco setup: ((lib "metapict/main.rkt") -pi/2)
raco setup: ((lib "metapict/main.rkt") ..)
raco setup: ((lib "metapict/main.rkt") ...)
raco setup: ((lib "metapict/main.rkt") above)
raco setup: ((lib "metapict/main.rkt") ahlength)
raco setup: ((lib "metapict/main.rkt") beside)
raco setup: ((lib "metapict/main.rkt") beside*)
raco setup: ((lib "metapict/main.rkt") bot)
raco setup: ((lib "metapict/main.rkt") circle)
raco setup: ((lib "metapict/main.rkt") curve)
raco setup: ((lib "metapict/main.rkt") curve-pict-height)
raco setup: ((lib "metapict/main.rkt") curve-pict-width)
raco setup: ((lib "metapict/main.rkt") curve-pict-window)
raco setup: ((lib "metapict/main.rkt") curve-reverse)
raco setup: ((lib "metapict/main.rkt") dot-label)
raco setup: ((lib "metapict/main.rkt") draw*)
raco setup: ((lib "metapict/main.rkt") draw-arrow)
raco setup: ((lib "metapict/main.rkt") draw-dot)
raco setup: ((lib "metapict/main.rkt") filldraw)
raco setup: ((lib "metapict/main.rkt") for/draw)
raco setup: ((lib "metapict/main.rkt") join)
raco setup: ((lib "metapict/main.rkt") join?)
raco setup: ((lib "metapict/main.rkt") label)
raco setup: ((lib "metapict/main.rkt") label->pict)
raco setup: ((lib "metapict/main.rkt") label-bot)
raco setup: ((lib "metapict/main.rkt") path?)
raco setup: ((lib "metapict/main.rkt") pi/2)
raco setup: ((lib "metapict/main.rkt") px)
raco setup: ((lib "metapict/main.rkt") scaled)
raco setup: ((lib "metapict/main.rkt") set-curve-pict-size)
raco setup: ((lib "metapict/main.rkt") top)
raco setup: ((lib "metapict/main.rkt") trans?)
raco setup: ((lib "metapict/main.rkt") unitcircle)
raco setup: ((lib "metapict/main.rkt") unitsquare)
raco setup: ((lib "metapict/main.rkt") window)
raco setup: ((lib "metapict/main.rkt") with-window)
raco setup: 4 rendering: <pkgs>/metapict/metapict/scribblings/metapict.scrbl
raco setup: 3 rendering: <pkgs>/racket-index/scribblings/main/release.scrbl
raco setup: 2 rendering: <pkgs>/racket-index/scribblings/main/start.scrbl
raco setup: 1 rendering: <pkgs>/racket-index/scribblings/main/local-redirect.scrbl
raco setup: 0 rendering: <pkgs>/racket-index/scribblings/main/search.scrbl
make-script: unexpected value rendered: '((font ((class "badlink")) (span ((class "indexlink")) (span ((class "RktModLink")) (span ((class "RktSym")) "metapict/draw")))))
context...:
/Users/greg/src/plt/racket/pkgs/racket-pkgs/racket-index/scribblings/main/private/make-search.rkt:116:4: for-loop
/Users/greg/src/plt/racket/pkgs/racket-pkgs/racket-index/scribblings/main/private/make-search.rkt:64:0: make-script
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/base-render.rkt:888:4: render-content method in render%
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1462:4: render-plain-content method in ...bble/html-render.rkt:267:2
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/base-render.rkt:888:4: render-content method in render%
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1171:4: do-render-paragraph method in ...bble/html-render.rkt:267:2
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1199:4: render-intrapara-block method in ...bble/html-render.rkt:267:2
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/base-render.rkt:834:4: render-compound-paragraph method in render%
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1702:4: render-compound-paragraph method in ...bble/html-render.rkt:267:2
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1158:6: loop
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:1090:4: render-part-content method in ...bble/html-render.rkt:267:2
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/html-render.rkt:813:4: render-one-part method in ...bble/html-render.rkt:267:2
loop
/Users/greg/src/plt/racket/pkgs/scribble-pkgs/scribble-lib/scribble/contract-render.rkt:14:4: render method in .../contract-render.rkt:12:2
/Users/greg/src/plt/racket/pkgs/racket-pkgs/racket-index/setup/scribble.rkt:1407:3
/Users/greg/src/plt/racket/racket/collects/setup/parallel-do.rkt:420:20: loop
That's just the documentation. Otherwise it seemed to install fine. The example state machine program you posted on Racket users mailing list, run great.
Box-and-pointer-diagrams: Vectors ought to be drawn the same way as cons cells.
currently pt
and vec
are documented twice, once in representation.scrbl and once in pt.scrbl. I'd suggest that either all data types are documented in one place (representations.scrbl) or each with the code that manipulates them (pt.scrbl). I'd maybe lean towards the latter, as it's nice to have them along with the code that uses them, but seeing them all in one place is nice too...
Either way, I suspect that having them in one place could confuse scribble as to which is the canonical version. Or at least make the version of pt
that is linked to when clicking on it nondeterministic.
This ought to render as a straight line, but doesn't.
It is visible in pdf, where you can zoom in.
(color "blue" (draw (bez (pt 0 0)
(pt 0.01 0.0003)
(pt 0.02 0.0006)
(pt 0.03 0.0009))))
One solution: In draw-bez if the four points are on line, either youse
(bez A A B B) which renders correctly, or simply add a line rather
than a bezier curve to the currect dc-path.
Metapict is a very nice project! The only thing I missed during the preparation of my slides was LaTeX for the labels (like in matplotlib). Is this possible to implement? Or is there another way, easier way to incorporate, maybe without introducing another dependency? Sorry if I missed it, I am a Racket n00b 😄
Best wishes
Johannes
(def triangle (curve (pt 0 0) -- (pt 1/2 1) -- (pt 1 0) -- cycle))
(pencolor "red" (brushcolor "pink" (filldraw triangle)))
Determine if it is a MetaPict problem or it is due to Cairo.
Hello, I first want to thank you for the work you do on this wonderful library!
I was encountering a problem with the intersection-points function. For example, when running the query (intersection-points (curve (pt 1 -1) .. (pt 2 -1) .. (pt 1 -1)) (curve (pt 1 -1) .. (pt 1 -1)))
, an infinite loop occurs and the function never returns. It looks like when the intersection point at the end of a curve such situation occurs. The example (intersection-points (curve (pt 1 -1) .. (pt 1 -1)) (curve (pt 1 -1) .. (pt 1 -1)))
also causes an infinite loop.
It seems like when intersection-points calculates the next point, its next step is the same as the initial value.
raco setup: 2 running: <pkgs>/metapict/metapict/scribblings/metapict.scrbl
raco setup: WARNING: undefined tag in <pkgs>/metapict/metapict/scribblings/metapict.scrbl:
raco setup: ((lib "metapict/main.rkt") --)
raco setup: ((lib "metapict/main.rkt") -pi/2)
raco setup: ((lib "metapict/main.rkt") ..)
raco setup: ((lib "metapict/main.rkt") ...)
raco setup: ((lib "metapict/main.rkt") ahlength)
raco setup: ((lib "metapict/main.rkt") beside)
raco setup: ((lib "metapict/main.rkt") bot)
raco setup: ((lib "metapict/main.rkt") curve)
raco setup: ((lib "metapict/main.rkt") dot-label)
raco setup: ((lib "metapict/main.rkt") draw)
raco setup: ((lib "metapict/main.rkt") draw*)
raco setup: ((lib "metapict/main.rkt") draw-arrow)
raco setup: ((lib "metapict/main.rkt") fill)
raco setup: ((lib "metapict/main.rkt") for/draw)
raco setup: ((lib "metapict/main.rkt") penwidth)
raco setup: ((lib "metapict/main.rkt") pi/2)
raco setup: ((lib "metapict/main.rkt") px)
raco setup: ((lib "metapict/main.rkt") set-curve-pict-size)
raco setup: ((lib "metapict/main.rkt") top)
raco setup: ((lib "metapict/main.rkt") trans?)
raco setup: ((lib "metapict/main.rkt") unitsquare)
raco setup: ((lib "metapict/main.rkt") window)
raco setup: ((lib "metapict/main.rkt") with-window)
The coordinate system is a little cumbersome: it requires both the size of the picture and some additional offsetting via a window.
Wouldn't it be possible, using picts, to get rid at least of the window (if not of the picture size) and center the picture?
Gradients are specified in device coordinates.
The function brushshade should use logical coordinates.
The transformations represented by the trans
structure currently
accepts pt
, vec
and curve
as inputs.
Allow point
to be used as input as well.
I got the following error when installing metapict
(as a dependency for racket-graphiz
) through the package server:
.racket/7.7/pkgs/metapict/metapict/structs.rkt:267:37: current-draw-axis-tick: unbound identifier
in: current-draw-axis-tick
compilation context...:
.racket/7.7/pkgs/metapict/metapict/tree.rkt
location...:
.racket/7.7/pkgs/metapict/metapict/structs.rkt:267:37
context...:
do-raise-syntax-error
expand-implicit
for-loop
finish-bodys
lambda-clause-expander
for-loop
[repeats 3 more times]
finish-bodys
do-local-expand
syntax-local-expand-expression
/usr/share/racket/collects/racket/private/stxparam.rkt:61:2: let-local-keys
apply-transformer-in-context
apply-transformer
dispatch-transformer
for-loop
finish-bodys
Likely nothing serious, but nevertheless ... :-)
When I install metapict
under Racket 8.5, I see several of these messages:
WARNING: collected information for key multiple times: '(dep ((lib "metapict/device.rkt") set-curve-pict-size)); values: #t #t
WARNING: collected information for key multiple times: '(def ((lib "metapict/device.rkt") set-curve-pict-size)); values: (vector #f '(def ((lib "metapict/device.rkt") set-curve-pict-size)) #f (list (mobile-root #<path:/home/schwa/.local/share/racket/8.5/pkgs/metapict/metapict/doc/metapict>) #"index.html") #f) (vector #f '(def ((lib "metapict/device.rkt") set-curve-pict-size)) #f (list (mobile-root #<path:/home/schwa/.local/share/racket/8.5/pkgs/metapict/metapict/doc/metapict>) #"index.html") #f)
WARNING: collected information for key multiple times: '(index-entry (def ((lib "metapict/device.rkt") set-curve-pict-size))); values: (list '("set-curve-pict-size") (list (sized-element (style "RktSym" (list 'tt-chars (css-addition '(collects #"scribble" #"racket.css")) (tex-addition '(collects #"scribble" #"racket.tex")))) (cached-delayed-element #<procedure:...scribble/racket.rkt:17... (list '("set-curve-pict-size") (list (sized-element (style "RktSym" (list 'tt-chars (css-addition '(collects #"scribble" #"racket.css")) (tex-addition '(collects #"scribble" #"racket.tex")))) (cached-delayed-element #<procedure:...scribble/racket.rkt:17...
The function bez-arc-length
doesn't handle the case where +inf.0 are used as coordinates.
#(struct:bez #(struct:pt 203.2 0.0) #(struct:pt +inf.0 +inf.0) #(struct:pt -inf.0 -inf.0) #(struct:pt 203.15 0.0))
I happened to notice that the .github
folder gets installed with the package. This is kind of a minor bug, but doesn't seem like it should get installed.
> ls -a /usr/local/Cellar/minimal-racket/8.7/share/racket/pkgs/metapict/
. .. .github README.txt info.rkt metapict
> ls -a /usr/local/Cellar/minimal-racket/8.7/share/racket/pkgs/metapict/.github/workflows/
. .. push.yml
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.