我编写此代码是为了以示意图的形式表示化学势能的概念。此图像将成为伏打电池中能量转换的代表性图表的一部分:化学势能 -> 电能(= 电功)(传感器:灯)-> 辐射能 -> 内能。我请求帮助完成两项任务:1)增加透明度并改善试管的表示,2)改善胡萝卜的表示(如果可能的话)。提前致谢。
\starttext
\startMPpage
picture tube, base, carrot;
path p;
pair t;
numeric xx, y;
color carrotcolor, aquaU, aquaD, tubecolor;
carrotcolor :=(235/255, 137/255, 33/255);
aquaU := (2/255, 132/255, 130/255);
aquaD := (122/255, 186/255, 122/255);
tubecolor :=(183/255, 110/255, 184/255);
%draw the essay tube
draw origin--origin shifted (3cm,0cm) withpen pencircle scaled 1cm withcolor tubecolor;
draw origin--origin shifted (3cm,0cm) withpen pencircle scaled .8cm withcolor white;
fill fullcircle shifted (-0.01cm,0) xscaled .6cm yscaled .9cm withpen pencircle scaled .1cm withcolor white;
draw fullcircle shifted (-.010cm,0) xscaled .61cm yscaled .9cm withpen pencircle scaled .1cm withcolor tubecolor;
tube := currentpicture scaled .4;currentpicture:=nullpicture;
%draw the rectangle base
linejoin := mitered; linecap := butt;
fill (0,0)--(0,2cm)--(3cm,2cm)--(3cm,0)--cycle withcolor aquaD;
draw (0,0)--(0,2cm)--(3cm,2cm)--(3cm,0)--cycle withpen pencircle scaled 1mm withcolor aquaU;
base:=currentpicture; currentpicture:=nullpicture;
% draw the carrot tubercle
p:= origin..(-.1cm,.15cm)..(-.1cm,2.15cm)..(0,2.15cm)..(.1cm,2.15cm)..(.1cm,.15cm)..cycle;
drawfill p withcolor transparent(1,.5,carrotcolor);
draw p ;
% draw the green leaves
linejoin :=mitered; linecap:=rounded;
for i=2 step .1 until 4:
t:= point i of p;
xx:=uniformdeviate( 1 )*1cm + xpart(t)-uniformdeviate( 1 )*1cm;
y:=uniformdeviate( 1.5 )*1cm + ypart(t);
draw t..(xx,y) withpen pencircle scaled 1.mm withcolor green;
endfor;
carrot := currentpicture scaled .45; currentpicture:=nullpicture;
%include all drawings
draw base;
draw tube rotated -135 shifted (2cm,1.5cm) ;
draw carrot rotated 45 shifted (2cm,.5cm) ;
\stopMPpage
\stoptext