Wie gut kennen Sie sich mit Box Shadows aus?
Was ist ein Box Shadow?
- Ein Box Shadow ist eine Art von Drop Shadow und eine Form von Bildfilter
- Ein Drop Shadow ist ein Filter, der die Pixel eines Bildes entlang der x- und y-Achse verschiebt, um einen Schatteneffekt zu erzeugen
- In CSS kann ein Drop Shadow mit der Eigenschaft
filter angewendet werden
div {
filter: drop-shadow(xOffset yOffset rgba(0, 0, 0, 0.5));
}
- CSS unterstützt zusätzlich einen Blur-Wert, der auf den Drop Shadow angewendet werden kann
div {
filter: drop-shadow(xOffset yOffset blurSize rgba(0, 0, 0, 0.5));
}
Box Shadow
- Ein Box Shadow ist eine Art von Drop-Filter, der nur Box-Formen unterstützt
- Ein Box Shadow ist in Bezug auf die Performance vorteilhaft
- Die CSS-Implementierung von Box Shadows nutzt mathematische Hacks, um abgerundete Boxen kostengünstig zu zeichnen
- Durch das Layering mehrerer Box Shadows lassen sich verschiedene Designs erstellen
function randomizeAndColor(e) {
randomize(e);
const spread = Math.random() > 0.8 ? 2 : 0;
const x1 = Math.floor(3 - Math.random() * 6) / (1 + spread);
const y1 = Math.floor(3 - Math.random() * 6) / (1 + spread);
const y2 = 2 + Math.floor(Math.random() * 4);
const blur2 = 8 + Math.floor(Math.random() * 12);
e.style.boxShadow = `${x1}px ${y1}px 0px ${spread}px ${getRandomPastelColor()}, 0 ${y2}px ${blur2}px #0006`;
}
So verwendet man Box Shadows falsch
- Im Allgemeinen platzieren Designer Rechtecke mit konsistenten Margins, Paddings und Typografie
- Mit Box Shadows lassen sich künstlerische Effekte in verschiedensten Formen erzeugen
- Mit Box Shadows können Animationseffekte umgesetzt werden
const tick = (timestamp: number) => {
gameState.frame++;
gameState.deltaTime = Math.min((timestamp - gameState.prevFrameStartTime) / 1000, 0.1);
gameState.prevFrameStartTime = timestamp;
update(gameState);
render(gameState);
winContext._gameFrame = window.requestAnimationFrame(tick);
};
So verwendet man Box Shadows richtig falsch
- Mit Box Shadows lassen sich 3D-Effekte erzeugen
- Es lassen sich Animationen mit springenden Bällen erstellen
- Mit Box Shadows können Punktwolken gezeichnet werden
const pixels = await getImagePixels("/images/starry_night_full.jpg", width);
const dx = window.innerWidth / pixels[0].length;
const dy = window.innerHeight / pixels.length;
for (let y = 0; y < pixels.length; y++) {
for (let x = 0; x < pixels[0].length; x++) {
const px = x * dx + dx / 2, py = y * dy + dy / 2, pz = 60 + Math.random() * 3;
state.particles.push({ size: pSize, x: px, y: py, z: pz, ox: px, oy: py, oz: pz, dx: Math.random() * 3, dy: Math.random() * 3, dz: Math.random() * 3, color: pixels[y][x] });
}
}
Ray Tracing mit Box Shadows
- Ray Tracing ist eine präzise, aber langsame Methode der Bilderzeugung
- Ray Tracing lässt sich mit Box Shadows umsetzen
- Mit Web Workern kann Multithreading implementiert werden
const gameState = {
frame: 0,
prevFrameStartTime: 0,
deltaTime: 0,
renderContainerSize: 32,
cam: new PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 100),
spheres: [
{ position: new Vector3(0, 1.3, 0), radius: 1.3, material: CreateMat({ color: new Color(1, 0.2, 0.3) }) },
{ position: new Vector3(-3, 1.3, 0), radius: 1.3, material: CreateMat({ color: new Color(0.9, 0.9, 0.9), smoothness: 0.9 }) },
{ position: new Vector3(0, 10.8, 0), radius: 3.6, material: CreateMat({ color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveStrength: 8 }) }
]
};
# GN⁺-Zusammenfassung
- Box Shadows sind eine Art von Drop Shadow und nützlich, um Bildern mehr Tiefenwirkung zu verleihen
- Mit CSS lassen sich verschiedene Box-Shadow-Effekte umsetzen, mit denen kreative Designs erstellt werden können
- Mit Box Shadows können 3D-Effekte und Animationen umgesetzt werden
- Ray Tracing mit Box Shadows ist ineffizient, aber möglich
- Der Artikel untersucht kreative und unkonventionelle Einsatzmöglichkeiten von Box Shadows und zeigt dadurch neue Designmöglichkeiten auf
Noch keine Kommentare.