Skip to content

Commit

Permalink
waves: Use ortho function (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf authored Jan 2, 2025
1 parent aa12700 commit fe6b635
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
Binary file modified gallery/waves.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 26 additions & 25 deletions gallery/waves.typ
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
#canvas({
import draw: *

// Set up the transformation matrix
set-transform(matrix.transform-rotate-dir((1, 1, -1.3), (0, 1, .3)))
scale(x: 1.5, z: -1)
ortho(y: -30deg, x: 30deg, {
on-xz({
grid((0,-2), (8,2), stroke: gray + .5pt)
})

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)

// 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)
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)
}
}
}
}

group({
rotate(x: 90deg)
wave(amplitude: 1.6, fill: rgb(0, 0, 255, 50))
on-xy({
wave(amplitude: 1.6, fill: rgb(0, 0, 255, 50))
})
on-xz({
wave(amplitude: 1, fill: rgb(255, 0, 0, 50))
})
})
wave(amplitude: 1, fill: rgb(255, 0, 0, 50))
})

0 comments on commit fe6b635

Please sign in to comment.