-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathwaves.typ
40 lines (34 loc) · 1.05 KB
/
waves.typ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import "@preview/cetz:0.3.2": canvas, draw, vector, matrix
#set page(width: auto, height: auto, margin: .5cm)
#canvas({
import draw: *
ortho(y: -30deg, x: 30deg, {
on-xz({
grid((0,-2), (8,2), stroke: gray + .5pt)
})
// Draw a sine wave on the xy plane
let wave(amplitude: 1, fill: none, phases: 2, scale: 8, samples: 100) = {
line(..(for x in range(0, samples + 1) {
let x = x / samples
let p = (2 * phases * calc.pi) * x
((x * scale, calc.sin(p) * amplitude),)
}), fill: fill)
let subdivs = 8
for phase in range(0, phases) {
let x = phase / phases
for div in range(1, subdivs + 1) {
let p = 2 * calc.pi * (div / subdivs)
let y = calc.sin(p) * amplitude
let x = x * scale + div / subdivs * scale / phases
line((x, 0), (x, y), stroke: rgb(0, 0, 0, 150) + .5pt)
}
}
}
on-xy({
wave(amplitude: 1.6, fill: rgb(0, 0, 255, 50))
})
on-xz({
wave(amplitude: 1, fill: rgb(255, 0, 0, 50))
})
})
})