Houdini CSS를 사용한 별 배경
그것은 별의 수와 주어진 별의 최대 크기의 두 가지 속성을 취합니다. 다음과 같이 사용할 수 있습니다
.container {
background: paint(stars), #282828;
--star-count: 3500;
--star-max-size: 0.5;
}
실제 worklet 코드는 다음과 같습니다.
class Stars {
static get inputProperties() {
return ['--star-count', '--star-max-size'];
}
getRandom(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
paint(ctx, geom, props) {
const count = parseInt(props.get('--star-count').toString());
const maxSize = parseInt(props.get('--star-max-size').toString());
const colorrange = [0, 60, 240];
for (let i = 0; i < count; i++) {
const x = Math.random() * geom.width;
const y = Math.random() * geom.height;
const radius = maxSize ? this.getRandom(1, maxSize) : Math.random() * 1.2;
const hue = colorrange[this.getRandom(0, colorrange.length - 1)];
const sat = this.getRandom(50, 100);
ctx.beginPath();
ctx.arc(x, y, radius, 0, 360);
ctx.fillStyle = 'hsl(' + hue + ', ' + sat + '%, 88%)';
ctx.fill();
ctx.closePath();
}
}
}
registerPaint('stars', Stars);
here이 호스팅되고 여기에 source code이 있습니다.
Reference
이 문제에 관하여(Houdini CSS를 사용한 별 배경), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/rafi993/star-background-using-houdini-css-2dog텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)