From 6af5f8dc4f15a324500465f4de5b29a67889196d Mon Sep 17 00:00:00 2001 From: NinoReichardt Date: Sat, 14 Nov 2026 21:22:42 +0100 Subject: feat: local font, trees without p5.js --- assets/fonts/OFL.txt | 93 +++++++++++++ assets/fonts/inter-latin-v20.woff2 | Bin 0 -> 73016 bytes assets/main.css | 9 ++ assets/trees.js | 276 ++++++++++++++++++++----------------- 4 files changed, 253 insertions(+), 125 deletions(-) create mode 100644 assets/fonts/OFL.txt create mode 100644 assets/fonts/inter-latin-v20.woff2 (limited to 'assets') diff --git a/assets/fonts/OFL.txt b/assets/fonts/OFL.txt new file mode 100644 index 0000000..21f6aff --- /dev/null +++ b/assets/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/inter-latin-v20.woff2 b/assets/fonts/inter-latin-v20.woff2 new file mode 100644 index 0000000..937631c Binary files /dev/null and b/assets/fonts/inter-latin-v20.woff2 differ diff --git a/assets/main.css b/assets/main.css index 740d495..3b283c8 100644 --- a/assets/main.css +++ b/assets/main.css @@ -1,3 +1,12 @@ +@font-face { + font-family: "Inter"; + font-style: normal; + font-weight: 100 900; + font-display: swap; + src: url("./fonts/inter-latin-v20.woff2") format("woff2"); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} + * { font-family: "Inter", sans-serif; font-optical-sizing: auto; diff --git a/assets/trees.js b/assets/trees.js index 74d3c44..8cb84b3 100644 --- a/assets/trees.js +++ b/assets/trees.js @@ -1,132 +1,158 @@ -const R_10 = Math.PI / 18; -const R_90 = Math.PI / 2; -const R_180 = Math.PI; - -const BRANCH_LENGTH = 5; -const BRANCH_START = 20; -const MAX_CHILDREN = 3; -const CHILD_CHANGE = 0.4; -const CHANCE_DEGRADATION = 4000; -const NEXT_SOFT_CAP = 400; -const BRANCH_MAX_ANGLE = R_10; -const BRANCH_STAY_CHANCE = 0.5; -const BRANCH_LIMIT_PADDING = 24 - -let current = []; -let next = []; -let cycle = 0; - - -function setup() { - const canvas = createCanvas(windowWidth, windowHeight); - canvas.parent("renderer"); - frameRate(30); - background("#05050500"); - stroke(127, 127, 127, 20); - smooth(); - - cycle = 0; - current = []; - next = []; - - const start = (x, y, r) => { - for (let i = 0; i < BRANCH_START; i++) { - let length = Math.random() * BRANCH_LENGTH; - let angle = - r + Math.random() * (BRANCH_MAX_ANGLE - BRANCH_MAX_ANGLE * -1) + BRANCH_MAX_ANGLE * -1; - - current.push({ - x, - y, - x2: x + length * Math.cos(angle), - y2: y + length * Math.sin(angle), - angle, - }); - } - }; - - start( - (Math.random() * 0.6 + 0.2) * windowWidth, - windowHeight + BRANCH_LENGTH, - -R_90, - ); - start( - windowWidth + BRANCH_LENGTH, - (Math.random() * 0.6 + 0.2) * windowHeight, - R_180, - ); - start( - 0 - BRANCH_LENGTH, - (Math.random() * 0.6 + 0.2) * windowHeight, - -R_90 * 4, - ); - start((Math.random() * 0.6 + 0.2) * windowWidth, 0 - BRANCH_LENGTH, R_90); -} - -function draw() { - let currentLen = current.length; - while (currentLen--) { - let index = Math.floor(Math.random() * currentLen); - let branch = current[index]; - current.splice(index, 1); - - // queue branch for next cycle - if (Math.random() <= BRANCH_STAY_CHANCE) { - next.push(branch); - continue; - } - - // draw branch - line(branch.x, branch.y, branch.x2, branch.y2); - - // stop if soft cap is reached - if (next.length >= NEXT_SOFT_CAP) continue; +(() => { + const renderer = document.getElementById("renderer"); + if (!renderer) return; + + const canvas = document.createElement("canvas"); + const context = canvas.getContext("2d"); + if (!context) return; + + const R_10 = Math.PI / 18; + const R_90 = Math.PI / 2; + const R_180 = Math.PI; + + const BRANCH_LENGTH = 5; + const BRANCH_START = 20; + const MAX_CHILDREN = 3; + const CHILD_CHANGE = 0.4; + const CHANCE_DEGRADATION = 4000; + const NEXT_SOFT_CAP = 400; + const BRANCH_MAX_ANGLE = R_10; + const BRANCH_STAY_CHANCE = 0.5; + const BRANCH_LIMIT_PADDING = 24; + const FRAME_INTERVAL = 1000 / 30; + + let current = []; + let next = []; + let cycle = 0; + let width; + let height; + let lastFrameTime; + + function setup() { + width = window.innerWidth; + height = window.innerHeight; + const pixelRatio = window.devicePixelRatio || 1; + + canvas.width = Math.floor(width * pixelRatio); + canvas.height = Math.floor(height * pixelRatio); + canvas.style.width = width + "px"; + canvas.style.height = height + "px"; + canvas.setAttribute("aria-hidden", "true"); + context.scale(pixelRatio, pixelRatio); + context.strokeStyle = "rgba(127, 127, 127, " + 20 / 255 + ")"; + context.lineWidth = 1; + context.lineCap = "round"; + renderer.appendChild(canvas); + + const start = (x, y, r) => { + for (let i = 0; i < BRANCH_START; i++) { + let length = Math.random() * BRANCH_LENGTH; + let angle = + r + Math.random() * (BRANCH_MAX_ANGLE - BRANCH_MAX_ANGLE * -1) + BRANCH_MAX_ANGLE * -1; + + current.push({ + x, + y, + x2: x + length * Math.cos(angle), + y2: y + length * Math.sin(angle), + angle, + }); + } + }; + + start( + (Math.random() * 0.6 + 0.2) * width, + height + BRANCH_LENGTH, + -R_90, + ); + start( + width + BRANCH_LENGTH, + (Math.random() * 0.6 + 0.2) * height, + R_180, + ); + start( + 0 - BRANCH_LENGTH, + (Math.random() * 0.6 + 0.2) * height, + -R_90 * 4, + ); + start((Math.random() * 0.6 + 0.2) * width, 0 - BRANCH_LENGTH, R_90); + } - if ( - branch.x2 > width + BRANCH_LIMIT_PADDING || - branch.x2 < -BRANCH_LIMIT_PADDING && - branch.y2 > height + BRANCH_LIMIT_PADDING || - branch.y2 < -BRANCH_LIMIT_PADDING - ) { - // stop if out of bounds - continue; + function draw() { + let currentLen = current.length; + while (currentLen--) { + let index = Math.floor(Math.random() * currentLen); + let branch = current[index]; + current.splice(index, 1); + + // Queue branch for next cycle. + if (Math.random() <= BRANCH_STAY_CHANCE) { + next.push(branch); + continue; + } + + context.beginPath(); + context.moveTo(branch.x, branch.y); + context.lineTo(branch.x2, branch.y2); + context.stroke(); + + // Stop if soft cap is reached. + if (next.length >= NEXT_SOFT_CAP) continue; + + if ( + branch.x2 > width + BRANCH_LIMIT_PADDING || + branch.x2 < -BRANCH_LIMIT_PADDING && + branch.y2 > height + BRANCH_LIMIT_PADDING || + branch.y2 < -BRANCH_LIMIT_PADDING + ) { + continue; + } + + let amount = MAX_CHILDREN; + + while (amount--) { + if (Math.random() > CHILD_CHANGE - cycle / CHANCE_DEGRADATION) continue; + + let length = Math.random() * BRANCH_LENGTH; + let sx = branch.x2 + 1 * Math.cos(branch.angle); + let sy = branch.y2 + 1 * Math.sin(branch.angle); + let angle = + branch.angle + + Math.random() * (BRANCH_MAX_ANGLE - BRANCH_MAX_ANGLE * -1) + + BRANCH_MAX_ANGLE * -1; + let ex = branch.x2 + length * Math.cos(angle); + let ey = branch.y2 + length * Math.sin(angle); + + next.push({ + x: sx, + y: sy, + x2: ex, + y2: ey, + angle, + }); + } } - let amount = MAX_CHILDREN; - - while (amount--) { - if (Math.random() > CHILD_CHANGE - cycle / CHANCE_DEGRADATION) continue; - - let length = Math.random() * BRANCH_LENGTH; - - // starting cordinates - let sx = branch.x2 + 1 * Math.cos(branch.angle); - let sy = branch.y2 + 1 * Math.sin(branch.angle); - - let angle = - branch.angle + - Math.random() * (BRANCH_MAX_ANGLE - BRANCH_MAX_ANGLE * -1) + - BRANCH_MAX_ANGLE * -1; - - // ending cordinates - let ex = branch.x2 + length * Math.cos(angle); - let ey = branch.y2 + length * Math.sin(angle); - - next.push({ - x: sx, - y: sy, - x2: ex, - y2: ey, - angle, - }); - } + current = next; + next = []; + cycle++; } - if (next.length == 0) { - noLoop(); + function animate(timestamp) { + const elapsed = timestamp - lastFrameTime; + if (elapsed >= FRAME_INTERVAL) { + lastFrameTime = timestamp - (elapsed % FRAME_INTERVAL); + draw(); + } + if (current.length > 0) requestAnimationFrame(animate); } - current = next; - next = []; - cycle++; -} + // Let the page paint before starting the decorative canvas. + requestAnimationFrame(() => { + requestAnimationFrame((timestamp) => { + setup(); + lastFrameTime = timestamp; + requestAnimationFrame(animate); + }); + }); +})(); -- cgit v1.2.3