查看: 1063|回复: 38

[单图] 【黑师代码】凝望(回赠:幽兰)

[复制链接]
随遇而安
少年歌行 守望千山 两周年庆 巳巳如意 一叶知秋 版主勋章 山高为峰 山外有山 樱果相依 闲花落
发表于 2024-3-27 21:02 | 显示全部楼层 |阅读模式

评分

8

查看全部评分

点评
回复

使用道具

随遇而安
少年歌行 守望千山 两周年庆 巳巳如意 一叶知秋 版主勋章 山高为峰 山外有山 樱果相依 闲花落
 楼主| 发表于 2024-3-27 21:02 | 显示全部楼层
本帖最后由 花简静 于 2024-3-31 18:37 编辑

<style> #papa {     margin: 130px 0 10px calc(50% - 931px);     width: 1700px;     height: 900px;     background: url('https://pic.imgdb.cn/item/6602e15c9f345e8d031591d4.webp') no-repeat center/cover;     box-shadow: 3px 3px 20px #000;     overflow: hidden;     display: grid;     place-items: center;     position: relative;     overflow: hidden;     z-index: 1; } #vid1 {     position: absolute;     width: 350px;     height: 350px;     opacity: .10;     top:451px;left:294px;     object-fit: cover;     border-radius: 50%;     mix-blend-mode: screen;     pointer-events: none;     z-index: 12;     opacity: .66; } #vid2 {     position: absolute;     width: 110%;     height: 100%;     opacity: .10;     left:-434px;     bottom:-200px;     object-fit: cover;     mix-blend-mode: screen;     pointer-events: none;     opacity: .36; } #mypic {     position: absolute;     width: 60px;     height: 60px;     left:440px;     top:600px;     mix-blend-mode: hard-light;     cursor: pointer;     transition: filter 1s;     animation: rot 6s infinite linear var(--state);     z-index: 10;opacity: .38; } #mypic:hover {     filter: invert(100%) drop-shadow(4px 4px 20px snow); }   #canv { position: absolute; width="300";height="300";top:480px;left:320px;z-index: 5;opacity: .58;}   @keyframes moving {     from { transform: translate(0,0) rotate(var(--deg)); opacity: 0; }     to { transform: translate(var(--xx),var(--yy)) rotate(var(--deg)); opacity: 1; } } @keyframes rot { to { transform: rotate(360deg); } } </style>   <div id="papa"> <video id="vid1" src="" autoplay loop muted></video> <video id="vid2" src="https://img.tukuppt.com/video_show/2269348/00/14/66/5e5a31400e91a.mp4" autoplay loop muted></video>     <img id="mypic" src="https://638183.freep.cn/638183/web/svg/flower_1.svg" alt="" title="暂停/播放" />     <canvas id="canv" width="300" height="300"></canvas>     <audio id="aud" src="https://music.163.com/song/media/outer/url?id=2040200174" autoplay loop></audio> </div> <script>   let cTimer = null;   /* 获取画笔 */ let ctx = canv.getContext('2d'); /* 函数 :绘制矩形(指针) */ let draw_rect = (x, y, w, h, rad, color) => { ctx.save(); ctx.fillStyle = color; ctx.translate(150,150); ctx.rotate(rad); ctx.fillRect(x,y,w,h); ctx.restore(); }; /* 函数 :绘制圆(环) */ let draw_circle = (x,y,r,lw,color1,color2) => { ctx.save(); ctx.fillStyle = color1; ctx.strokeStyle = color2; ctx.lineWidth = lw; ctx.beginPath(); ctx.arc(x,y,r,0,Math.PI * 2); ctx.fill(); ctx.stroke(); ctx.restore(); }; /* 函数 :绘制文本 */ let draw_text = (txt,x,y,color,fontsize=18,b="bold") => { ctx.save(); ctx.translate(150,150); ctx.font = `${b} ${fontsize}px sans-serif`; ctx.textAlign = 'center'; ctx.textBaseline="middle"; ctx.fillStyle = color; ctx.fillText(txt,x,y); ctx.restore(); }; let render = () => { /* 获取时间 */ let now = new Date(); let hr = now.getHours() > 12 ? now.getHours() - 12 : now.getHours(), min = now.getMinutes(), sec = now.getSeconds(), msec = now.getMilliseconds(); let hDeg = hr * 30 + (min * 6 / 12), mDeg = min * 6 + (sec * 6 / 60), sDeg = sec * 6 + (msec * 0.36 / 1000); ctx.clearRect(0,0,300,300); /* 每一次绘制前都衔擦除画布 */ draw_circle(150,150,140,10,'AliceBlue','SteelBlue'); /* 钟壳和钟面 */ /* 钟点 */ for(let i = 0; i < 12; i ++) { let radian = Math.PI/180*(i*30-60); let x = 115 * Math.cos(radian), y = 115 * Math.sin(radian); draw_text(i+1, x, y, 'DimGray'); } /* 刻度 */ for(let i = 0; i < 60; i ++) { let radian = Math.PI/180*(i*6); let x = 150 + 130 * Math.cos(radian), y = 150 + 130 * Math.sin(radian); draw_circle(x,y,1,2,'gray','gray'); } /* 按一定次序绘制时钟各个元素 :确保指针、指针扣不会被遮挡 */ draw_text(`${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`,0,-50,'    DimGray', 15, 'normal'); /* 日期 */ draw_text(`星期${'日一二三四五六'.substr(now.getDay(),1)}`,0,-25,'DimGray', 15, 'normal'); /* 星期 */ draw_text('HUACHAO',0,60,'DimGray'); /* Logo */ draw_rect(0, -3, 90, 6, (hDeg - 90) * Math.PI/180, 'CadetBlue'); /* 时针 */ draw_rect(0, -2, 100, 4, (mDeg - 90) * Math.PI/180, 'CadetBlue'); /* 分针 */ draw_rect(0, -1, 120, 2, (sDeg - 90) * Math.PI/180, 'CadetBlue'); /* 秒针 */ draw_circle(150,150,6,6,'white','CadetBlue'); /* 指针扣 */ requestAnimationFrame(render); }; render();   let mState = () => {     aud.paused         ? (papa.style.setProperty('--state','paused'), vid1.pause(), vid2.pause())         : (papa.style.setProperty('--state','running'),vid1.play(),vid2.play());     draw(); };   aud.addEventListener('pause', () => mState()); aud.addEventListener('playing', () => mState()); mypic.onclick = () => aud.paused ? aud.play() : aud.pause();   </script>
点评
回复

