From e218b894bbfc63142d64b9c456dd98396b6c14df Mon Sep 17 00:00:00 2001 From: Loewe1000 Date: Thu, 17 Apr 2025 13:34:59 +0200 Subject: [PATCH] Added simple-circuit --- gallery/simple-circuit.typ | 36 ++++++++++++++++++++++++++++++++++++ src/lib.typ | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 gallery/simple-circuit.typ diff --git a/gallery/simple-circuit.typ b/gallery/simple-circuit.typ new file mode 100644 index 0000000..e1b00aa --- /dev/null +++ b/gallery/simple-circuit.typ @@ -0,0 +1,36 @@ +#import "../src/lib.typ": * +#import "@preview/cetz:0.3.2": draw // For potential use of draw.hide if needed, but trying without first + +#set page(width: auto, height: auto, margin: 1cm) + +#circuit({ + // Circuit 1: Series Lamps + electrical.voltage-source(x: 0, y: 0, w: 1, h: 1, id: "vs1") + electrical.lamp(x: 1, y: 0, w: 1, h: 1, id: "lamp1") + electrical.lamp(x: 2, y: 0, w: 1, h: 1, id: "lamp2") + + // Circuit 1 Wires + wire.wire("w-s-1", ("vs1.east", "lamp1.west")) + wire.wire("w-s-2", ("lamp1.east", "lamp2.west")) + // Use dodge style for return path + wire.wire("w-s-return", ("lamp2.east", "vs1.west"), style: "dodge", dodge-y: -1.5, dodge-sides: ("east", "west")) +}) + + +#circuit({ + // Circuit 2: RC Charging + + electrical.voltage-source(x: 0, y: 0, w: 1, h: 1, id: "vs") + electrical.switch(x: 2, y: 0, w: 1, h: 1, id: "sw1", closed: false) + electrical.capacitor(x: 2, y: -2, w: 1, h: 1, id: "c1") + electrical.resistor(x: 0, y: -2, w: 2, h: 1, id: "r1") + + electrical.voltmeter(x: 2, y: -3, w: 1, h: 1, id: "vm") + + wire.wire("w-s-1", ("vs-port-1", "sw1-port-0")) + wire.wire("w-s-2", ("c1-port-1", "sw1-port-1")) + wire.wire("w-s-3", ("r1-port-0", "vs-port-0")) + + wire.wire("w-s-4", ("vm-port-0", "c1-port-0")) + wire.wire("w-s-4", ("vm-port-1", "c1-port-1")) +}) diff --git a/src/lib.typ b/src/lib.typ index 7f27208..0603b79 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -4,4 +4,5 @@ #import "element.typ" #import "gates.typ" #import "util.typ" -#import "wire.typ" \ No newline at end of file +#import "wire.typ" +#import "electrical.typ" \ No newline at end of file