Skip to content

Commit 6bb5cf8

Browse files
committed
add organic-molecule.typ converted from Latex and add 3d shading via radial gradient to assets/sublattice-points/sublattice-points.typ
1 parent d22e74c commit 6bb5cf8

File tree

3 files changed

+253
-6
lines changed

3 files changed

+253
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
#import "@preview/cetz:0.3.4": canvas, draw
2+
#import draw: circle, content, line, on-layer
3+
4+
#set page(width: auto, height: auto, margin: 5pt)
5+
6+
// Atom with 3D shading effect
7+
#let atom(pos, color, element, radius: 0.3, name: none) = {
8+
// Base circle with main color
9+
circle(
10+
pos,
11+
radius: radius,
12+
stroke: none,
13+
fill: color,
14+
name: name,
15+
)
16+
17+
// Gradient overlay for 3D effect
18+
circle(
19+
pos,
20+
radius: radius,
21+
stroke: none,
22+
fill: gradient.radial(
23+
color.lighten(85%),
24+
color,
25+
color.darken(25%),
26+
focal-center: (25%, 20%),
27+
focal-radius: 10%,
28+
center: (30%, 25%),
29+
),
30+
)
31+
32+
// Add element label
33+
let text-color = if color == rgb("#333333") { white } else { black }
34+
35+
// Calculate text size based on radius
36+
let text-size = if radius < 0.4 { 10pt } else { 14pt }
37+
38+
content(
39+
pos,
40+
text(fill: text-color, weight: "bold", size: text-size)[#element],
41+
anchor: "center",
42+
)
43+
}
44+
45+
#canvas({
46+
// Define atom colors
47+
let hydrogen-color = rgb("#eee")
48+
let carbon-color = rgb("#333")
49+
let nitrogen-color = rgb("#3333cc")
50+
let oxygen-color = red.darken(10%)
51+
52+
// Define atom sizes - increased to match target image
53+
let h-radius = 0.35
54+
let heavy-radius = 0.5
55+
56+
// Adjust hydrogen positions to be further from connected atoms
57+
// Original positions from LaTeX
58+
let orig-h-positions = (
59+
("H1", (-2.9, 1.39)),
60+
("H2", (-3.5, 1.23)),
61+
("H3", (-3.8, 0.15)),
62+
("H4", (-1.7, -0.6)),
63+
("H5", (-0.3, 1.4)),
64+
("H6", (-1, 1.15)),
65+
("H7", (0, -0.7)),
66+
("H8", (1, -1.82)),
67+
("H9", (0.2, -1.8)),
68+
("H10", (3.5, 0.5)),
69+
)
70+
71+
// Heavy atom positions
72+
let c-positions = (
73+
("C1", (-3.19, 0.68)),
74+
("C2", (-0.78, 0.67)),
75+
("C3", (0.47, -0.18)),
76+
("C4", (1.73, 0.67)),
77+
)
78+
79+
let n-positions = (
80+
("N1", (-2.00, -0.15)),
81+
("N2", (0.51, -1.32)),
82+
)
83+
84+
let o-positions = (
85+
("O1", (1.80, 1.88)),
86+
("O2", (2.86, -0.07)),
87+
)
88+
89+
// Function to move hydrogen atoms further from their connected atoms
90+
let adjust-h-position(h-pos, connected-pos, factor: 1.5) = {
91+
let (hx, hy) = h-pos
92+
let (cx, cy) = connected-pos
93+
let dx = hx - cx
94+
let dy = hy - cy
95+
let dist = calc.sqrt(dx * dx + dy * dy)
96+
let new-dist = dist * factor
97+
let scale = new-dist / dist
98+
(cx + dx * scale, cy + dy * scale)
99+
}
100+
101+
// Connection map: which hydrogen connects to which heavy atom
102+
let h-connections = (
103+
"H1": "C1",
104+
"H2": "C1",
105+
"H3": "C1",
106+
"H4": "N1",
107+
"H5": "C2",
108+
"H6": "C2",
109+
"H7": "C3",
110+
"H8": "N2",
111+
"H9": "N2",
112+
"H10": "O2",
113+
)
114+
115+
// Combine all heavy atom positions for lookup
116+
let heavy-atoms = (:)
117+
for (name, pos) in c-positions { heavy-atoms.insert(name, pos) }
118+
for (name, pos) in n-positions { heavy-atoms.insert(name, pos) }
119+
for (name, pos) in o-positions { heavy-atoms.insert(name, pos) }
120+
121+
// Adjust hydrogen positions
122+
let h-positions = (:)
123+
for (name, pos) in orig-h-positions {
124+
let connected-atom = h-connections.at(name)
125+
let connected-pos = heavy-atoms.at(connected-atom)
126+
h-positions.insert(name, adjust-h-position(pos, connected-pos))
127+
}
128+
129+
// Further adjust overlapping hydrogens
130+
// Adjust H1 and H2 which overlap in the top left
131+
let h1-pos = h-positions.at("H1")
132+
let h2-pos = h-positions.at("H2")
133+
h-positions.insert("H1", (h1-pos.at(0) - 0.2, h1-pos.at(1) + 0.2))
134+
h-positions.insert("H2", (h2-pos.at(0) - 0.2, h2-pos.at(1) - 0.2))
135+
136+
// Adjust H8 and H9 which overlap near the right N atom
137+
let h8-pos = h-positions.at("H8")
138+
let h9-pos = h-positions.at("H9")
139+
h-positions.insert("H8", (h8-pos.at(0) + 0.3, h8-pos.at(1) - 0.2))
140+
h-positions.insert("H9", (h9-pos.at(0) - 0.3, h9-pos.at(1) - 0.2))
141+
142+
// Draw all atoms
143+
// Draw carbon atoms
144+
for (name, pos) in c-positions {
145+
atom(pos, carbon-color, "C", radius: heavy-radius, name: name)
146+
}
147+
148+
// Draw nitrogen atoms
149+
for (name, pos) in n-positions {
150+
atom(pos, nitrogen-color, "N", radius: heavy-radius, name: name)
151+
}
152+
153+
// Draw oxygen atoms
154+
for (name, pos) in o-positions {
155+
atom(pos, oxygen-color, "O", radius: heavy-radius, name: name)
156+
}
157+
158+
// Draw hydrogen atoms
159+
for (name, pos) in h-positions {
160+
atom(pos, hydrogen-color, "H", radius: h-radius, name: name)
161+
}
162+
163+
// Draw bonds on a background layer (behind atoms)
164+
on-layer(
165+
-1,
166+
{
167+
// Main chain
168+
let bond-chain = ("H1", "C1", "N1", "C2", "C3", "C4", "O1")
169+
for i in range(bond-chain.len() - 1) {
170+
let from = bond-chain.at(i)
171+
let to = bond-chain.at(i + 1)
172+
173+
let from-pos = if from.starts-with("H") {
174+
h-positions.at(from)
175+
} else {
176+
heavy-atoms.at(from)
177+
}
178+
179+
let to-pos = if to.starts-with("H") {
180+
h-positions.at(to)
181+
} else {
182+
heavy-atoms.at(to)
183+
}
184+
185+
line(
186+
from-pos,
187+
to-pos,
188+
stroke: (paint: gray, thickness: 3.5pt),
189+
)
190+
}
191+
192+
// Additional bonds
193+
let additional-bonds = (
194+
("H2", "C1"),
195+
("H3", "C1"),
196+
("N1", "H4"),
197+
("C2", "H5"),
198+
("C2", "H6"),
199+
("C3", "H7"),
200+
("C3", "N2"),
201+
("N2", "H8"),
202+
("N2", "H9"),
203+
("C4", "O2"),
204+
("O2", "H10"),
205+
)
206+
207+
for (from, to) in additional-bonds {
208+
let from-pos = if from.starts-with("H") {
209+
h-positions.at(from)
210+
} else {
211+
heavy-atoms.at(from)
212+
}
213+
214+
let to-pos = if to.starts-with("H") {
215+
h-positions.at(to)
216+
} else {
217+
heavy-atoms.at(to)
218+
}
219+
220+
line(
221+
from-pos,
222+
to-pos,
223+
stroke: (paint: gray, thickness: 3.5pt),
224+
)
225+
}
226+
},
227+
)
228+
})

