|
| 1 | +# czbloch |
| 2 | + |
| 3 | +Draw Bloch spheres in Typst with configurable state vectors, axes, angle annotations, and sphere styles. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Quick Start |
| 8 | + |
| 9 | +```typst |
| 10 | +#import "@preview/czbloch:0.1.0" |
| 11 | +
|
| 12 | +#set page(width: auto, height: auto, margin: 8pt) |
| 13 | +
|
| 14 | += Basic States |
| 15 | +
|
| 16 | +#stack( |
| 17 | + dir: ltr, |
| 18 | + spacing: 16pt, |
| 19 | + czbloch.bloch(..czbloch.zero), |
| 20 | + czbloch.bloch(..czbloch.one), |
| 21 | + czbloch.bloch(..czbloch.plus), |
| 22 | + czbloch.bloch(..czbloch.minus), |
| 23 | +) |
| 24 | +``` |
| 25 | + |
| 26 | +## API |
| 27 | + |
| 28 | +### `bloch(...)` |
| 29 | + |
| 30 | +Main drawing function. |
| 31 | + |
| 32 | +```typst |
| 33 | +#czbloch.bloch( |
| 34 | + length: 2cm, |
| 35 | + radius: 1, |
| 36 | + debug: false, |
| 37 | + padding: none, |
| 38 | + show-axis: true, |
| 39 | + phi: 0deg, |
| 40 | + theta: 0deg, |
| 41 | + state-color: rgb("#ae3fee"), |
| 42 | + sphere-style: "circle", |
| 43 | + angle-labels: true, |
| 44 | + polar-labels: true, |
| 45 | +) |
| 46 | +``` |
| 47 | + |
| 48 | +Parameters: |
| 49 | + |
| 50 | +- `length`: Final rendered canvas size. |
| 51 | +- `radius`: Logical radius of the Bloch sphere inside the canvas. |
| 52 | +- `debug`: Enables CeTZ debug rendering. |
| 53 | +- `padding`: CeTZ canvas padding. |
| 54 | +- `show-axis`: Draw Cartesian axes and labels. |
| 55 | +- `phi`: Azimuthal angle of the state vector. |
| 56 | +- `theta`: Polar angle of the state vector. |
| 57 | +- `state-color`: Stroke/fill color for the state arrow. |
| 58 | +- `sphere-style`: `"circle"`, `"sphere"`, or `none`. |
| 59 | +- `angle-labels`: Show `phi` and `theta` labels. |
| 60 | +- `polar-labels`: Show `|0>` and `|1>` pole labels. |
| 61 | + |
| 62 | +### Presets |
| 63 | + |
| 64 | +Useful preset states exported by the package: |
| 65 | + |
| 66 | +- `czbloch.zero`: `(phi: 0deg, theta: 0deg)` |
| 67 | +- `czbloch.one`: `(phi: 0deg, theta: 180deg)` |
| 68 | +- `czbloch.plus`: `(phi: 0deg, theta: 90deg)` |
| 69 | +- `czbloch.minus`: `(phi: 180deg, theta: 90deg)` |
| 70 | + |
| 71 | +Use with argument spread: |
| 72 | + |
| 73 | +```typst |
| 74 | +#czbloch.bloch(..czbloch.plus, state-color: green) |
| 75 | +``` |
| 76 | + |
| 77 | +## More Examples |
| 78 | + |
| 79 | +```typst |
| 80 | +#import "@preview/czbloch:0.1.0" as czbloch |
| 81 | +
|
| 82 | +#stack( |
| 83 | + dir: ttb, |
| 84 | + spacing: 12pt, |
| 85 | +
|
| 86 | + // Sphere-style shading |
| 87 | + czbloch.bloch(..czbloch.one, sphere-style: "sphere"), |
| 88 | +
|
| 89 | + // Custom state |
| 90 | + czbloch.bloch( |
| 91 | + phi: 50deg, |
| 92 | + theta: 30deg, |
| 93 | + state-color: orange, |
| 94 | + angle-labels: false, |
| 95 | + ), |
| 96 | +
|
| 97 | + // Wrapped angles are supported |
| 98 | + czbloch.bloch( |
| 99 | + phi: -10deg, |
| 100 | + theta: 240deg, |
| 101 | + sphere-style: "sphere", |
| 102 | + ), |
| 103 | +) |
| 104 | +``` |
0 commit comments