summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/modules/mkiv/m-asymptote.mkiv
blob: 9cd4037fb583ebbab23682b9dfdbed7e1eea44fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%D \module
%D   [       file=m-asymptote,
%D        version=2017.03.24,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=Asymptote,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% \enabletrackers[sandbox,buffers.run]

%D Currently asymptote assumes \MKII\ but better is to only support \MKIV. A problem
%D is that asymptote has this hard coded while for \CONTEXT\ it's better to stick to
%D something simple:
%D
%D \starttyping
%D \starttext
%D
%D \startasymptotepage
%D     some label
%D \stopasymptotepage
%D
%D \startasymptotepage
%D     some label
%D \stopasymptotepage
%D
%D \stoptext
%D \stoptyping
%D
%D Which is then run with:
%D
%D \starttyping
%D context --nonstopmode --purge somefile.tex
%D \stoptyping
%D
%D For the moment add "settings.prc=true;" to a graphic that is meant to produce that
%D format. See end of file for some examples.

\registerctxluafile{m-asymptote}{}

\unprotect

\unexpanded\def\asymptote
  {\dodoubleempty\module_asymptote}

\unexpanded\def\module_asymptote[#1][#2]%
  {\iffirstargument
     \begingroup
     \getdummyparameters[#2]%
     \edef\lasttypesetbuffer{\ctxlua{moduledata.asympote.process("asymptote:#1","\dummyparameter\c!type")}}%
     \externalfigure
       [\lasttypesetbuffer]%
       [\c!controls=\lasttypesetbuffer,#2]%
     \endgroup
   \fi}

\unexpanded\def\startasymptote[#1]%
  {\begingroup
   \dostartbuffer[asymptote:#1][startasymptote][stopasymptote]}

\unexpanded\def\stopasymptote
  {\endgroup}

\definefittingpage
  [asymptotepage]
  [\c!align=\v!normal]

\protect

\continueifinputfile{m-asymptote.mkiv}

\starttext

\startasymptote[demo-1]
settings.prc = true ;

import graph3 ;
import palette ;

size(6cm,6cm) ;
size3(5cm,0) ;

currentprojection = orthographic(3,-6,12) ;
currentlight = light(8,10,2) ;

real g(pair z) { return 1-z.x^2-z.y^2 ; }
real f(pair z) { return -2z.x+2 ; }

real x(real t) { return t ; }
real y(real t) { return 0 ; }
real z(real t) { return 1-t^2 ; }
real a(real t) { return 1 ; }
real b(real t) { return t ; }
real c(real t) { return -t^2 ; }

path3 p=graph(x,y,z,-2,2,operator ..) ;
path3 o=graph(a,b,c,-2,2,operator ..) ;

surface r = surface(f, (0,-1), (2,1), nx = 3, Spline) ;
surface s = surface(g, (-2,-2), (2,2), nx = 5, Spline) ;

path3 q = (-2,-2,-7) -- (2,-2,-7) -- (2,2,-7) -- (-2,2,-7) -- cycle ;

draw(q) ;

draw(p, blue+thick(), Arrow3) ;
draw(o, blue+thick(), Arrow3) ;

draw(s, lightgray + opacity(0.8), nolight, meshpen = black + thick()) ;
draw(r, lightgray + opacity(0.8), nolight, meshpen = black + thick()) ;

draw((1,0,0) -- (2,0,-2), black, Arrow3) ;
draw((1,0,0) -- (1,1,0), black, Arrow3) ;
\stopasymptote

\startasymptote[demo-2]
size(6cm,6cm) ;

fill((1cm,2cm) -- (3cm,3cm) -- (4cm,0cm) -- cycle);
\stopasymptote

% see end of grph-inc.mkiv for some more options:

\startluaparameterset[demo-1]
    toolbar = true,
    tree = false,
    view = 'ortho'
\stopluaparameterset

\asymptote[demo-1][type=prc,width=5cm,height=5cm,frame=on,display=yes,controls=yes,preview=yes]
\asymptote[demo-2][type=pdf,width=8cm,frame=on]

% \typebuffer[asymptote:demo-1]

% \startasymptotepage
%     test
% \stopasymptotepage

\stoptext