update example brushes; add builtin/dashes

This commit is contained in:
りき萌 2025-06-30 23:54:50 +02:00
parent 9de4a8aecd
commit 731046d1f7

View file

@ -11,8 +11,8 @@ export const builtInPresets = [
code: ` code: `
-- Try playing around with the values -- Try playing around with the values
-- and see what happens! -- and see what happens!
color = #000 color: #000
thickness = 8 thickness: 8
withDotter \\d -> withDotter \\d ->
stroke thickness color (line (d From) (d To)) stroke thickness color (line (d From) (d To))
@ -23,20 +23,42 @@ withDotter \\d ->
id: "builtin/thick", id: "builtin/thick",
name: "Thick", name: "Thick",
code: ` code: `
color = #000 color: #000
thickness = 48 thickness: 48
withDotter \\d -> withDotter \\d ->
stroke thickness color (line (d From) (d To)) stroke thickness color (line (d From) (d To))
`.trim(), `.trim(),
}, },
{
id: "builtin/dashes",
name: "Dashes",
code: `
color: #000
thickness: 4
length: 5
duty: 0.5
or_: \\a, b ->
if (a) a
else b
withDotter \\d ->
visible = mod (d Num) length < length * duty
if (visible)
stroke thickness color (line (d From) (d To))
else
()
`.trim(),
},
{ {
id: "builtin/pencil", id: "builtin/pencil",
name: "Pencil", name: "Pencil",
code: ` code: `
color = #0003 color: #0003
thickness = 6 thickness: 6
withDotter \\d -> withDotter \\d ->
stroke thickness color (line (d From) (d To)) stroke thickness color (line (d From) (d To))
@ -47,16 +69,16 @@ withDotter \\d ->
id: "builtin/woobly", id: "builtin/woobly",
name: "Woobly", name: "Woobly",
code: ` code: `
color = #000 color: #000
minThickness = 8 minThickness: 8
maxThickness = 20 maxThickness: 20
wavelength = 1 wavelength: 1
withDotter \\d -> withDotter \\d ->
let pi = 3.14159265 pi = 3.14159265
let a = (sin (d Num * wavelength / pi) + 1) / 2 a = (sin (d Num * wavelength / pi) + 1) / 2
let range = maxThickness - minThickness range = maxThickness - minThickness
let thickness = minThickness + a * range thickness = minThickness + a * range
stroke thickness color (line (d From) (d To)) stroke thickness color (line (d From) (d To))
`.trim(), `.trim(),
}, },
@ -65,28 +87,28 @@ withDotter \\d ->
id: "builtin/wavy", id: "builtin/wavy",
name: "Wavy", name: "Wavy",
code: ` code: `
color = #000 color: #000
thickness = 4 thickness: 4
amplitude = 50 amplitude: 50
wavelength = 1 wavelength: 1
mag = \\v -> mag: \\v ->
hypot (vecX v) (vecY v) hypot (vecX v) (vecY v)
norm = \\u -> norm: \\u ->
let l = mag u l = mag u
u / vec l l u / vec l l
perpClockwise = \\v -> perpClockwise: \\v ->
vec (vecY v) (-(vecX v)) vec (vecY v) (-(vecX v))
withDotter \\d -> withDotter \\d ->
let pi = 3.14159265 pi = 3.14159265
let a = sin (d Num * wavelength / pi) * amplitude a = sin (d Num * wavelength / pi) * amplitude
let direction = (d To) - (d From) direction = (d To) - (d From)
let clockwise = norm (perpClockwise direction) * vec a a clockwise = norm (perpClockwise direction) * vec a a
let from = d From + clockwise from = d From + clockwise
let to = d To + clockwise to = d To + clockwise
stroke thickness color (line from to) stroke thickness color (line from to)
`.trim(), `.trim(),
}, },
@ -95,19 +117,19 @@ withDotter \\d ->
id: "builtin/rainbow", id: "builtin/rainbow",
name: "Rainbow", name: "Rainbow",
code: ` code: `
wavelength = 0.1 wavelength: 0.1
thickness = 8 thickness: 8
colorCurve = \\n -> colorCurve: \\n ->
abs (cos n) abs (cos n)
withDotter \\d -> withDotter \\d ->
let pi = 3.14159265 pi = 3.14159265
let l = wavelength l = wavelength
let r = colorCurve (d Num * l) r = colorCurve (d Num * l)
let g = colorCurve (d Num * l + pi/3) g = colorCurve (d Num * l + pi/3)
let b = colorCurve (d Num * l + 2*pi/3) b = colorCurve (d Num * l + 2*pi/3)
let color = rgba r g b 1 color = rgba r g b 1
stroke thickness color (line (d From) (d To)) stroke thickness color (line (d From) (d To))
`.trim(), `.trim(),
}, },