summaryrefslogtreecommitdiff
path: root/ld.mp
diff options
context:
space:
mode:
authortouka <touka@nopwd.lol>2024-07-05 07:47:31 +0000
committertouka <touka@nopwd.lol>2024-07-05 07:47:31 +0000
commit0ba116798aa6ba7a220dfe6d2d2b067f7f57d5f7 (patch)
treeebf26c0544092cf96f37a2820acbad3ba4fb798e /ld.mp
Baisc gates
Diffstat (limited to 'ld.mp')
-rw-r--r--ld.mp240
1 files changed, 240 insertions, 0 deletions
diff --git a/ld.mp b/ld.mp
new file mode 100644
index 0000000..18e2ab2
--- /dev/null
+++ b/ld.mp
@@ -0,0 +1,240 @@
+prologues := 3;
+
+GNL = 20;
+GAL = 46;
+
+% ========= OR GATE ===========
+def gate_or(expr gox, goy) =
+
+pair GOe;
+numeric gos, wt, ht, il;
+save gos, wt, ht, il;
+
+wt = 25;
+ht = 15;
+il = 10;
+gos = gox + il - 5;
+GOe = (gos+wt, goy+5);
+
+draw (gox, goy)--(gox+il-.3, goy);
+draw (gox, goy+10)--(gox+il-.3, goy+10);
+
+draw (gos, goy-5)..(gos + 6, ypart GOe)..(gos, goy+ht);
+draw (gos, goy-5)--(gos + 10, goy-5)..(gos + 11, goy-5)..GOe;
+draw (gos, goy+ht)--(gos + 10, goy+ht)..(gos + 11, goy+ht)..GOe;
+
+draw GOe--(xpart GOe + il, ypart GOe);
+
+GOe := (gos+wt+il, goy+5);
+
+enddef;
+
+% ========= AND GATE ===========
+def gate_and(expr gax, gay) =
+
+numeric GAh, GAl, GAs;
+GAh := 20;
+GAl := 10;
+GAe := gax+36;
+GAs := gax+GAl;
+
+draw (GAs, gay-5)--(GAs, gay+GAh-5);
+draw (GAs, gay+GAh-5)--(gax+25,gay+GAh-5)..(GAe-1,gay+9)..(GAe,gay+5)..(GAe-6,gay-4)..
+ (gax+25,gay-5)--(gax+GAl, gay-5);
+
+draw (gax,gay)--(GAs,gay);
+draw (gax,gay+10)--(GAs,gay+10);
+draw (GAe, gay+5)--(GAe+GAl, gay+5);
+
+GAe := GAe + GAl;
+enddef;
+
+% ========= NOT GATE ===========
+def gate_not(expr gnx, gny) =
+
+numeric il, sz, wd, gns, GNe;
+save il, gns;
+
+il = 10;
+sz = 5;
+wd = 10;
+gns = gnx;
+
+draw (gns, gny)--(gns+il, gny);
+
+gns := gns + il;
+GNe = gns + wd;
+
+draw (gns, gny-sz)--(gns, gny+sz)--(GNe, gny)--(gns, gny-sz);
+draw (GNe, gny)..(GNe+3, gny)..(GNe, gny);
+
+il := il - 3;
+draw (GNe+3, gny)--(GNe+il, gny);
+GNe := GNe + il;
+
+enddef;
+
+% ======== TRIPLE INPUT ========
+
+outputtemplate := "nora.eps";
+beginfig(5)
+
+numeric wt, ht, il;
+
+wt = 50;
+ht = 15;
+il = 15;
+
+label.lft(btex $z$ etex, (0, 0));
+label.lft(btex $y$ etex, (0, 10));
+label.lft(btex $x$ etex, (0, 20));
+label.rt(btex $(x+y+z)'$ etex, (wt+il, 10));
+
+draw (0, 0)--(19, 0);
+draw (0, 10)--(22, 10);
+draw (0, 20)--(19, 20);
+
+draw (15, -5)..(22, 10)..(15, 25);
+draw (15, -5)--(25, -5)..(26, -5)..(wt, 10);
+draw (15, 25)--(22, 25)..(23, 25)..(wt, 10);
+draw (wt, 10)..(wt+3, 10)..(wt, 10);
+
+draw (wt+3, 10)--(wt+il-3, 10);
+
+endfig;
+
+% =================
+
+outputtemplate := "norb.eps";
+beginfig(6)
+
+numeric wt, ht, il;
+
+wt = 50;
+ht = 30;
+il = 12;
+
+label.lft(btex $z$ etex, (0, 0));
+label.lft(btex $y$ etex, (0, 10));
+label.lft(btex $x$ etex, (0, 20));
+label.rt(btex $x'y'z'=(x+y+z)'$ etex, (wt+il, 10));
+
+draw (0, 0)--(il, 0);
+draw (il, 0)..(il+3, 0)..(il, 0);
+draw (0, 10)--(il, 10);
+draw (il, 10)..(il+3, 10)..(il, 10);
+draw (0, 20)--(il, 20);
+draw (il, 20)..(il+3, 20)..(il, 20);
+
+il := il + 3;
+draw (il, -5)--(il, ht-5);
+draw (il, -5)--(il+20, -5)..(il+21, -5)..(wt, 10);
+draw (il, 25)--(il+20, 25)..(il+21, 25)..(wt, 10);
+
+draw (wt, 10)--(wt+il, 10);
+endfig;
+
+% =================
+
+outputtemplate := "nanda.eps";
+beginfig(7);
+
+numeric il, gas, ht, wt;
+
+il = 10;
+gas = il;
+ht = 30;
+wt = 40;
+
+label.lft(btex $z$ etex, (0, 5));
+label.lft(btex $y$ etex, (0, 15));
+label.lft(btex $x$ etex, (0, 25));
+
+draw (0, 5)--(il, 5);
+draw (0, 15)--(il, 15);
+draw (0, 25)--(il, 25);
+
+draw (gas, 0)--(gas, ht);
+draw (gas, 0)--(gas + 25, 0)..(gas + wt, ht/2-1)..
+ (gas + 25, ht)--(gas, ht);
+
+gas := gas + wt;
+draw (gas, ht/2)..(gas + 3, ht/2)..(gas, ht/2);
+gas := gas + 3;
+il := il - 3;
+draw (gas, ht/2)--(gas + il, ht/2);
+
+label.rt(btex $(xyz)'$ etex, (gas + il, ht/2));
+
+endfig;
+
+% ================================
+% LOGIC DIAGRAMS
+% ================================
+
+outputtemplate := "ld3.eps";
+beginfig(0);
+
+pair FX, FY, FZ;
+numeric hs;
+
+hs := 5;
+FZ := (0, 0);
+FY := (0, hs*3);
+FX := (0, ypart FY*2);
+
+draw FY--(5, ypart FY);
+gate_not(5, ypart FY);
+draw (GNe, ypart FY)--(GNe+10, ypart FY);
+
+draw FZ--(GNe+5, 0)--(GNe+5, hs)--(GNe+10, hs);
+gate_and(GNe+10, hs);
+draw (GAe, hs+5)--(GAe+10, hs*2);
+
+draw FX--(GAe, ypart FX)--(GAe, ypart FX-10)--(GAe+10, ypart FX-10);
+gate_or(GAe+10, hs*2);
+
+label.lft(btex $z$ etex, FZ);
+label.lft(btex $y$ etex, FY);
+label.lft(btex $x$ etex, FX);
+label.lft(btex $F$ etex, (xpart GOe + 12, ypart GOe));
+
+endfig;
+
+% ===============
+
+outputtemplate := "ld6b.eps";
+beginfig(1)
+ numeric FA, FB, FC, tmp;
+
+ FC = 0;
+ FB = 40;
+ FA = FB+10;
+
+ label.lft(btex $C$ etex, (0, FC));
+ label.lft(btex $B$ etex, (0, FB));
+ label.lft(btex $A$ etex, (0, FA));
+
+ tmp := 30;
+ draw (0, FA)--(tmp, FA);
+ draw (0, FB)--(tmp, FB);
+
+ drawdot (10, FA) withpen pencircle scaled 3pt;
+ draw (10, FA)--(10, 10)--(15, 10);
+ gate_not(15, 10);
+
+ draw (0, FC)--(GNe, 0);
+ gate_and(GNe, 0);
+
+ draw (tmp, FA)--(GNe, FA);
+ draw (tmp, FB)--(GNe, FB);
+ gate_and(GNe, FB);
+
+ draw (GAe, FB+5)--(GAe, FB-10)--(GAe+5, FB-10);
+ draw (GAe, 5)--(GAe, 20)--(GAe+5, 20);
+
+ gate_or(GAe+5, 20);
+
+ label.rt(btex $F$ etex, GOe);
+endfig;
+end