summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mp-grid.mp184
-rw-r--r--metapost/context/base/mp-tool.mp34
2 files changed, 122 insertions, 96 deletions
diff --git a/metapost/context/base/mp-grid.mp b/metapost/context/base/mp-grid.mp
index cfcc6bc15..d0d97dba9 100644
--- a/metapost/context/base/mp-grid.mp
+++ b/metapost/context/base/mp-grid.mp
@@ -2,142 +2,142 @@
%D [ file=mp-grid.mp,
%D version=2000.07.10,
%D title=\CONTEXT\ \METAPOST\ graphics,
-%D subtitle=grid support,
+%D subtitle=grid support,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
-%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
-%C details.
+%C therefore copyrighted by \PRAGMA. See licen-en.pdf for
+%C details.
%D Under construction.
-if unknown context_tool : input mp-tool ; fi ;
-if known context_grid : endinput ; fi ;
+if unknown context_tool : input mp-tool ; fi ;
+if known context_grid : endinput ; fi ;
-boolean context_grid ; context_grid := true ;
+boolean context_grid ; context_grid := true ;
-string fmt_separator ; fmt_separator := "@" ;
-numeric fmt_precision ; fmt_precision := 3 ;
-boolean fmt_initialize ; fmt_initialize := false ;
-boolean fmt_zerocheck ; fmt_zerocheck := true ;
+string fmt_separator ; fmt_separator := "@" ;
+numeric fmt_precision ; fmt_precision := 3 ;
+boolean fmt_initialize ; fmt_initialize := false ;
+boolean fmt_zerocheck ; fmt_zerocheck := true ;
if unknown fmt_loaded : input mp-form ; fi ;
-boolean fmt_pictures ; fmt_pictures := true ;
+boolean fmt_pictures ; fmt_pictures := true ;
-def do_format = if fmt_pictures : format else : formatstr fi enddef ;
-def do_mformat = if fmt_pictures : Mformat else : Mformatstr fi enddef ;
+def do_format = if fmt_pictures : format else : formatstr fi enddef ;
+def do_mformat = if fmt_pictures : Mformat else : Mformatstr fi enddef ;
-def hlingrid (expr Min, Max, Step, Length, Width) text t =
- image ( for i=Min step Step until Max :
- draw (origin--(Width,0)) shifted (0,i*(Length/Max)) t ;
- endfor ; ) ;
-enddef ;
+def hlingrid (expr Min, Max, Step, Length, Width) text t =
+ image ( for i=Min step Step until Max :
+ draw (origin--(Width,0)) shifted (0,i*(Length/Max)) t ;
+ endfor ; ) ;
+enddef ;
-def vlingrid (expr Min, Max, Step, Length, Height) text t =
- image ( for i=Min step Step until Max :
- draw (origin--(0,Height)) shifted (i*(Length/Max),0) t ;
- endfor ; ) ;
-enddef ;
+def vlingrid (expr Min, Max, Step, Length, Height) text t =
+ image ( for i=Min step Step until Max :
+ draw (origin--(0,Height)) shifted (i*(Length/Max),0) t ;
+ endfor ; ) ;
+enddef ;
def hloggrid (expr Min, Max, Step, Length, Width) text t =
- image ( for i=max(Min,1) step Step until min(Max,10) :
- draw (origin--(Width,0)) shifted (0,Length*log(i)) t ;
- endfor ; ) ;
-enddef ;
+ image ( for i=max(Min,1) step Step until min(Max,10) :
+ draw (origin--(Width,0)) shifted (0,Length*log(i)) t ;
+ endfor ; ) ;
+enddef ;
def vloggrid (expr Min, Max, Step, Length, Height) text t =
image ( for i=max(Min,1) step Step until min(Max,10) :
- draw (origin--(0,Height)) shifted (Length*log(i),0) t ;
- endfor ; ) ;
-enddef ;
+ draw (origin--(0,Height)) shifted (Length*log(i),0) t ;
+ endfor ; ) ;
+enddef ;
-vardef hlintext@#(expr Min, Max, Step, Length, Format) text t =
+vardef hlintext@#(expr Min, Max, Step, Length, Format) text t =
image ( do_initialize_numbers ;
- for i=Min step Step until Max :
- draw textext@#(do_format(Format,i)) shifted (0,i*(Length/Max)) t ;
- endfor ; )
-enddef ;
+ for i=Min step Step until Max :
+ draw textext@#(do_format(Format,i)) shifted (0,i*(Length/Max)) t ;
+ endfor ; )
+enddef ;
-vardef vlintext@#(expr Min, Max, Step, Length, Format) text t =
+vardef vlintext@#(expr Min, Max, Step, Length, Format) text t =
image ( do_initialize_numbers ;
- for i=Min step Step until Max :
- draw textext@#(do_format(Format,i)) shifted (i*(Length/Max),0) t ;
- endfor ; )
-enddef ;
+ for i=Min step Step until Max :
+ draw textext@#(do_format(Format,i)) shifted (i*(Length/Max),0) t ;
+ endfor ; )
+enddef ;
vardef hlogtext@#(expr Min, Max, Step, Length, Format) text t =
image ( do_initialize_numbers ;
- for i=max(Min,1) step Step until min(Max,10) :
- draw textext@#(do_format(Format,i)) shifted (0,Length*log(i)) t ;
- endfor ; )
-enddef ;
+ for i=max(Min,1) step Step until min(Max,10) :
+ draw textext@#(do_format(Format,i)) shifted (0,Length*log(i)) t ;
+ endfor ; )
+enddef ;
vardef vlogtext@#(expr Min, Max, Step, Length, Format) text t =
image ( do_initialize_numbers ;
- for i=max(Min,1) step Step until min(Max,10) :
- draw textext@#(do_format(Format,i)) shifted (Length*log(i),0) t ;
- endfor ; )
-enddef ;
-
-vardef hlinlabel@#(expr Min, Max, Step, Length) text t =
- image (
- for i=Min step Step until Max :
- draw thelabel@#(decimal i,(0,i*(Length/Max))) t ;
- endfor ; )
-enddef ;
-
-vardef vlinlabel@#(expr Min, Max, Step, Length) text t =
- image (
- for i=Min step Step until Max :
- draw thelabel@#(decimal i,(i*(Length/Max),0)) t ;
- endfor ; )
-enddef ;
+ for i=max(Min,1) step Step until min(Max,10) :
+ draw textext@#(do_format(Format,i)) shifted (Length*log(i),0) t ;
+ endfor ; )
+enddef ;
+
+vardef hlinlabel@#(expr Min, Max, Step, Length) text t =
+ image (
+ for i=Min step Step until Max :
+ draw thelabel@#(decimal i,(0,i*(Length/Max))) t ;
+ endfor ; )
+enddef ;
+
+vardef vlinlabel@#(expr Min, Max, Step, Length) text t =
+ image (
+ for i=Min step Step until Max :
+ draw thelabel@#(decimal i,(i*(Length/Max),0)) t ;
+ endfor ; )
+enddef ;
boolean numbers_initialized ; numbers_initialized := false ;
-def do_initialize_numbers =
- if not numbers_initialized :
- init_numbers ( textext.raw("$-$") ,
+def do_initialize_numbers =
+ if not numbers_initialized :
+ init_numbers ( textext.raw("$-$") ,
textext.raw("$1$") ,
textext.raw("${\times}10$") ,
- textext.raw("${}^-$") ,
+ textext.raw("${}^-$") ,
textext.raw("${}^2$") ) ;
numbers_initialized := true ;
- fi ;
-enddef ;
+ fi ;
+enddef ;
def initialize_numbers =
numbers_initialized := false ; do_initialize_numbers ;
-enddef ;
+enddef ;
-vardef linlog(expr xy) = ( xpart xy, log(ypart xy)) enddef ;
-vardef loglin(expr xy) = (log(xpart xy), ypart xy) enddef ;
-vardef loglog(expr xy) = (log(xpart xy), log(ypart xy)) enddef ;
-vardef linlin(expr xy) = ( (xpart xy), (ypart xy)) enddef ;
+vardef linlog(expr xy) = ( xpart xy, log(ypart xy)) enddef ;
+vardef loglin(expr xy) = (log(xpart xy), ypart xy) enddef ;
+vardef loglog(expr xy) = (log(xpart xy), log(ypart xy)) enddef ;
+vardef linlin(expr xy) = ( (xpart xy), (ypart xy)) enddef ;
-vardef loglinpath primary p = processpath (p) (loglin) enddef ;
-vardef linlogpath primary p = processpath (p) (linlog) enddef ;
-vardef loglogpath primary p = processpath (p) (loglog) enddef ;
-vardef linlinpath primary p = processpath (p) (linlin) enddef ;
+vardef loglinpath primary p = processpath (p) (loglin) enddef ;
+vardef linlogpath primary p = processpath (p) (linlog) enddef ;
+vardef loglogpath primary p = processpath (p) (loglog) enddef ;
+vardef linlinpath primary p = processpath (p) (linlin) enddef ;
-def processpath (expr p) (text pp) =
- if path p :
+def processpath (expr p) (text pp) =
+ if path p :
for i=0 upto length(p)-1 :
- (pp(point i of p)) .. controls
- (pp(postcontrol i of p)) and
- (pp(precontrol (i+1) of p)) ..
- endfor
- if cycle p :
- cycle
+ (pp(point i of p)) .. controls
+ (pp(postcontrol i of p)) and
+ (pp(precontrol (i+1) of p)) ..
+ endfor
+ if cycle p :
+ cycle
else :
- (pp(point length(p) of p))
+ (pp(point length(p) of p))
fi
- elseif pair p :
- (pp(p))
- else :
- p
- fi
-enddef ;
+ elseif pair p :
+ (pp(p))
+ else :
+ p
+ fi
+enddef ; \ No newline at end of file
diff --git a/metapost/context/base/mp-tool.mp b/metapost/context/base/mp-tool.mp
index 19160ba32..a23d86f35 100644
--- a/metapost/context/base/mp-tool.mp
+++ b/metapost/context/base/mp-tool.mp
@@ -1761,9 +1761,6 @@ vardef repathed (expr mode, p) text t =
endgroup
enddef ;
-
-
-
% After a question of Denis on how to erase a z variable, Jacko
% suggested to assign whatever to x and y. So a clearz
% variable can be defined as:
@@ -2125,7 +2122,36 @@ vardef colorpart(expr i) =
(redpart i, greenpart i,bluepart i)
enddef ;
+% for david arnold:
+
+% showgrid(-5,10,1cm,-10,10,1cm);
+
+def showgrid (expr MinX, MaxX, DeltaX, MinY, MaxY, DeltaY)=
+ begingroup
+ save defaultfont, defaultscale, size ;
+ string defaultfont ; defaultfont := "cmtt10"; % i.e. infofont
+ numeric defaultscale ; defaultscale := 8pt / fontsize defaultfont;
+ numeric size ; size := 2pt ;
+ for x=MinX upto MaxX :
+ for y=MinY upto MaxY :
+ draw (x*DeltaX, y*DeltaY)
+ withpen pencircle scaled
+ if (x mod 5 = 0) and (y mod 5 = 0) :
+ 1.5size withcolor .50white
+ else :
+ size withcolor .75white
+ fi ;
+ endfor ;
+ endfor ;
+ for x=MinX upto MaxX:
+ label.bot(decimal x, (x*DeltaX,-size));
+ endfor ;
+ for y=MinY upto MaxY:
+ label.lft(decimal y, (-size,y*DeltaY)) ;
+ endfor ;
+ endgroup
+enddef;
% done
-endinput ;
+endinput ; \ No newline at end of file