使用道具

随遇而安
少年歌行 守望千山 两周年庆 巳巳如意 一叶知秋 版主勋章 山高为峰 山外有山 樱果相依 闲花落
 楼主| 发表于 2024-3-27 21:03 | 显示全部楼层
本帖最后由 花简静 于 2024-3-31 18:45 编辑

<style>
#papa {
    margin: 130px 0 10px calc(50% - 931px);
    width: 1700px;
    height: 900px;
    background: url('https://pic.imgdb.cn/item/6602e15c9f345e8d031591d4.webp') no-repeat center/cover;
    box-shadow: 3px 3px 20px #000;
    overflow: hidden;
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    z-index: 1;
}
#vid1 {
    position: absolute;
    width: 350px;
    height: 350px;
    opacity: .10;
    top:451px;left:294px;
    object-fit: cover;
    border-radius: 50%;
    mix-blend-mode: screen;
    pointer-events: none;
    z-index: 12;
    opacity: .66;
}
#vid2 {
    position: absolute;
    width: 110%;
    height: 100%;
    opacity: .10;
    left:-434px;
    bottom:-200px;
    object-fit: cover;
    mix-blend-mode: screen;
    pointer-events: none;
    opacity: .36;
}

#mypic {
    position: absolute;
   width: 60px;
    height: 60px;
    left:440px;
    top:600px;

    mix-blend-mode: hard-light;
    cursor: pointer;
    transition: filter 1s;
    animation: rot 6s infinite linear var(--state);
    z-index: 10;opacity: .38;
}
#mypic:hover {
    filter: invert(100%) drop-shadow(4px 4px 20px snow);
}

#canv { position: absolute; width="300";height="300";top:480px;left:320px;z-index: 5;opacity: .58;}

@keyframes moving {
    from { transform: translate(0,0) rotate(var(--deg)); opacity: 0; }
    to { transform: translate(var(--xx),var(--yy)) rotate(var(--deg)); opacity: 1; }
}
@keyframes rot { to { transform: rotate(360deg); } }
</style>