assets/sublattice-points/sublattice-points.typ

+22-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33

44
#set page(width: auto, height: auto, margin: 8pt)
55

6+
// Atom with 3D shading effect
7+
#let shaded-circle(pos, color, radius: 0.1, name: none, stroke: 0.2pt) = {
8+
circle(
9+
pos,
10+
radius: radius,
11+
stroke: stroke,
12+
fill: gradient.radial(
13+
color.lighten(85%),
14+
color,
15+
color.darken(25%),
16+
focal-center: (25%, 20%),
17+
focal-radius: 10%,
18+
center: (30%, 25%),
19+
),
20+
name: name,
21+
)
22+
}
23+
624
#canvas({
725
// Define styles and constants
826
let grid-size = 2 // number of points in each direction
@@ -29,11 +47,12 @@
2947
// Use modulo to cycle through colors
3048
let color-idx = calc.rem(ii - 2 * jj, colors.len())
3149
if color-idx < 0 { color-idx += colors.len() }
32-
circle(
50+
51+
// Use the shaded-circle function instead of regular circle
52+
shaded-circle(
3353
(x, y),
54+
colors.at(color-idx),
3455
radius: dot-radius * 1.2,
35-
fill: colors.at(color-idx),
36-
stroke: .5pt,
3756
name: str(ii) + "," + str(jj),
3857
)
3958
}

readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<h3 align="center">
1010

11-
[![92 with Typst](https://img.shields.io/badge/92%20with-Typst-1f425f.svg?logo=typst)](https://typst.app)
11+
[![94 with Typst](https://img.shields.io/badge/94%20with-Typst-1f425f.svg?logo=typst)](https://typst.app)
1212
[![112 with LaTeX](https://img.shields.io/badge/112%20with-LaTeX-1f425f.svg?logo=latex)](https://latex-project.org)
1313
[![Site](https://github.com/janosh/diagrams/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/janosh/diagrams/actions/workflows/gh-pages.yml)
1414
[![Pull Requests Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?logo=github)](https://github.com/janosh/diagrams/pulls)
@@ -72,7 +72,7 @@ Have a TikZ/Cetz diagram you'd like to share? [Submit a PR](https://github.com/j
7272
| ![`gravitons.png`](assets/gravitons/gravitons.png) | ![`harmonic-oscillator-energy-vs-freq.png`](assets/harmonic-oscillator-energy-vs-freq/harmonic-oscillator-energy-vs-freq.png) |
7373
| [`harmonic-oscillator-energy-vs-inv-temp`](https://janosh.github.io/diagrams/harmonic-oscillator-energy-vs-inv-temp) &nbsp;[![LaTeX][latex-logo]](assets/harmonic-oscillator-energy-vs-inv-temp/harmonic-oscillator-energy-vs-inv-temp.tex)&nbsp;[![Typst][typst-logo]](assets/harmonic-oscillator-energy-vs-inv-temp/harmonic-oscillator-energy-vs-inv-temp.typ) | [`heatmap`](https://janosh.github.io/diagrams/heatmap) &nbsp;[![LaTeX][latex-logo]](assets/heatmap/heatmap.tex)&nbsp;[![Typst][typst-logo]](assets/heatmap/heatmap.typ) |
7474
| ![`harmonic-oscillator-energy-vs-inv-temp.png`](assets/harmonic-oscillator-energy-vs-inv-temp/harmonic-oscillator-energy-vs-inv-temp.png) | ![`heatmap.png`](assets/heatmap/heatmap.png) |
75-
| [`higgs-potential`](https://janosh.github.io/diagrams/higgs-potential) &nbsp;[![LaTeX][latex-logo]](assets/higgs-potential/higgs-potential.tex) | [`high-entropy-alloy`](https://janosh.github.io/diagrams/high-entropy-alloy) &nbsp;[![LaTeX][latex-logo]](assets/high-entropy-alloy/high-entropy-alloy.tex) |
75+
| [`higgs-potential`](https://janosh.github.io/diagrams/higgs-potential) &nbsp;[![LaTeX][latex-logo]](assets/higgs-potential/higgs-potential.tex) | [`high-entropy-alloy`](https://janosh.github.io/diagrams/high-entropy-alloy) &nbsp;[![LaTeX][latex-logo]](assets/high-entropy-alloy/high-entropy-alloy.tex)&nbsp;[![Typst][typst-logo]](assets/high-entropy-alloy/high-entropy-alloy.typ) |
7676
| ![`higgs-potential.png`](assets/higgs-potential/higgs-potential.png) | ![`high-entropy-alloy.png`](assets/high-entropy-alloy/high-entropy-alloy.png) |
7777
| [`isotherms`](https://janosh.github.io/diagrams/isotherms) &nbsp;[![LaTeX][latex-logo]](assets/isotherms/isotherms.tex)&nbsp;[![Typst][typst-logo]](assets/isotherms/isotherms.typ) | [`jensens-inequality`](https://janosh.github.io/diagrams/jensens-inequality) &nbsp;[![LaTeX][latex-logo]](assets/jensens-inequality/jensens-inequality.tex)&nbsp;[![Typst][typst-logo]](assets/jensens-inequality/jensens-inequality.typ) |
7878
| ![`isotherms.png`](assets/isotherms/isotherms.png) | ![`jensens-inequality.png`](assets/jensens-inequality/jensens-inequality.png) |
@@ -98,7 +98,7 @@ Have a TikZ/Cetz diagram you'd like to share? [Submit a PR](https://github.com/j
9898
| ![`mosfet.png`](assets/mosfet/mosfet.png) | ![`normalizing-flow-coupling-layer.png`](assets/normalizing-flow-coupling-layer/normalizing-flow-coupling-layer.png) |
9999
| [`normalizing-flow`](https://janosh.github.io/diagrams/normalizing-flow) &nbsp;[![LaTeX][latex-logo]](assets/normalizing-flow/normalizing-flow.tex)&nbsp;[![Typst][typst-logo]](assets/normalizing-flow/normalizing-flow.typ) | [`open-string-topologies`](https://janosh.github.io/diagrams/open-string-topologies) &nbsp;[![LaTeX][latex-logo]](assets/open-string-topologies/open-string-topologies.tex) |
100100
| ![`normalizing-flow.png`](assets/normalizing-flow/normalizing-flow.png) | ![`open-string-topologies.png`](assets/open-string-topologies/open-string-topologies.png) |
101-
| [`operator-orderings`](https://janosh.github.io/diagrams/operator-orderings) &nbsp;[![LaTeX][latex-logo]](assets/operator-orderings/operator-orderings.tex) | [`organic-molecule`](https://janosh.github.io/diagrams/organic-molecule) &nbsp;[![LaTeX][latex-logo]](assets/organic-molecule/organic-molecule.tex) |
101+
| [`operator-orderings`](https://janosh.github.io/diagrams/operator-orderings) &nbsp;[![LaTeX][latex-logo]](assets/operator-orderings/operator-orderings.tex) | [`organic-molecule`](https://janosh.github.io/diagrams/organic-molecule) &nbsp;[![LaTeX][latex-logo]](assets/organic-molecule/organic-molecule.tex)&nbsp;[![Typst][typst-logo]](assets/organic-molecule/organic-molecule.typ) |
102102
| ![`operator-orderings.png`](assets/operator-orderings/operator-orderings.png) | ![`organic-molecule.png`](assets/organic-molecule/organic-molecule.png) |
103103
| [`otto-cycle`](https://janosh.github.io/diagrams/otto-cycle) &nbsp;[![LaTeX][latex-logo]](assets/otto-cycle/otto-cycle.tex)&nbsp;[![Typst][typst-logo]](assets/otto-cycle/otto-cycle.typ) | [`periodic-table`](https://janosh.github.io/diagrams/periodic-table) &nbsp;[![LaTeX][latex-logo]](assets/periodic-table/periodic-table.tex)&nbsp;[![Typst][typst-logo]](assets/periodic-table/periodic-table.typ) |
104104
| ![`otto-cycle.png`](assets/otto-cycle/otto-cycle.png) | ![`periodic-table.png`](assets/periodic-table/periodic-table.png) |

0 commit comments

Comments
 (0)