Vladimír Lukeš: METAFONT - Jak kreslit obrázky
Predchozi (Obsah) Dalsi

B. Další příklady

B.1. Příklad 1

obrazek 28

u#:=1mm#; define_pixels(u);

def uchyt(expr s,uhel)= % rotacni uchyt
pair jv,ps;
jv:=unitvector(dir(uhel));
ps:=s+unitvector(dir(uhel+90))*2.5u;
pickup pencircle scaled .3pt
for i:=1 upto 5: % ram
draw (origin--(u,2u)) rotated uhel shifted (ps+jv*(i-3)*u);
endfor;
pickup pencircle scaled .6pt;
draw (ps-jv*2.5u)--(ps+jv*2.5u);
draw ((-2.5u,-1.5u)--origin--(-2.5u,1.5u)) rotated (uhel-90) shifted s;
erase filldraw fullcircle scaled(1.5u) shifted s;
draw fullcircle scaled(1.5u) shifted s; % krouzek
enddef;

def pruzina(expr od,do)= % pruzina - (zacatek,konec)
draw od--do;
erase draw (left*6u--right*6u) rotated angle(do-od) shifted .5[od,do];
draw ((-6u,0)--(-5u,2u)--(-3u,-2u)--(-u,2u)--(u,-2u)--(3u,2u)
--(5u,-2u)--(6u,0)) rotated angle(do-od) shifted .5[od,do];
enddef;

beginchar(65,80mm#,40mm#,0);
pickup pencircle scaled .6pt;
draw (66u,16u)--(66u,14u); % stred koule
draw (65u,15u)--(67u,15u);
pickup pencircle scaled .8pt;
draw (55u,13u)--(10u,13u)--(10u,17u)--(55u,17u); % tyc
draw fullcircle scaled 22u shifted (66u,15u); % koule
pickup pencircle scaled .8pt;
pruzina((35u,15u),(35u,35u)); % pruzina
uchyt((10u,15u),90); % uchyty
uchyt((35u,35u),0);
erase filldraw fullcircle scaled(1.5u) shifted (35u,15u);
draw fullcircle scaled(1.5u) shifted (35u,15u); % kloub
endchar;

B.2. Příklad 2

obrazek 29

u#:=1mm#; define_pixels(u);

def odpor (expr od,do)= % odpor
pickup pencircle scaled .6pt;
draw od--do; % privod
erase draw (left*4.5u--right*4.5u) rotated angle(do-od) shifted .5[od,do];
draw (unitsquare xscaled (9u) yscaled (3u) shifted (-4.5u,-1.5u)) rotated angle(do-od) shifted .5[od,do];
enddef;

def kondenzator (expr od,do)= % kondenzator
transform tr;
tr:=identity rotated angle(do-od) shifted .5[od,do];
pickup pencircle scaled .6pt;
draw od--do; % privody
erase draw (left*.9u--right*.9u) transformed tr;
pickup penrazor scaled .75u rotated angle(do-od);
draw (down*2.4u--up*2.4u) shifted (right*.9u) transformed tr;
draw (down*2.4u--up*2.4u) shifted (left*.9u) transformed tr;
enddef;

def uzel expr uz= % uzel - plny
filldraw fullcircle scaled .8u shifted uz;
enddef;

def uzelp expr uz= % uzel - prazdny
erase filldraw fullcircle scaled .8u shifted uz;
draw fullcircle scaled .8u shifted uz;
enddef;

beginchar(66,50mm#,35mm#,0);
pickup pencircle scaled .6pt;
draw (5u,15u)--(5u,5u)--(45u,5u);
draw (5u,20u)--(5u,30u)--(45u,30u);
odpor((10u,30u),(30u,30u)); % odpor
kondenzator((35u,5u),(35u,30u)); % kondenzator
pickup pencircle scaled .6pt;
uzel(35u,5u); uzel(35u,30u); % uzly
uzel(45u,5u); uzel(45u,30u);
uzelp(5u,15u); uzelp(5u,20u); % plne uzly
draw (left*2u{dir60}..{dir-60}origin{dir-60}..{dir60}right*2u) shifted (3u,17.5u);
endchar;

B.3. Příklad 3

obrazek 30

u#:=1mm#; define_pixels(u);

def sipka(expr smer) = % zakulacena sipka k osam
begingroup
sip:=3u;
((-sip,-2/7sip){dir45}..{dir2}(0,0)&(0,0){dir178}..{dir135}(-sip,2/7sip)&(-sip,2/7sip)..controls
(-3/4sip,0)..(-sip,-2/7sip)&(-sip,-2/7sip)..cycle) rotated smer
endgroup
enddef;

def fce(expr x)= % funkce
(x**3)-3*(x**2)-(13*x)+15
enddef;

beginchar(67,60mm#,40mm#,0);
pair nula;
nula:=(20u,10u);
pickup pencircle scaled .6pt;
draw (up*h--origin) shifted (right*xpart(nula)); % osa x
draw (origin--right*w) shifted (up*ypart(nula)); % osa y
filldraw sipka(0) shifted (w,ypart(nula)); % sipky k osam
filldraw sipka(90) shifted (xpart(nula),h);
pickup pencircle scaled .3pt;
for i:=0 step 2u until w+1u: % x-ova sit
draw (origin--up*h) shifted (right*i);
endfor;
for i:=0 step 2u until h+1u: % y-ova sit
draw (origin--right*w) shifted (up*i);
endfor;
pickup pencircle scaled .8pt;
currenttransform:=identity xscaled 4u yscaled (u/20) shifted nula;
x:=-5; px:=x; py:=fce(px);
forever: % hodnoty funkce
x:=x+0.1; y:=fce(x);
draw (px,py)..(x,y);
px:=x; py:=y;
exitif x>10;
endfor;
endchar;


Predchozi
Converted by Selathco 0.85 on 19.06.1999 11:53
Dalsi