// ---------------------- Charges -------------------------
+pen pChargePen = red;
+pen nChargePen = blue;
+pen neutralChargePen = grey;
+
// charged particle
struct Charge {
LabeledCircle lc;
real q;
void operator init(pair center=(0,0), real q=1, real radius=2mm,
- pen outline=currentpen, pen fill=red, Label L="") {
+ pen outline=currentpen, pen fill=pChargePen, Label L="") {
this.lc.operator init(center=center, radius=radius, outline=outline,
fill=fill, L=L);
this.q = q;
Charge pCharge(pair center=(0,0), real q=1, real radius=2mm,
pen outline=currentpen, Label L="")
{
- return Charge(center=center, q=q, radius=radius, outline=outline, fill=red,
- L=L);
+ return Charge(center=center, q=q, radius=radius, outline=outline,
+ fill=pChargePen, L=L);
}
// negative charge
Charge nCharge(pair center=(0,0), real q=-1, real radius=2mm,
pen outline=currentpen, Label L="")
{
- return Charge(center=center, q=q, radius=radius, outline=outline, fill=blue,
- L=L);
+ return Charge(center=center, q=q, radius=radius, outline=outline,
+ fill=nChargePen, L=L);
}
// neutral charge
Charge neutralCharge(pair center=(0,0), real radius=2mm,
pen outline=currentpen, Label L="")
{
- return Charge(center=center, q=0, radius=radius, outline=outline, fill=grey,
- L=L);
+ return Charge(center=center, q=0, radius=radius, outline=outline,
+ fill=neutralChargePen, L=L);
}
// auto-signed charge