<div id="papa">
<video id="vid1" src="" autoplay loop muted></video>
<video id="vid2" src="https://img.tukuppt.com/video_show/2269348/00/14/66/5e5a31400e91a.mp4" autoplay loop muted></video>

    <img id="mypic" src="https://638183.freep.cn/638183/web/svg/flower_1.svg" alt="" title="暂停/播放" />
    <canvas id="canv" width="300" height="300"></canvas>
    <audio id="aud" src="https://music.163.com/song/media/outer/url?id=2040200174" autoplay loop></audio>
</div>
<script>

let cTimer = null;

/* 获取画笔 */
let ctx = canv.getContext('2d');

/* 函数 :绘制矩形(指针) */
let draw_rect = (x, y, w, h, rad, color) => {
    ctx.save();
    ctx.fillStyle = color;
    ctx.translate(150,150);
    ctx.rotate(rad);
    ctx.fillRect(x,y,w,h);
    ctx.restore();
};
/* 函数 :绘制圆(环) */
let draw_circle = (x,y,r,lw,color1,color2) => {
    ctx.save();
    ctx.fillStyle = color1;
    ctx.strokeStyle = color2;
    ctx.lineWidth = lw;
    ctx.beginPath();
    ctx.arc(x,y,r,0,Math.PI * 2);
    ctx.fill();
    ctx.stroke();
    ctx.restore();
};
/* 函数 :绘制文本 */
let draw_text = (txt,x,y,color,fontsize=18,b="bold") => {
    ctx.save();
    ctx.translate(150,150);
    ctx.font = `${b} ${fontsize}px sans-serif`;
    ctx.textAlign = 'center';
    ctx.textBaseline="middle";
    ctx.fillStyle = color;
    ctx.fillText(txt,x,y);
    ctx.restore();
};

let render = () => {
    /* 获取时间 */
    let now = new Date();
    let hr = now.getHours() > 12 ? now.getHours() - 12 : now.getHours(),
        min = now.getMinutes(),
        sec = now.getSeconds(),
        msec = now.getMilliseconds();
    let hDeg = hr * 30 + (min * 6 / 12),
        mDeg = min * 6 + (sec * 6 / 60),
        sDeg = sec * 6 + (msec * 0.36 / 1000);
   
    ctx.clearRect(0,0,300,300); /* 每一次绘制前都衔擦除画布 */
    draw_circle(150,150,140,10,'AliceBlue','SteelBlue'); /* 钟壳和钟面 */

    /* 钟点 */
    for(let i = 0; i < 12; i ++) {
        let radian = Math.PI/180*(i*30-60);
        let x = 115 * Math.cos(radian), y = 115 * Math.sin(radian);
        draw_text(i+1, x, y, 'DimGray');
    }
    /* 刻度 */
    for(let i = 0; i < 60; i ++) {
        let radian = Math.PI/180*(i*6);
        let x = 150 + 130 * Math.cos(radian), y = 150 + 130 * Math.sin(radian);
        draw_circle(x,y,1,2,'gray','gray');
    }
    /* 按一定次序绘制时钟各个元素 :确保指针、指针扣不会被遮挡 */
    draw_text(`${now.getFullYear()}年${now.getMonth() + 1}月${now.getDate()}日`,0,-50,'    DimGray', 15, 'normal'); /* 日期 */
    draw_text(`星期${'日一二三四五六'.substr(now.getDay(),1)}`,0,-25,'DimGray', 15, 'normal'); /* 星期 */
    draw_text('HUACHAO',0,60,'DimGray'); /* Logo */
    draw_rect(0, -3, 90, 6, (hDeg - 90) * Math.PI/180, 'CadetBlue'); /* 时针 */
    draw_rect(0, -2, 100, 4, (mDeg - 90) * Math.PI/180, 'CadetBlue'); /* 分针 */
    draw_rect(0, -1, 120, 2, (sDeg - 90) * Math.PI/180, 'CadetBlue'); /* 秒针 */
    draw_circle(150,150,6,6,'white','CadetBlue'); /* 指针扣 */

    requestAnimationFrame(render);
};

render();


