Created
August 27, 2025 02:29
-
-
Save VincentTam/5b8219764f9b2c193c2bacfe7aa4c35a to your computer and use it in GitHub Desktop.
Cantor set & function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set page(height: auto, width: auto, margin: 1em) | |
#import "@preview/cetz:0.4.1" | |
#let n = 4 | |
#let vsep = 1 | |
#let width = 1 | |
#let lefts = range(2, n + 1).fold( | |
((1/3,),), | |
(a, e) => (..a, a.last().map(x => (x - 2*calc.pow(1/3, e), x + 4*calc.pow(1/3, e))).flatten()) | |
) | |
#cetz.canvas({ | |
import cetz.draw: * | |
let seglen = 1 * width | |
let seghei = vsep | |
let segsep = 2*vsep | |
for i in range(0, n) { | |
seglen /= 3 | |
seghei /= 2 | |
segsep /= 2 | |
let points = lefts.at(i) | |
for j in range(0, points.len()) { | |
let point = points.at(j) * width | |
seghei += segsep | |
line((point, seghei), (point + seglen, seghei), stroke: (paint: blue, thickness: 0.2pt)) | |
} | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set page(height: auto, width: auto, margin: 1em) | |
#import "@preview/cetz:0.4.1" | |
#let n = 2 | |
#let vsep = 0.2 | |
#let width = 3.2 | |
#let lefts = range(1, n + 1).fold( | |
((0,),), | |
(a, e) => (..a, a.last().zip(a.last().map(x => x + 2*calc.pow(1/3, e))).flatten()) | |
) | |
#cetz.canvas({ | |
import cetz.draw: * | |
let seglen = 3 * width | |
for i in range(0, n + 1) { | |
seglen /= 3 | |
let points = lefts.at(i) | |
for j in range(0, points.len()) { | |
let point = points.at(j) * width | |
line((point, -i*vsep), (point + seglen, -i*vsep), stroke: blue) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment