Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Package Features #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions circuitypst.typ
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#import "components.typ"
#import "utils.typ"

#import "../typst-canvas/draw.typ": *
#import "../typst-canvas/coordinate.typ"
#import "../typst-canvas/vector.typ"
#import "@preview/cetz:0.0.1"
#import cetz.draw: fill, stroke, group, anchor, rotate, set-origin, line, content, move-to

#let canvas-fill = fill
#let canvas-stroke = stroke
Expand All @@ -17,7 +16,7 @@
#let node(component, position, label: none, name: none, anchor: none, fill: auto, stroke: auto, ..options) = {
assert(component in components.node, message: "Component '" + component + "' is unknown")
group(name: name, anchor: anchor, {
import "../typst-canvas/draw.typ": anchor
import cetz.draw: anchor

if fill != auto {
canvas-fill(fill)
Expand Down
4 changes: 3 additions & 1 deletion components.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "../typst-canvas/draw.typ": *
#import "@preview/cetz:0.0.1"

#import cetz.draw: line, circle, fill, rect

#import "parts.typ"
#import "utils.typ": anchors
Expand Down
Binary file modified examples/current-shunt.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/current-shunt.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "../../typst-canvas/canvas.typ": canvas
#import "@preview/cetz:0.0.1"

#lorem(30)

#figure(
canvas(length: 1cm, debug: false, {
import "../../typst-canvas/draw.typ": *
import "../circuitypst.typ": node, to
cetz.canvas(length: 1cm, debug: false, {
import cetz.draw: line
import "@local/circuitypst:0.0.1": node, to

to("isourceAM", (0,0), (0,3), label: $I_0$, v: h(0.5em) + $V_0$)
to("short", (), (2,3), i: $I_0$,)
Expand Down
Binary file modified examples/exclusive-or.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/exclusive-or.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "../../typst-canvas/canvas.typ": canvas
#import "@preview/cetz:0.0.1"

#lorem(30)

#figure(
canvas({
import "../../typst-canvas/draw.typ": *
import "../circuitypst.typ": node
cetz.canvas({
import cetz.draw: line, content
import "@local/circuitypst:0.0.1": node

node("nand gate", (0,1), name: "g1")
content("g1.out", [#h(0.5em) Q], anchor: "left")
Expand Down
Binary file modified examples/half-adder.pdf
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/half-adder.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "../../typst-canvas/canvas.typ": canvas
#import "@preview/cetz:0.0.1"

#lorem(30)

#figure(
canvas(length: 1cm, debug: false, {
import "../../typst-canvas/draw.typ": *
import "../circuitypst.typ": node
cetz.canvas(length: 1cm, debug: false, {
import cetz.draw: line, content
import "@local/circuitypst:0.0.1": node

node("and gate", (0,0), name: "g1")
content("g1.out", h(0.5em)+[Carry], anchor: "left")
Expand Down
16 changes: 9 additions & 7 deletions parts.typ
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#import "../typst-canvas/draw.typ": *
#import "@preview/cetz:0.0.1"
#import cetz.draw: merge-path, arc, line, circle

#import "utils.typ": anchors
#let and-gate-body = {
merge-path(close: true, {
arc((0,0), -90deg, 90deg, radius: 0.5, name: "curve", anchor: "origin")
arc((0,0), start: -90deg, stop: 90deg, radius: 0.5, name: "curve", anchor: "origin")
line(
(0, 0.5),
(-0.5, 0.5),
Expand All @@ -27,10 +29,10 @@

#let or-gate-body = {
merge-path(close: true, {
arc((0.5, 0), -90deg, -30deg, anchor: "end", name: "bcurve")
arc((0.5,0), 30deg, 90deg, anchor: "start", name: "tcurve")
arc((0.5, 0), start: -90deg, stop: -30deg, anchor: "end", name: "bcurve")
arc((0.5,0), start: 30deg, stop: 90deg, anchor: "start", name: "tcurve")
line("tcurve.end", (-0.5, 0.5))
arc((), -30deg, 30deg, anchor: "end")
arc((), start: 30deg, stop: -30deg, anchor: "start")
})

// x coordinate of where the input legs touch the body of the gate
Expand Down Expand Up @@ -62,7 +64,7 @@
}

#let xor-bar = {
arc((-0.6, -0.5), -30deg, 30deg)
arc((-0.6, -0.5), start: -30deg, stop: 30deg)
anchors((
"ibin 1": "bin 1",
"ibin 2": "bin 2",
Expand All @@ -75,4 +77,4 @@

#let logic-gate-legs = for a in ("in 1", "in 2", "out") {
line("b" + a, a)
}
}
4 changes: 4 additions & 0 deletions typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "circuitypst"
version = "0.0.1"
entrypoint = "circuitypst.typ"
7 changes: 4 additions & 3 deletions utils.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "../typst-canvas/vector.typ"
#import "../typst-canvas/draw.typ": anchor
#import "@preview/cetz:0.0.1"
#import cetz.draw: anchor, vector


#let vector-dist(v1, v2) = {
return calc.abs(
Expand Down Expand Up @@ -56,4 +57,4 @@
for (k, v) in anchors {
anchor(k, v)
}
}
}