圣诞节马上就要到了,不知道给自己喜欢的人准备什么样的惊喜吗?作为一名程序员,当然是用编程制作专属于她or他的圣诞树!
目录
圣诞树
✨3D圣诞树
代码块
打开方式
修改位置
效果展示
✨音乐律动圣诞树
代码块
打开方式
效果展示
✨灯光圣诞树
代码块
修改位置
效果展示
圣诞贺卡
祝福绘制圣诞贺卡
代码块
修改位置
效果展示
雪橇雪人圣诞贺卡
代码块
效果展示
祝福语圣诞贺卡
代码块
修改位置
效果展示
裏源码获取方式
一年一度的圣诞节马上就要到了,看到好多程序员小伙伴已经开始炫耀自己制作的圣诞树了。今天就跟大家分享多种不同风格的圣诞树和圣诞贺卡,附上完整代码,拿来即用可以按照自己的喜好来去运行使用哦。
圣诞树
✨3D圣诞树
代码块
html, body
{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
}
div
{
margin: 0;
padding: 0;
border: 0;
}
.nav
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 27px;
background-color: white;
color: black;
text-align: center;
line-height: 25px;
}
a
{
color: black;
text-decoration: none;
border-bottom: 1px dashed black;
}
a:hover
{
border-bottom: 1px solid red;
}
.previous
{
float: left;
margin-left: 10px;
}
.next
{
float: right;
margin-right: 10px;
}
.green
{
color: green;
}
.red
{
color: red;
}
textarea
{
width: 100%;
height: 100%;
border: 0;
padding: 0;
margin: 0;
padding-bottom: 20px;
}
.block-outer
{
float: left;
width: 22%;
height: 100%;
padding: 5px;
border-left: 1px solid black;
margin: 30px 3px 3px 3px;
}
.block-inner
{
height: 68%;
}
.one
{
border: 0;
}
var collapsed = true;
function toggle()
{
var fs = top.document.getElementsByTagName('frameset')[0];
var f = fs.getElementsByTagName('frame');
if (collapsed)
{
fs.rows = '250px,*';
fs.noResize = false;
f[0].noResize = false;
f[1].noResize = false;
}
else
{
fs.rows = '30px,*';
fs.noResize = true;
f[0].noResize = true;
f[1].noResize = true;
}
collapsed = !collapsed;
}
var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth;
M=Math;
Q=M.random;J=[];
U=16;
T=M.sin;
E=M.sqrt;
for(O=k=0;x=z=j=i=k<200;)
with(M[k]=k?c.cloneNode(0):c)
{
width=height=k?32:W=446;
with(getContext('2d'))
if(k>10|!k)
for(
font='60px Impact',
V='rgba(';I=i*U,fillStyle=k?k==13?V+'205,205,215,.15)':
V+(147+I)+','+(k%2?128+I:0)+','+I+',.5)':'#cca',i<7;)
beginPath(fill(arc(U-i/3,24-i/2,k==13?4-(i++)/2:8-i++,0,M.PI*2,1)));
else for(;
x=T(i),
y=Q()*2-1,
D=x*x+y*y,
B=E(D-x/.9-1.5*y+1),
R=67*(B+1)*(L=k/9+.8)>>1,
i++ ) if(D<1) beginPath(strokeStyle=V+R+','+(R+B*L>>0)+',40,.1)'), moveTo(U+x*8,U+y*8), lineTo(U+x*U,U+y*U), stroke(); for( y=H=k+E(k++)*25, R=Q()*W; P=3,j J[O++]=[ x+=T(R)*P+Q()*6-3,y+=Q()*U-8, z+=T(R-11)*P+Q()*6-3, j/H*20+((j+=U)>H&Q()>.8?Q(P=9)*4:0)>>1] } setInterval(function G(m,l) { A=T(D-11); if(l) return( m[2]-l[2])*A+(l[0]-m[0])*T(D); a.clearRect(0,0,W,W); J.sort(G); for( i=0; L=J[i++]; a.drawImage(M[L[3]+1],207+L[0]*A+L[2]*T(D)>>0,L[1]>>1)) { if(i==2e3) a.fillText //修改引号内的内容 ('Happy Christmas!',U,345); //例如: ('猪猪圣诞快乐!',U,345); if(!(i%7)) a.drawImage(M[13], ((157*(i*i)+T(D*5+i*i)*5)%W)>>0, ((113*i+(D*i)/60)%(290+i/99))>>0); } D+=.02 },1) 打开方式 新建文本文档----→将代码粘贴后保存----→将文件后缀改为html打开即可 注意事项:用记事本输入代码,然后更改格式为html,有些人的电脑会默认隐藏文件格式,这时候你要在此电脑的查看选项中,把已知文件类型的扩展名这个选项的✓给打开,这样就会显示你每个文件的具体格式了。 修改位置 //修改引号内的内容 ('Happy Christmas!',U,345); //例如: ('猪猪圣诞快乐!',U,345); 源代码中已标注 效果展示 ✨音乐律动圣诞树 代码块
*
{
box-sizing: border-box;
}
body
{
margin: 0;
height: 100vh;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background: #161616;
color: #c5a880;
font-family: sans-serif;
}
label
{
display: inline-block;
background-color: #161616;
padding: 16px;
border-radius: 0.3rem;
cursor: pointer;
margin-top: 1rem;
width: 300px;
border-radius: 10px;
border: 1px solid #c5a880;
text-align: center;
}
ul
{
list-style-type: none;
padding: 0;
margin: 0;
}
.btn
{
background-color: #161616;
border-radius: 10px;
color: #c5a880;
border: 1px solid #c5a880;
padding: 16px;
width: 300px;
margin-bottom: 16px;
line-height: 1.5;
cursor: pointer;
}
.separator
{
font-weight: bold;
text-align: center;
width: 300px;
margin: 16px 0px;
color: #a07676;
}
.title
{
color: #a07676;
font-weight: bold;
font-size: 1.25rem;
margin-bottom: 16px;
}
.text-loading
{
font-size: 2rem;
}
window.console = window.console || function(t) {};
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
- 请选择音乐
Snowflakes Falling Down by Simon Panrucker
- 或者
const { PI, sin, cos } = Math;
const TAU = 2 * PI;
const map = (value, sMin, sMax, dMin, dMax) => {
return dMin + (value - sMin) / (sMax - sMin) * (dMax - dMin);
};
const range = (n, m = 0) =>
Array(n).
fill(m).
map((i, j) => i + j);
const rand = (max, min = 0) => min + Math.random() * (max - min);
const randInt = (max, min = 0) => Math.floor(min + Math.random() * (max - min));
const randChoise = arr => arr[randInt(arr.length)];
const polar = (ang, r = 1) => [r * cos(ang), r * sin(ang)];
let scene, camera, renderer, analyser;
let step = 0;
const uniforms = {
time: { type: "f", value: 0.0 },
step: { type: "f", value: 0.0 } };
const params = {
exposure: 1,
bloomStrength: 0.9,
bloomThreshold: 0,
bloomRadius: 0.5 };
let composer;
const fftSize = 2048;
const totalPoints = 4000;
const listener = new THREE.AudioListener();
const audio = new THREE.Audio(listener);
document.querySelector("input").addEventListener("change", uploadAudio, false);
const buttons = document.querySelectorAll(".btn");
buttons.forEach((button, index) =>
button.addEventListener("click", () => loadAudio(index)));
function init() {
const overlay = document.getElementById("overlay");
overlay.remove();
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
1,
1000);
camera.position.set(-0.09397456774197047, -2.5597086635726947, 24.420789670889008);
camera.rotation.set(0.10443543723052419, -0.003827152981119352, 0.0004011488708739715);
const format = renderer.capabilities.isWebGL2 ?
THREE.RedFormat :
THREE.LuminanceFormat;
uniforms.tAudioData = {
value: new THREE.DataTexture(analyser.data, fftSize / 2, 1, format) };
addPlane(scene, uniforms, 3000);
addSnow(scene, uniforms);
range(10).map(i => {
addTree(scene, uniforms, totalPoints, [20, 0, -20 * i]);
addTree(scene, uniforms, totalPoints, [-20, 0, -20 * i]);
});
const renderScene = new THREE.RenderPass(scene, camera);
const bloomPass = new THREE.UnrealBloomPass(
new THREE.Vector2(window.innerWidth, window.innerHeight),
1.5,
0.4,
0.85);
bloomPass.threshold = params.bloomThreshold;
bloomPass.strength = params.bloomStrength;
bloomPass.radius = params.bloomRadius;
composer = new THREE.EffectComposer(renderer);
composer.addPass(renderScene);
composer.addPass(bloomPass);
addListners(camera, renderer, composer);
animate();
}
function animate(time) {
analyser.getFrequencyData();
uniforms.tAudioData.value.needsUpdate = true;
step = (step + 1) % 1000;
uniforms.time.value = time;
uniforms.step.value = step;
composer.render();
requestAnimationFrame(animate);
}
function loadAudio(i) {
document.getElementById("overlay").innerHTML =
'
const files = [
"https://files.freemusicarchive.org/storage-freemusicarchive-org/music/no_curator/Simon_Panrucker/Happy_Christmas_You_Guys/Simon_Panrucker_-_01_-_Snowflakes_Falling_Down.mp3",
"https://files.freemusicarchive.org/storage-freemusicarchive-org/music/no_curator/Dott/This_Christmas/Dott_-_01_-_This_Christmas.mp3",
"https://files.freemusicarchive.org/storage-freemusicarchive-org/music/ccCommunity/TRG_Banks/TRG_Banks_Christmas_Album/TRG_Banks_-_12_-_No_room_at_the_inn.mp3",
"https://files.freemusicarchive.org/storage-freemusicarchive-org/music/ccCommunity/Mark_Smeby/En_attendant_Nol/Mark_Smeby_-_07_-_Jingle_Bell_Swing.mp3"];
const file = files[i];
const loader = new THREE.AudioLoader();
loader.load(file, function (buffer) {
audio.setBuffer(buffer);
audio.play();
analyser = new THREE.AudioAnalyser(audio, fftSize);
init();
});
}
function uploadAudio(event) {
document.getElementById("overlay").innerHTML =
'
const files = event.target.files;
const reader = new FileReader();
reader.onload = function (file) {
var arrayBuffer = file.target.result;
listener.context.decodeAudioData(arrayBuffer, function (audioBuffer) {
audio.setBuffer(audioBuffer);
audio.play();
analyser = new THREE.AudioAnalyser(audio, fftSize);
init();
});
};
reader.readAsArrayBuffer(files[0]);
}
function addTree(scene, uniforms, totalPoints, treePosition) {
const vertexShader = `
attribute float mIndex;
varying vec3 vColor;
varying float opacity;
uniform sampler2D tAudioData;
float norm(float value, float min, float max ){
return (value - min) / (max - min);
}
float lerp(float norm, float min, float max){
return (max - min) * norm + min;
}
float map(float value, float sourceMin, float sourceMax, float destMin, float destMax){
return lerp(norm(value, sourceMin, sourceMax), destMin, destMax);
}
void main() {
vColor = color;
vec3 p = position;
vec4 mvPosition = modelViewMatrix * vec4( p, 1.0 );
float amplitude = texture2D( tAudioData, vec2( mIndex, 0.1 ) ).r;
float amplitudeClamped = clamp(amplitude-0.4,0.0, 0.6 );
float sizeMapped = map(amplitudeClamped, 0.0, 0.6, 1.0, 20.0);
opacity = map(mvPosition.z , -200.0, 15.0, 0.0, 1.0);
gl_PointSize = sizeMapped * ( 100.0 / -mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
}
`;
const fragmentShader = `
varying vec3 vColor;
varying float opacity;
uniform sampler2D pointTexture;
void main() {
gl_FragColor = vec4( vColor, opacity );
gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord );
}
`;
const shaderMaterial = new THREE.ShaderMaterial({
uniforms: {
...uniforms,
pointTexture: {
value: new THREE.TextureLoader().load(`https://assets.codepen.io/3685267/spark1.png`) } },
vertexShader,
fragmentShader,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true,
vertexColors: true });
const geometry = new THREE.BufferGeometry();
const positions = [];
const colors = [];
const sizes = [];
const phases = [];
const mIndexs = [];
const color = new THREE.Color();
for (let i = 0; i < totalPoints; i++) {
const t = Math.random();
const y = map(t, 0, 1, -8, 10);
const ang = map(t, 0, 1, 0, 6 * TAU) + TAU / 2 * (i % 2);
const [z, x] = polar(ang, map(t, 0, 1, 5, 0));
const modifier = map(t, 0, 1, 1, 0);
positions.push(x + rand(-0.3 * modifier, 0.3 * modifier));
positions.push(y + rand(-0.3 * modifier, 0.3 * modifier));
positions.push(z + rand(-0.3 * modifier, 0.3 * modifier));
color.setHSL(map(i, 0, totalPoints, 1.0, 0.0), 1.0, 0.5);
colors.push(color.r, color.g, color.b);
phases.push(rand(1000));
sizes.push(1);
const mIndex = map(i, 0, totalPoints, 1.0, 0.0);
mIndexs.push(mIndex);
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3).setUsage(
THREE.DynamicDrawUsage));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));
geometry.setAttribute("phase", new THREE.Float32BufferAttribute(phases, 1));
geometry.setAttribute("mIndex", new THREE.Float32BufferAttribute(mIndexs, 1));
const tree = new THREE.Points(geometry, shaderMaterial);
const [px, py, pz] = treePosition;
tree.position.x = px;
tree.position.y = py;
tree.position.z = pz;
scene.add(tree);
}
function addSnow(scene, uniforms) {
const vertexShader = `
attribute float size;
attribute float phase;
attribute float phaseSecondary;
varying vec3 vColor;
varying float opacity;
uniform float time;
uniform float step;
float norm(float value, float min, float max ){
return (value - min) / (max - min);
}
float lerp(float norm, float min, float max){
return (max - min) * norm + min;
}
float map(float value, float sourceMin, float sourceMax, float destMin, float destMax){
return lerp(norm(value, sourceMin, sourceMax), destMin, destMax);
}
void main() {
float t = time* 0.0006;
vColor = color;
vec3 p = position;
p.y = map(mod(phase+step, 1000.0), 0.0, 1000.0, 25.0, -8.0);
p.x += sin(t+phase);
p.z += sin(t+phaseSecondary);
opacity = map(p.z, -150.0, 15.0, 0.0, 1.0);
vec4 mvPosition = modelViewMatrix * vec4( p, 1.0 );
gl_PointSize = size * ( 100.0 / -mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
}
`;
const fragmentShader = `
uniform sampler2D pointTexture;
varying vec3 vColor;
varying float opacity;
void main() {
gl_FragColor = vec4( vColor, opacity );
gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord );
}
`;
function createSnowSet(sprite) {
const totalPoints = 300;
const shaderMaterial = new THREE.ShaderMaterial({
uniforms: {
...uniforms,
pointTexture: {
value: new THREE.TextureLoader().load(sprite) } },
vertexShader,
fragmentShader,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true,
vertexColors: true });
const geometry = new THREE.BufferGeometry();
const positions = [];
const colors = [];
const sizes = [];
const phases = [];
const phaseSecondaries = [];
const color = new THREE.Color();
for (let i = 0; i < totalPoints; i++) {
const [x, y, z] = [rand(25, -25), 0, rand(15, -150)];
positions.push(x);
positions.push(y);
positions.push(z);
color.set(randChoise(["#f1d4d4", "#f1f6f9", "#eeeeee", "#f1f1e8"]));
colors.push(color.r, color.g, color.b);
phases.push(rand(1000));
phaseSecondaries.push(rand(1000));
sizes.push(rand(4, 2));
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));
geometry.setAttribute("phase", new THREE.Float32BufferAttribute(phases, 1));
geometry.setAttribute(
"phaseSecondary",
new THREE.Float32BufferAttribute(phaseSecondaries, 1));
const mesh = new THREE.Points(geometry, shaderMaterial);
scene.add(mesh);
}
const sprites = [
"https://assets.codepen.io/3685267/snowflake1.png",
"https://assets.codepen.io/3685267/snowflake2.png",
"https://assets.codepen.io/3685267/snowflake3.png",
"https://assets.codepen.io/3685267/snowflake4.png",
"https://assets.codepen.io/3685267/snowflake5.png"];
sprites.forEach(sprite => {
createSnowSet(sprite);
});
}
function addPlane(scene, uniforms, totalPoints) {
const vertexShader = `
attribute float size;
attribute vec3 customColor;
varying vec3 vColor;
void main() {
vColor = customColor;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_PointSize = size * ( 300.0 / -mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
}
`;
const fragmentShader = `
uniform vec3 color;
uniform sampler2D pointTexture;
varying vec3 vColor;
void main() {
gl_FragColor = vec4( vColor, 1.0 );
gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord );
}
`;
const shaderMaterial = new THREE.ShaderMaterial({
uniforms: {
...uniforms,
pointTexture: {
value: new THREE.TextureLoader().load(`https://assets.codepen.io/3685267/spark1.png`) } },
vertexShader,
fragmentShader,
blending: THREE.AdditiveBlending,
depthTest: false,
transparent: true,
vertexColors: true });
const geometry = new THREE.BufferGeometry();
const positions = [];
const colors = [];
const sizes = [];
const color = new THREE.Color();
for (let i = 0; i < totalPoints; i++) {
const [x, y, z] = [rand(-25, 25), 0, rand(-150, 15)];
positions.push(x);
positions.push(y);
positions.push(z);
color.set(randChoise(["#93abd3", "#f2f4c0", "#9ddfd3"]));
colors.push(color.r, color.g, color.b);
sizes.push(1);
}
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3).setUsage(
THREE.DynamicDrawUsage));
geometry.setAttribute(
"customColor",
new THREE.Float32BufferAttribute(colors, 3));
geometry.setAttribute("size", new THREE.Float32BufferAttribute(sizes, 1));
const plane = new THREE.Points(geometry, shaderMaterial);
plane.position.y = -8;
scene.add(plane);
}
function addListners(camera, renderer, composer) {
document.addEventListener("keydown", e => {
const { x, y, z } = camera.position;
console.log(`camera.position.set(${x},${y},${z})`);
const { x: a, y: b, z: c } = camera.rotation;
console.log(`camera.rotation.set(${a},${b},${c})`);
});
window.addEventListener(
"resize",
() => {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
composer.setSize(width, height);
},
false);
}
打开方式
新建文本文档----→将代码粘贴后保存----→将文件后缀改为html打开即可
注意事项:用记事本输入代码,然后更改格式为html,有些人的电脑会默认隐藏文件格式,这时候你要在此电脑的查看选项中,把已知文件类型的扩展名这个选项的✓给打开,这样就会显示你每个文件的具体格式了。
效果展示
✨灯光圣诞树
代码块
html
fill="none" stroke-width="6.88" stroke-linecap="round" stroke-linejoin="round">
猪猪 ♥ 圣诞快乐 修改文字部分即可
new Vue({
el: '.tree',
data:{}
})
CSS
*{
margin: 0;
padding:0;
}
body{
height:100vh;
display:flex;
justify-content:center;
align-items: center;
background-color: #233343;
overflow:hidden;
transform-style: preserve-3d;
perspective: 1200px;
}
.tree{
/* border:1px solid red; */
width:1200px;
height: 716px;
position:relative;
transform-style: preserve-3d;
animation:spin 1s linear infinite
}
.tree-light{
transform-style: preserve-3d;
position:absolute;
width: 8px;
height:8px;
border-radius:50%;
left:50%;
bottom:calc(var(--y)*1%);
transform: translate(-50%,50%) rotateY(calc(var(--rotate,0)*1deg))
translate3d(0,0,calc(var(--radius,0)*25px));
animation: flash calc(var(--speed) * 0.5s) calc(var(--delay)*0.5s) infinite, appear 0.5s calc(var(--appear)*0.05s);
}
.tree-star{
stroke:#f5e0a3;
stroke-dasharray: 1000 1000;
width: 50px;
height: 50px;
filter:drop-shadow(0 0 10px #fcf1cf);
position: absolute;
left:50%;
bottom:100%;
transform: translate(-50%,0);
animation: stroke 1s calc((var(--delay)*0.95)*0.02s) backwards;
}
.wish{
stroke:#f5e0a3;
stroke-dasharray: 1000 1000;
position:absolute;
left:50%;
transform: translate(-20%,20%);
width:1000px;
height:300px;
justify-content:center;
align-items: center;
color:#faebd7;
font-size: 50px;
}
@keyframes appear {
from{
opacity:0;
}
}
@keyframes flash {
0%,100%{
background-color:#4f60f6;
}
20%{
background-color: #f64f4f;
}
40%{
background: #4fecf6;
}
60%{
background-color: #f6db4f;
}
80%{
background-color: #f64fe5;
}
}
@keyframes spin {
to{
transform: rotateY(360deg);
}
}
@keyframes stroke{
from{
stroke-dashoffset: -1000;
}
}
修改位置
猪猪 ♥ 圣诞快乐 修改文字部分即可
源代码中已标注
效果展示
圣诞贺卡
祝福绘制圣诞贺卡
代码块
HTML
JS
$('text').each(function () {
const el = $(this);
const text = el.html().split('');
el.html(`
});
CSS
@import url(https://fonts.googleapis.com/css?family=Calligraffitti);
@-webkit-keyframes s {
0% {
stroke-dasharray: 0 300;
}
100% {
stroke-dasharray: 300 0;
}
}
@keyframes s {
0% {
stroke-dasharray: 0 300;
}
100% {
stroke-dasharray: 300 0;
}
}
@-webkit-keyframes f {
0% {
transform: translateY(-40px);
opacity: 0.5;
}
50% {
transform: scale(1.5);
opacity: 0.1;
}
100% {
transform: translateY(50vh);
opacity: 0;
}
}
@keyframes f {
0% {
transform: translateY(-40px);
opacity: 0.5;
}
50% {
transform: scale(1.5);
opacity: 0.1;
}
100% {
transform: translateY(50vh);
opacity: 0;
}
}
html {
height: 100%;
}
body {
background: #a32300;
font-family: "Calligraffitti";
height: 100%;
text-align: center;
}
svg {
margin-top: calc(50vh - 75px);
width: 300px;
}
.Merry, .Christmas {
fill: none;
stroke: #fff;
text-shadow: 0 0 14px #a32300;
stroke-width: 4;
stroke-dasharray: 0 100;
text-anchor: middle;
}
.Merry {
font-size: 44px;
}
.Merry tspan:nth-child(1) {
-webkit-animation: s 2s 1s linear forwards;
animation: s 2s 1s linear forwards;
}
.Merry tspan:nth-child(2) {
-webkit-animation: s 2s 2s linear forwards;
animation: s 2s 2s linear forwards;
}
.Merry tspan:nth-child(3) {
-webkit-animation: s 2s 3s linear forwards;
animation: s 2s 3s linear forwards;
}
.Merry tspan:nth-child(4) {
-webkit-animation: s 2s 4s linear forwards;
animation: s 2s 4s linear forwards;
}
.Merry tspan:nth-child(5) {
-webkit-animation: s 2s 5s linear forwards;
animation: s 2s 5s linear forwards;
}
.Christmas {
font-size: 64px;
stroke-width: 6;
}
.Christmas tspan:nth-child(1) {
-webkit-animation: s 2s 6s linear forwards;
animation: s 2s 6s linear forwards;
}
.Christmas tspan:nth-child(2) {
-webkit-animation: s 2s 7s linear forwards;
animation: s 2s 7s linear forwards;
}
.Christmas tspan:nth-child(3) {
-webkit-animation: s 2s 8s linear forwards;
animation: s 2s 8s linear forwards;
}
.Christmas tspan:nth-child(4) {
-webkit-animation: s 2s 9s linear forwards;
animation: s 2s 9s linear forwards;
}
.Christmas tspan:nth-child(5) {
-webkit-animation: s 2s 10s linear forwards;
animation: s 2s 10s linear forwards;
}
.Christmas tspan:nth-child(6) {
-webkit-animation: s 2s 11s linear forwards;
animation: s 2s 11s linear forwards;
}
.Christmas tspan:nth-child(7) {
-webkit-animation: s 2s 12s linear forwards;
animation: s 2s 12s linear forwards;
}
.Christmas tspan:nth-child(8) {
-webkit-animation: s 2s 13s linear forwards;
animation: s 2s 13s linear forwards;
}
.Christmas tspan:nth-child(9) {
-webkit-animation: s 2s 14s linear forwards;
animation: s 2s 14s linear forwards;
}
.Snow {
position: absolute;
filter: blur(1px);
top: 0;
left: 0;
width: 100%;
font-size: 0;
height: 100%;
overflow: hidden;
}
.Snow-flake {
-webkit-animation: f 4s linear infinite;
animation: f 4s linear infinite;
display: inline-block;
border-radius: 50%;
background: #fff;
margin: 0 10px 0;
width: 10px;
height: 10px;
transform: translateY(-40px);
opacity: 0.5;
}
.Snow-flake:nth-child(1) {
-webkit-animation-delay: -3.6793681361s;
animation-delay: -3.6793681361s;
}
.Snow-flake:nth-child(2) {
-webkit-animation-delay: -0.4661163393s;
animation-delay: -0.4661163393s;
}
.Snow-flake:nth-child(3) {
-webkit-animation-delay: -3.4905253225s;
animation-delay: -3.4905253225s;
}
.Snow-flake:nth-child(4) {
-webkit-animation-delay: -2.7553831417s;
animation-delay: -2.7553831417s;
}
.Snow-flake:nth-child(5) {
-webkit-animation-delay: -0.7750134007s;
animation-delay: -0.7750134007s;
}
.Snow-flake:nth-child(6) {
-webkit-animation-delay: -2.5446368156s;
animation-delay: -2.5446368156s;
}
.Snow-flake:nth-child(7) {
-webkit-animation-delay: -1.5677614822s;
animation-delay: -1.5677614822s;
}
.Snow-flake:nth-child(8) {
-webkit-animation-delay: -2.3025289221s;
animation-delay: -2.3025289221s;
}
.Snow-flake:nth-child(9) {
-webkit-animation-delay: -2.2273608114s;
animation-delay: -2.2273608114s;
}
.Snow-flake:nth-child(10) {
-webkit-animation-delay: -2.8704051936s;
animation-delay: -2.8704051936s;
}
.Snow-flake:nth-child(11) {
-webkit-animation-delay: -3.1400586948s;
animation-delay: -3.1400586948s;
}
.Snow-flake:nth-child(12) {
-webkit-animation-delay: -0.3667266026s;
animation-delay: -0.3667266026s;
}
.Snow-flake:nth-child(13) {
-webkit-animation-delay: -1.7854983938s;
animation-delay: -1.7854983938s;
}
.Snow-flake:nth-child(14) {
-webkit-animation-delay: -0.3196037779s;
animation-delay: -0.3196037779s;
}
.Snow-flake:nth-child(15) {
-webkit-animation-delay: -1.964419289s;
animation-delay: -1.964419289s;
}
.Snow-flake:nth-child(16) {
-webkit-animation-delay: -2.791841093s;
animation-delay: -2.791841093s;
}
.Snow-flake:nth-child(17) {
-webkit-animation-delay: -2.0680800485s;
animation-delay: -2.0680800485s;
}
.Snow-flake:nth-child(18) {
-webkit-animation-delay: -1.3058220809s;
animation-delay: -1.3058220809s;
}
.Snow-flake:nth-child(19) {
-webkit-animation-delay: -3.4707126316s;
animation-delay: -3.4707126316s;
}
.Snow-flake:nth-child(20) {
-webkit-animation-delay: -0.6200169916s;
animation-delay: -0.6200169916s;
}
.Snow-flake:nth-child(21) {
-webkit-animation-delay: -1.3589008464s;
animation-delay: -1.3589008464s;
}
.Snow-flake:nth-child(22) {
-webkit-animation-delay: -3.2398063322s;
animation-delay: -3.2398063322s;
}
.Snow-flake:nth-child(23) {
-webkit-animation-delay: -2.6176651192s;
animation-delay: -2.6176651192s;
}
.Snow-flake:nth-child(24) {
-webkit-animation-delay: -3.8524291697s;
animation-delay: -3.8524291697s;
}
.Snow-flake:nth-child(25) {
-webkit-animation-delay: -0.4768476793s;
animation-delay: -0.4768476793s;
}
.Snow-flake:nth-child(26) {
-webkit-animation-delay: -3.4299640078s;
animation-delay: -3.4299640078s;
}
.Snow-flake:nth-child(27) {
-webkit-animation-delay: -2.3016890045s;
animation-delay: -2.3016890045s;
}
.Snow-flake:nth-child(28) {
-webkit-animation-delay: -0.5442387221s;
animation-delay: -0.5442387221s;
}
.Snow-flake:nth-child(29) {
-webkit-animation-delay: -0.0972386453s;
animation-delay: -0.0972386453s;
}
.Snow-flake:nth-child(30) {
-webkit-animation-delay: -3.7545507289s;
animation-delay: -3.7545507289s;
}
.Snow-flake:nth-child(31) {
-webkit-animation-delay: -2.6359017685s;
animation-delay: -2.6359017685s;
}
.Snow-flake:nth-child(32) {
-webkit-animation-delay: -3.5004651428s;
animation-delay: -3.5004651428s;
}
.Snow-flake:nth-child(33) {
-webkit-animation-delay: -3.0667933556s;
animation-delay: -3.0667933556s;
}
.Snow-flake:nth-child(34) {
-webkit-animation-delay: -3.8334187764s;
animation-delay: -3.8334187764s;
}
.Snow-flake:nth-child(35) {
-webkit-animation-delay: -3.4092893657s;
animation-delay: -3.4092893657s;
}
.Snow-flake:nth-child(36) {
-webkit-animation-delay: -3.0679398153s;
animation-delay: -3.0679398153s;
}
.Snow-flake:nth-child(37) {
-webkit-animation-delay: -0.5319986551s;
animation-delay: -0.5319986551s;
}
.Snow-flake:nth-child(38) {
-webkit-animation-delay: -0.2151432213s;
animation-delay: -0.2151432213s;
}
.Snow-flake:nth-child(39) {
-webkit-animation-delay: -3.1537248027s;
animation-delay: -3.1537248027s;
}
.Snow-flake:nth-child(40) {
-webkit-animation-delay: -3.2429406902s;
animation-delay: -3.2429406902s;
}
.Snow-flake:nth-child(41) {
-webkit-animation-delay: -1.4561511317s;
animation-delay: -1.4561511317s;
}
.Snow-flake:nth-child(42) {
-webkit-animation-delay: -2.5445790184s;
animation-delay: -2.5445790184s;
}
.Snow-flake:nth-child(43) {
-webkit-animation-delay: -1.5814941713s;
animation-delay: -1.5814941713s;
}
.Snow-flake:nth-child(44) {
-webkit-animation-delay: -3.0079767172s;
animation-delay: -3.0079767172s;
}
.Snow-flake:nth-child(45) {
-webkit-animation-delay: -0.1491416773s;
animation-delay: -0.1491416773s;
}
.Snow-flake:nth-child(46) {
-webkit-animation-delay: -0.0382036011s;
animation-delay: -0.0382036011s;
}
.Snow-flake:nth-child(47) {
-webkit-animation-delay: -1.3252301845s;
animation-delay: -1.3252301845s;
}
.Snow-flake:nth-child(48) {
-webkit-animation-delay: -0.5701800381s;
animation-delay: -0.5701800381s;
}
.Snow-flake:nth-child(49) {
-webkit-animation-delay: -0.0226088033s;
animation-delay: -0.0226088033s;
}
.Snow-flake:nth-child(50) {
-webkit-animation-delay: -3.028402928s;
animation-delay: -3.028402928s;
}
.Snow-flake:nth-child(51) {
-webkit-animation-delay: -0.9428044719s;
animation-delay: -0.9428044719s;
}
.Snow-flake:nth-child(52) {
-webkit-animation-delay: -1.4180933824s;
animation-delay: -1.4180933824s;
}
.Snow-flake:nth-child(53) {
-webkit-animation-delay: -1.1818536686s;
animation-delay: -1.1818536686s;
}
.Snow-flake:nth-child(54) {
-webkit-animation-delay: -1.8777931193s;
animation-delay: -1.8777931193s;
}
.Snow-flake:nth-child(55) {
-webkit-animation-delay: -1.1268303298s;
animation-delay: -1.1268303298s;
}
.Love {
position: absolute;
background: #fff;
bottom: 0;
height: 44px;
width: 100%;
left: 0;
color: #a32300;
}
.Love-heart, .Love-text {
display: inline-block;
font-family: sans-serif;
line-height: 44px;
}
修改位置
//修改文字部分
效果展示
雪橇雪人圣诞贺卡
代码块
HTML
JS
const hatEase = "Sine.easeInOut";
let hatDuration = 0.3;
const hatTl = gsap.timeline({
repeat: -1,
yoyo: true,
})
.to('#hat-1',{
morphSVG: "M332.84 146.29s-3.54-36.88 76.59-39.21c0 0-23.41 39.65-38.22 46.62 0 0-33.76 16.5-38.37-7.41z",
ease: hatEase,
duration: hatDuration,
},0)
.to('#hat-ball',{
x: -10,
y: -20,
ease: hatEase,
duration: hatDuration,
},0)
gsap.set('#snowman',{
x: -30,
y: -30,
})
gsap.set('#snowman-body',{
x: -5,
y: -3,
rotate: 10,
transformOrigin: '30% 40%',
})
const skingEase = "Sine.easeInOut";
const skingTl = gsap.timeline({
repeat: -1,
yoyo: true,
})
.to('#snowman',{
x: 30,
y: 15,
ease: skingEase,
},"ski-right")
.to('#snowman-body',{
x: 3,
y: 3,
rotate: -3,
transformOrigin: 'center',
ease: skingEase,
},"ski-right")
// .to('.head',{
// x: 2,
// y: 2,
// ease: skingEase,
// },"ski-right")
skingTl.timeScale(0.4)
const speedTl = gsap.timeline({
paused: true,
// repeat: -1,
})
.to('#snowman-container',{
x: -50,
y: 20,
},0)
.to('.head',{
x: -20,
y: 20,
},0)
.to('#snaman-face',{
x: -3,
y: 3,
},0)
.to('.arms',{
x: -10,
y: 5,
},0)
.to('#stick-back',{
x: 0,
y: -5,
},0)
.to('#stick-front',{
x: 0,
y: -8,
},0)
.to('#left-arm-1',{
rotate: 20,
transformOrigin: 'right top',
},0)
.to('#right-arm-1',{
rotate: 10,
transformOrigin: 'right top',
},0)
function resetPosition(){
gsap.to('#snowman-container',{ x: 0, y: 0, })
gsap.to('.head',{ x: 0, y: 0, })
gsap.to('#snaman-face',{ x: 0, y: 0, })
gsap.to('.arms',{ x: 0, y: 0, })
gsap.to('#stick-back',{ x: 0, y: 0, })
gsap.to('#snowman-container',{ x: 0, y: 0, })
gsap.to('#stick-front',{ x: 0, y: 0, })
gsap.to('#left-arm-1',{ rotate: 0, })
gsap.to('#right-arm-1',{ rotate: 0, })
}
for (let i = 0; i < 20; i++) {
let snow = document.querySelector("#snow").cloneNode(true);
gsap.set(snow, {
attr: {
cx: "115.05",
cy: "117.16",
r: "6.97",
fill: "#fff"
},
scale: "random(0.5, 1)",
x: -100 + (i * 15),
y: 200 + (i * 10),
opacity: 0,
});
document.querySelector("svg").appendChild(snow);
const snowTl = gsap.timeline({
repeat: -1,
})
.to(snow, {
x: (i * 15) + 350,
y: (i * 5),
duration: "random(0.8, 1)",
},0)
.to(snow, {
opacity: 1,
duration: 0.1,
},0)
.to(snow, {
opacity: 0,
duration: 0.4,
},"-=0.4")
.seek(100)
}
const svg = document.getElementById("hover");
svg.addEventListener('mouseover', () => {
hatTl.timeScale(1.8);
skingTl.timeScale(0.9);
speedTl.restart();
})
svg.addEventListener('mouseleave', () => {
hatTl.timeScale(1);
skingTl.timeScale(0.4);
resetPosition();
})
CSS
body {
width: 100%;
height: 100vh;
overflow: hidden;
background: #f2adab;
}
.box {
position: fixed;
left: calc(50vw - 50vmin);
top: calc(50vh - 37.5vmin);
width: 100vmin;
height: 75vmin;
}
svg {
overflow: visible;
}
#snow {
pointer-events: none;
}
.snow-clone {
opacity: 0;
}
效果展示
祝福语圣诞贺卡
代码块
HTML
body { background-color:#333; }
#snow{
background:none;
font-family:Androgyne;
background-image:url('https://www.iculture.cc/demo/Christmas/v7/img/ChQcWgQ.png'), url('https://www.iculture.cc/demo/Christmas/v7/img/5gvatHT.png'), url('https://www.iculture.cc/demo/Christmas/v7/img/pUPB6gi.png');
height:100%;
left:0;
position:absolute;
pointer-events:none;
top:0;width:100%;
z-index:1;
-webkit-animation:snow 10s linear infinite;
-moz-animation:snow 10s linear infinite;
-ms-animation:snow 10s linear infinite;
animation:snow 10s linear infinite
}
@keyframes snow{
0%{background-position:0px 0px, 0px 0px, 0px 0px}
50%{background-position:500px 500px, 100px 200px, -100px 150px}
100%{background-position:500px 1000px, 200px 400px, -100px 300px}
}
@-moz-keyframes snow{
0%{background-position:0px 0px, 0px 0px, 0px 0px}
50%{background-position:500px 500px, 100px 200px, -100px 150px}
100%{background-position:400px 1000px, 200px 400px, 100px 300px}
}
@-webkit-keyframes snow{
0%{background-position:0px 0px, 0px 0px, 0px 0px}
50%{background-position:500px 500px, 100px 200px, -100px 150px}
100%{background-position:500px 1000px, 200px 400px, -100px 300px}
}
@-ms-keyframes snow{
0%{background-position:0px 0px, 0px 0px, 0px 0px}
50%{background-position:500px 500px, 100px 200px, -100px 150px}
100%{background-position:500px 1000px, 200px 400px, -100px 300px}
}
.letter {
background: #fff;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
margin: 26px auto 0;
max-width: 550px;
min-height: 300px;
padding: 24px;
position: relative;
width: 80%;
}
.letter:before, .letter:after {
content: "";
height: 98%;
position: absolute;
width: 100%;
z-index: -1;
}
.letter:before {
background: #fafafa;
box-shadow: 0 0 8px rgba(0,0,0,0.2);
left: -5px;
top: 4px;
transform: rotate(-2.5deg);
}
.letter:after {
background: #f6f6f6;
box-shadow: 0 0 3px rgba(0,0,0,0.2);
right: -3px;
top: 1px;
transform: rotate(1.4deg);
}
CSS JSResult Skip Results Iframe
EDIT ON
/* style.css */
html, body {
height: 100%;
}
body {
margin: 0;
display: flex;
/* This centers our sketch horizontally. */
justify-content: center;
/* This centers our sketch vertically. */
align-items: center;
}
.polaroid a {
background: #ffffff;
display: inline-block;
margin: 55px 75px 30px;
padding: 15px 15px 30px;
text-align: center;
text-decoration: none;
-webkit-box-shadow: 0 4px 6px rgba(0, 0, 0, .3);
-moz-box-shadow: 0 4px 6px rgba(0, 0, 0, .3);
box-shadow: 0 4px 6px rgba(0, 0, 0, .3);
-webkit-transition: all .20s linear;
-moz-transition: all .20s linear;
transition: all .20s linear;
z-index: 0;
position: relative;
transform: rotate(-9deg);
}
.polaroid a:after {
color: #333;
font-size: 25px;
content: attr(title);
position: relative;
top: 15px;
}
.polaroid img {
display: block;
width: 250px;
}
.polaroid a:hover {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
transform: scale(1.2);
z-index: 10;
-webkit-box-shadow: 0 10px 20px rgba(0, 0, 0, .7);
-moz-box-shadow: 0 10px 20px rgba(0, 0, 0, .7);
box-shadow: 0 10px 20px rgba(0, 0, 0, .7);
}
var typed = new Typed('#typed', {
stringsElement: '#typed-strings',
typeSpeed: 50
});
const WANDERER_MOVE_MULTIPLIER = 8;
const WANDERER_ROTATE_SPEED = 0.03; // very sensitive
const PATH_WIDTH = 5;
const PATH_HIGHLIGHT_WIDTH = 4;
const LIGHT_GRAPHICS_WIDTH_HEIGHT = 60;
const MAX_BULBS = 300;
const BULB_COLORS = [
'#00d9ff',
'#ff0d0d',
'#59ff9d',
'#b959ff'
];
const BULB_LAST_INDEX = BULB_COLORS.length - 1;
const BULB_FREQUENCY = 200;
let node;
let pathGraphics;
let bulbGraphics = [];
let bulbs = [];
let bulbTick = 0;
let bulbFlip = false;
let bulbColorIndex = 0;
let bulbInterval = null;
let done = false;
function setup() {
createCanvas(window.windowWidth, window.windowHeight);
background(20);
node = new Wanderer();
pathGraphics = createGraphics(width, height);
pathGraphics.noFill();
pathGraphics.strokeCap(PROJECT);
BULB_COLORS.forEach((color) => {
bulbGraphics.push(getBulbGraphics(color));
});
bulbInterval = setInterval(() => {
if(bulbs.length < MAX_BULBS) {
addBulb();
} else {
clearInterval(bulbInterval);
done = true;
}
}, BULB_FREQUENCY)
}
function draw() {
background(20);
if(!done) {
node.render();
}
image(pathGraphics, 0, 0);
bulbs.forEach((bulb) => bulb.render());
}
function addBulb() {
const pos = node.getPosition();
const direction = node.getDirection();
bulbs.push(new Bulb(pos.x, pos.y, direction - (bulbFlip ? PI : 0), bulbGraphics[bulbColorIndex]));
bulbFlip = !bulbFlip;
bulbColorIndex += 1;
if(bulbColorIndex > BULB_LAST_INDEX) {
bulbColorIndex = 0;
}
}
function drawBulb(graphics, color) {
graphics.fill(color);
graphics.noStroke();
graphics.beginShape();
graphics.vertex(-4, 0);
graphics.vertex(-6, -5);
graphics.vertex(-7, -10);
graphics.vertex(-8, -15);
graphics.vertex(0 - 7, -20);
graphics.vertex(-4, -25);
graphics.vertex(0, -27);
graphics.vertex(0, 0);
graphics.endShape();
graphics.beginShape();
graphics.vertex(4, 0);
graphics.vertex(6, -5);
graphics.vertex(7, -10);
graphics.vertex(8, -15);
graphics.vertex(7, -20);
graphics.vertex(4, -25);
graphics.vertex(0, -27);
graphics.vertex(0, 0);
graphics.endShape();
graphics.fill('#378a2e');
graphics.rect(0, 0, 10, 5);
}
function getBulbGraphics(color) {
const graphics = createGraphics(LIGHT_GRAPHICS_WIDTH_HEIGHT, LIGHT_GRAPHICS_WIDTH_HEIGHT);
graphics.rectMode(CENTER);
const startX = graphics.width * 0.5;
const startY = graphics.height - 10;
graphics.translate(startX, startY - 45);
graphics.rotate(PI);
graphics.scale(1.2);
// draw the bulb once
drawBulb(graphics, color);
// blur the bulb
graphics.filter(BLUR, 8);
graphics.scale(0.8);
// draw the bulb again to give a glow effect
drawBulb(graphics, color);
return graphics;
}
class Wanderer {
constructor() {
this.pos = { x: random(width), y: random(height) };
this.lastPos = { ...this.pos }
this.direction = random(TWO_PI);
this.noiseValue = 0;
}
getPosition() {
return { x: this.pos.x, y: this.pos.y };
}
getDirection() {
return this.direction;
}
render() {
this.lastPos = { ...this.pos }
const xx = cos(this.direction) * WANDERER_MOVE_MULTIPLIER;
const yy = sin(this.direction) * WANDERER_MOVE_MULTIPLIER;
this.pos.x += xx;
this.pos.y += yy;
this.direction = noise(this.noiseValue += WANDERER_ROTATE_SPEED) * TWO_PI;
let pathBroken = false;
if(this.pos.y > height) {
pathBroken = true;
this.pos.y = 0;
} else if(this.pos.y < 0) {
pathBroken = true;
this.pos.y = height;
}
if(this.pos.x > width) {
pathBroken = true;
this.pos.x = 0;
} else if(this.pos.x < 0) {
pathBroken = true;
this.pos.x = width;
}
if(pathBroken) {
this.lastPos = { ...this.pos }
}
pathGraphics.strokeWeight(PATH_WIDTH);
pathGraphics.stroke('#378a2e');
pathGraphics.line(this.pos.x, this.pos.y, this.lastPos.x, this.lastPos.y);
pathGraphics.strokeWeight(PATH_HIGHLIGHT_WIDTH);
pathGraphics.stroke('#42c134');
pathGraphics.line(this.pos.x + 1, this.pos.y - 2, this.lastPos.x + 1, this.lastPos.y - 2);
}
}
class Bulb {
constructor(x, y, direction, bulbImage) {
this.bulbImage = bulbImage;
this.pos = { x, y };
this.direction = direction;
this.halfImageWidth = this.bulbImage.width * 0.5;
}
render() {
push();
translate(this.pos.x, this.pos.y);
// const dir = atan2(this.pos.y - mouseY, this.pos.x - mouseX);
rotate(this.direction);
image(this.bulbImage, -this.halfImageWidth, 0);
pop();
}
}
修改位置
情意绵绵,喜乐常。事事如意,人安康。风花雪月,圣诞至。祝福千万,表衷肠。家和兴旺,亲人吉祥,事业中天,学业辉煌。圣诞节快乐!
//修改文字部分
效果展示
裏源码获取方式
圣诞树|圣诞贺卡 网站源码https://blog.csdn.net/dxt19980308?type=download
美酒,在酒杯中摇曳;灯火,在夜色中阑珊;幸福,在生活中陶醉;快乐,在节日中开怀;飞雪,在吉祥中飘落;问候,在真挚中送达。
希望大家在圣诞节都可以和喜欢的人在一起,送上那棵专属于她or他的圣诞树!
相关文章
发表评论