纯代码的3D玫瑰花,有个这个还怕女朋友不开心?

这篇具有很好参考价值的文章主要介绍了纯代码的3D玫瑰花,有个这个还怕女朋友不开心?。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

先上效果图:
纯代码的3D玫瑰花,有个这个还怕女朋友不开心?
再上代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        @import url("https://fonts.googleapis.com/css2?family=Niconne&display=swap");
        * {
            margin: 0;
            padding: 0;
        }
        body {
            position: relative;
            width: 100vw;
            height: 100vh;
            background: radial-gradient(circle, #82707a, #24111e 100%);
        }
        main {
            position: relative;
            z-index: 1;
        }
        h1 {
            font-family: "Niconne", cursive;
            font-size: 10vw;
            margin-left: 1rem;
            color: rgba(255, 255, 255, 0.2);
        }
        p {
            position: fixed;
            bottom: 0;
            margin: 10px;
            font-size: max(3.3vw, 15px);
            color: rgba(255, 255, 255, 0.5);
        }
        #filter {

        }
        canvas {
            -moz-user-select: none;
            -webkit-user-select: none;
            -ms-user-select: none;
            user-select: none;
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            margin: 0;
            padding: 0;
            z-index: 0;
        }
        header {
            position: fixed;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 0 1% 1%;
            width: 100%;
            z-index: 3;
            height: 7em;
            font-family: "Bebas Neue", sans-serif;
            font-size: clamp(0.66rem, 2vw, 1rem);
            letter-spacing: 0.5em;
        }

        a{
            color: black;
            text-decoration: none;
        }
    </style>
</head>
<body>
<main>
    <h1></h1>
    <p></p>
</main>
<header>
    <div>Animated Sections</div>
    <div><a href="https://blog.csdn.net/qq_35241329?type=blog">Original By TiMi先生</a></div>
</header>
<div id="filter"></div>
<script async src="https://ga.jspm.io/npm:es-module-shims@1.6.3/dist/es-module-shims.js" crossorigin="anonymous"></script>
<script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/three@0.150.1/build/three.module.js",
      "three/addons/": "https://unpkg.com/three@0.150.1/examples/jsm/"
    }
  }
</script>
</body>
<script type="module">
    import * as THREE from "three";
    import { OrbitControls } from "three/addons/controls/OrbitControls.js";
    import { OBJLoader } from "three/addons/loaders/OBJLoader.js";

    let container;
    let camera, scene, renderer, controls;
    let manager;
    let object;
    let material = new THREE.MeshStandardMaterial({
        metalness: 0,
        roughness: 0.8,
        side: THREE.DoubleSide
    });

    init();
    animate();

    function init() {
        container = document.createElement("div");
        document.body.appendChild(container);

        camera = new THREE.PerspectiveCamera(
            33, //45
            window.innerWidth / window.innerHeight,
            1,
            2000
        );
        camera.position.y = 150;
        camera.position.z = 250;

        scene = new THREE.Scene();

        const ambientLight = new THREE.AmbientLight(0xffffff, 0.1);
        scene.add(ambientLight);

        const pointLight = new THREE.PointLight(0xffffff, 0.5);
        pointLight.castShadow = true;
        camera.add(pointLight);
        scene.add(camera);

        // manager
        function loadModel() {
            object.traverse(function (child) {
                if (child.isMesh) {
                    if (child.name == "rose") {
                        material = material.clone();
                        material.color.set("crimson");
                    } else if (child.name == "calyx") {
                        material = material.clone();
                        material.color.set("#001a14");
                    } else if (child.name == "leaf1" || child.name == "leaf2") {
                        material = material.clone();
                        material.color.set("#00331b");
                    }
                    child.material = material;
                }
            });
            object.rotation.set(0, Math.PI / 1.7, 0);
            object.receiveShadow = true;
            object.castShadow = true;
            scene.add(object);
        }

        manager = new THREE.LoadingManager(loadModel);

        // model
        function onProgress(xhr) {
            if (xhr.lengthComputable) {
                const percentComplete = (xhr.loaded / xhr.total) * 100;
            }
        }
        function onError() {}

        const loader = new OBJLoader(manager);
        loader.load(
            "https://happy358.github.io/Images/Model/red_rose3.obj",
            function (obj) {
                object = obj;
            },
            onProgress,
            onError
        );

        renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });

        renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.outputEncoding = THREE.sRGBEncoding;
        renderer.shadowMap.enabled = true;
        container.appendChild(renderer.domElement);

        controls = new OrbitControls(camera, renderer.domElement);
        controls.autoRotate = true; //true
        controls.autoRotateSpeed = 2;
        controls.enableDamping = true;
        controls.enablePan = false;
        controls.minPolarAngle = 0;
        controls.maxPolarAngle = Math.PI / 2;
        controls.target.set(0, 0, 0);
        controls.update();

        window.addEventListener("resize", onWindowResize);
    }
    function onWindowResize() {
        camera.aspect = window.innerWidth / window.innerHeight;
        camera.updateProjectionMatrix();
        renderer.setSize(window.innerWidth, window.innerHeight);
    }

    function animate() {
        requestAnimationFrame(animate);
        controls.update();
        render();
    }
    function render() {
        renderer.render(scene, camera);
    }