let mState = () => {
    aud.paused
        ? (papa.style.setProperty('--state','paused'), vid1.pause(), vid2.pause())
        : (papa.style.setProperty('--state','running'),vid1.play(),vid2.play());
    draw();
};

aud.addEventListener('pause', () => mState());
aud.addEventListener('playing', () => mState());
mypic.onclick = () => aud.paused ? aud.play() : aud.pause();

</script>
红色部分是时间代码
蓝色部分是小花播的大小和位置可以更改,后一句蓝色可改小花播的图片。
绿色部分是视频代码,可以更改设定位置(两个视频代码,我只用了一个)
点评
回复

使用道具

随遇而安
少年歌行 守望千山 两周年庆 巳巳如意 一叶知秋 版主勋章 山高为峰 山外有山 樱果相依 闲花落
 楼主| 发表于 2024-3-27 21:04 | 显示全部楼层
@幽兰 看到你的礼物十分开心哦。。
一起玩图快乐,相伴千山。。

评分

1

查看全部评分

点评
回复

使用道具

山高为峰 海洋之心 蝴蝶精灵 诗中之仙 花漫千山 江湖之上 音画同行
发表于 2024-3-27 21:08 | 显示全部楼层
分享你们的快乐 幽兰收礼快乐
点评
回复

使用道具

笑傲江湖
前兔似锦 七夕之桥 少年歌行 守望千山 两周年庆 巳巳如意 映像2024 我书我心 一叶知秋 版主勋章 山高为峰 山外有山 樱果相依 一坛酒
发表于 2024-3-27 21:54 | 显示全部楼层
静静这图非常精彩
深邃的凝望
配合漩涡般空间感大增
空灵音乐的加持
仿佛带我们进入了三维空间
码字也很美
点赞。。。

评分

1

查看全部评分

点评
回复

使用道具

『默然守候』
少年歌行 守望千山 两周年庆 江湖之上 桃花朵朵 山高为峰 山外有山 巳巳如意 海洋之心 蝴蝶精灵 山间红叶 花漫千山 音画同行 中秋月圆 欢度国庆 雪花精灵 一叶知秋 我书我心 樱果相依 小青龙
发表于 2024-3-27 23:30 | 显示全部楼层
花简静 发表于 2024-3-27 21:04
@幽兰 看到你的礼物十分开心哦。。
一起玩图快乐,相伴千山。。

静宝这图极美
时钟代表时光的穿梭
珍惜当下过好每一天
点评
回复

使用道具

『默然守候』
少年歌行 守望千山 两周年庆 江湖之上 桃花朵朵 山高为峰 山外有山 巳巳如意 海洋之心 蝴蝶精灵 山间红叶 花漫千山 音画同行 中秋月圆 欢度国庆 雪花精灵 一叶知秋 我书我心 樱果相依 小青龙
发表于 2024-3-27 23:32 | 显示全部楼层
深邃的背景
码字漂亮
光感运用甚是精彩
这图整天感觉视觉盛宴
问好静宝
点评
回复

使用道具

『默然守候』
少年歌行 守望千山 两周年庆 江湖之上 桃花朵朵 山高为峰 山外有山 巳巳如意 海洋之心 蝴蝶精灵 山间红叶 花漫千山 音画同行 中秋月圆 欢度国庆 雪花精灵 一叶知秋 我书我心 樱果相依 小青龙
发表于 2024-3-27 23:34 | 显示全部楼层
超喜欢静宝的创意和制作
最近这几天忙了些
好几天没一起聊天了
甚念
点评
回复

使用道具

『默然守候』
少年歌行 守望千山 两周年庆 江湖之上 桃花朵朵 山高为峰 山外有山 巳巳如意 海洋之心 蝴蝶精灵 山间红叶 花漫千山 音画同行 中秋月圆 欢度国庆 雪花精灵 一叶知秋 我书我心 樱果相依 小青龙
发表于 2024-3-27 23:35 | 显示全部楼层
期待静宝更多佳作分享
祝宝玩的开心快乐
借美图祝幽兰收礼开心
点评
回复

使用道具

您需要登录后才可以回帖 登录 | 中文注册

本版积分规则

手机版|千山论坛 ( 冀ICP备2024055714号 )

GMT+8, 2026-1-31 23:57

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表