m-asymptote.mkiv /size: 3364 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=m-asymptote,
3%D        version=2017.03.24,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=Asymptote,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% \enabletrackers[sandbox,buffers.run]
15
16%D Currently asymptote assumes \MKII\ but better is to only support \MKIV. A problem
17%D is that asymptote has this hard coded while for \CONTEXT\ it's better to stick to
18%D something simple:
19%D
20%D \starttyping
21%D \starttext
22%D
23%D \startasymptotepage
24%D     some label
25%D \stopasymptotepage
26%D
27%D \startasymptotepage
28%D     some label
29%D \stopasymptotepage
30%D
31%D \stoptext
32%D \stoptyping
33%D
34%D Which is then run with:
35%D
36%D \starttyping
37%D context --nonstopmode --purge somefile.tex
38%D \stoptyping
39%D
40%D For the moment add "settings.prc=true;" to a graphic that is meant to produce that
41%D format. See end of file for some examples.
42
43\registerctxluafile{m-asymptote}{}
44
45\unprotect
46
47\unexpanded\def\asymptote
48  {\dodoubleempty\module_asymptote}
49
50\unexpanded\def\module_asymptote[#1][#2]%
51  {\iffirstargument
52     \begingroup
53     \getdummyparameters[#2]%
54     \edef\lasttypesetbuffer{\ctxlua{moduledata.asymptote.process("asymptote:#1","\dummyparameter\c!type")}}%
55     \externalfigure
56       [\lasttypesetbuffer]%
57       [\c!controls=\lasttypesetbuffer,#2]%
58     \endgroup
59   \fi}
60
61\unexpanded\def\startasymptote[#1]%
62  {\begingroup
63   \dostartbuffer[asymptote:#1][startasymptote][stopasymptote]}
64
65\unexpanded\def\stopasymptote
66  {\endgroup}
67
68\definefittingpage
69  [asymptotepage]
70  [\c!align=\v!normal]
71
72\protect
73
74\continueifinputfile{m-asymptote.mkiv}
75
76\starttext
77
78\startasymptote[demo-1]
79settings.prc = true ;
80
81import graph3 ;
82import palette ;
83
84size(6cm,6cm) ;
85size3(5cm,0) ;
86
87currentprojection = orthographic(3,-6,12) ;
88currentlight = light(8,10,2) ;
89
90real g(pair z) { return 1-z.x^2-z.y^2 ; }
91real f(pair z) { return -2z.x+2 ; }
92
93real x(real t) { return t ; }
94real y(real t) { return 0 ; }
95real z(real t) { return 1-t^2 ; }
96real a(real t) { return 1 ; }
97real b(real t) { return t ; }
98real c(real t) { return -t^2 ; }
99
100path3 p=graph(x,y,z,-2,2,operator ..) ;
101path3 o=graph(a,b,c,-2,2,operator ..) ;
102
103surface r = surface(f, (0,-1), (2,1), nx = 3, Spline) ;
104surface s = surface(g, (-2,-2), (2,2), nx = 5, Spline) ;
105
106path3 q = (-2,-2,-7) -- (2,-2,-7) -- (2,2,-7) -- (-2,2,-7) -- cycle ;
107
108draw(q) ;
109
110draw(p, blue+thick(), Arrow3) ;
111draw(o, blue+thick(), Arrow3) ;
112
113draw(s, lightgray + opacity(0.8), nolight, meshpen = black + thick()) ;
114draw(r, lightgray + opacity(0.8), nolight, meshpen = black + thick()) ;
115
116draw((1,0,0) -- (2,0,-2), black, Arrow3) ;
117draw((1,0,0) -- (1,1,0), black, Arrow3) ;
118\stopasymptote
119
120\startasymptote[demo-2]
121size(6cm,6cm) ;
122
123fill((1cm,2cm) -- (3cm,3cm) -- (4cm,0cm) -- cycle);
124\stopasymptote
125
126% see end of grph-inc.mkiv for some more options:
127
128\startluaparameterset[demo-1]
129    toolbar = true,
130    tree = false,
131    view = 'ortho'
132\stopluaparameterset
133
134\asymptote[demo-1][type=prc,width=5cm,height=5cm,frame=on,display=yes,controls=yes,preview=yes]
135\asymptote[demo-2][type=pdf,width=8cm,frame=on]
136
137% \typebuffer[asymptote:demo-1]
138
139% \startasymptotepage
140%     test
141% \stopasymptotepage
142
143\stoptext
144