</script>
</html>

最近截的动图好多都大于5M无法上传了,有没有比较好的视频转gif的工具推荐以下。文章来源地址https://www.toymoban.com/news/detail-447776.html

到了这里,关于纯代码的3D玫瑰花,有个这个还怕女朋友不开心?的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • python写玫瑰花代码

    路漫漫其修远兮,吾将上下而求索 马上情人节了,今天让我们在电脑电脑上创建一朵玫瑰花,送你,送你想送的人。话不多说,直接来。 只要改掉代码中的某某某成自己想给的人的名字即可。  情人节送的代码,这不上火,哈哈😂🤣 谢谢观看

    2024年02月08日
    浏览(29)
  • 玫瑰花动态代码html(可直接复制)

    !DOCTYPE html html head meta charset=\\\"UTF-8\\\" title玫瑰/title style type=\\\"text/css\\\" #shusheng { position: absolute; width: 100%; height: 100%; text-align: center; } /style /head body div style=\\\"text-align: center\\\" /div div id=\\\"shusheng\\\" canvas id=\\\"c\\\"/canvas script var b = document.body; var c = document.getElementsByTagName(\\\'canvas\\\')[0]; var a = c.getContex

    2024年02月06日
    浏览(24)
  • Python绘制玫瑰花完整代码✅发妹纸用

    在Python中,我们可以使用matplotlib和numpy库来创建三维图形。在这篇文章中,我们将介绍如何使用这些库来绘制一个立体的玫瑰花。让我们开始吧! 在开始之前,请确保您的计算机上已安装Python和matplotlib库。您可以使用以下命令来安装matplotlib: 以下代码将使用matplotlib库来绘

    2024年02月07日
    浏览(27)
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码

    本文目录: 一、前言 二、草莓熊手持玫瑰花成品效果图 三、代码演示方法和代码命令解释 四、草莓熊手持的玫瑰花源代码 五、相关资源图片 六、我的“草莓熊python turtle绘图(玫瑰花版)”绘图源代码 七、草莓熊python turtle绘图(风车版)附源代码 八、怎么才能正常运行

    2024年02月02日
    浏览(37)
  • 【Python Turtle合集】有趣好玩的代码当然要分享给大家啦~(皮卡丘、玫瑰花、小黄人......)

    🚀 作者 :“程序员梨子” 🚀 **文章简介 **:本篇文章主要是写了利用Turtle库绘制四种不一样的图案的小程序! 🚀 **文章源码免费获取 : 为了感谢每一个关注我的小可爱💓每篇文章的项目源码都是无 偿分享滴💓👇👇👇👇 点这里蓝色这行字体自取,需要什么源码记得

    2023年04月13日
    浏览(43)
  • Python玫瑰花

    序号 文章目录 直达链接 1 浪漫520表白代码 https://want595.blog.csdn.net/article/details/130666881 2 满屏表白代码 https://want595.blog.csdn.net/article/details/129794518 3 跳动的爱心 https://want595.blog.csdn.net/article/details/129503123 4 漂浮爱心 https://want595.blog.csdn.net/article/details/128808630 5 爱心光波 https://wa

    2024年02月08日
    浏览(33)
  • Python绘制玫瑰花

    前言 一、第一种画法 二、第二种画法 总结 今天我们来画一朵玫瑰花。 这应该是最好看玫瑰花了。 第二种就稍逊一筹了,但也挺好看。 所画玫瑰花的库用的只是turtle,但代码却很多。

    2024年02月05日
    浏览(28)
  • python绘制立体玫瑰花

    2024年02月08日
    浏览(31)
  • 【Python炫酷系列】这个3D星空好有趣(完整代码)

    python3.11.4及以上版本 PyCharm Community Edition 2023.2.5 pyinstaller6.2.0 ( 可选 ,这个库用于打包,使程序没有python环境也可以运行,如果想发给好朋友的话需要这个库哦~) 【注】 python环境搭建请见:https://want595.blog.csdn.net/article/details/134586653 pyinstaller使用教程见:h

    2024年02月03日
    浏览(31)
  • 写给女朋友的动态爱心代码html(可修改名字)

    写给女朋友的爱心代码html(可修改名字) 桌面新建一个txt文件,把代码复制进去,再把后缀改成.html

    2024年02月04日
    浏览(43)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包