Python编程 圣诞树教程 (附代码)专属于程序员的浪漫

文章目录

    • 1.turtle库
    • 2.python函数的定义规则
    • 3.引入库
    • 4.定义画彩灯函数
    • 5.定义画圣诞树的函数
    • 6.定义树下面小装饰的函数
    • 7.定义一个画雪花的函数
    • 8.画五角星
    • 9.写文字
    • 10.全部源代码
    • 11.html圣诞树代码实现(动态音乐)

1.turtle库

turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。
在这里插入图片描述

2.python函数的定义规则

(1)以 def 开头,后接定义函数的名称和圆括号(),以冒号结尾
(2)圆括号()可为空,也可以传入参数
(3)定义函数的内容,与def有缩进关系
(4)调用自定义的函数的基本格式为:定义函数的名称();若圆括号()为空,调用时,也为空,若若圆括号()不为空,调用时需传入参数
(5)return [表达式] 结束函数,选择性地返回一个值给调用方。不带表达式的return相当于返回 None。

3.引入库

import turtle as  t
from turtle import *
import random as r
import  time

4.定义画彩灯函数

#定义画彩灯的函数
def drawlight():
    if r.randint(0,30) == 0:         #randint用来生成随机数
        color('tomato')              #颜色()
        circle(6)                    #根据半径radius绘制extent角度的弧形
    elif r.randint(0,30) == 1:
        color('orange')              #颜色()
        circle(3)
    else:
        linewidth = 5                #线型
        color('dark green')          #颜色

5.定义画圣诞树的函数

#定义画圣诞树的函数
def tree(d,s):         #定义函数 树
    if d <= 0:  return   #返回函数的返回值
    forward(s)           #向前
    tree(d-1, s * .8)
    right(120)           #方向 向右
    tree(d-3, s * .5)
    drawlight()          
    right(120)
    tree(d-3, s * .5)
    right(120)
    backward(s)          #向后 

6.定义树下面小装饰的函数

#定义树下面小装饰的函数
def  xzs():
    for i in range(200):              #范围
        a = 200-400* r.random()       # random模块用于生成随机数
        b = 10 -20* r.random()
        up()
        forward(b)                    #向前
        left(90)                      #左边
        forward(a)
        down()                        #向下
        if  r.randint(0,1) == 0:
            color('tomato')
        else:
            color('wheat')
        circle(2)                      #圆
        up()
        backward(a)
        right(90)
        backward(b)

7.定义一个画雪花的函数

#定义一个画雪花的函数
def drawsnow():
    t.hideturtle()                   #这个方法是用来使Turtle隐身的。          
    t.pensize(2)                     #pensize(数字)可以设置画笔的宽度
    for i in range(200):
        t.pencolor("white")
        t.penup()
        t.setx(r.randint(-350,350))   #将当前x轴移动到指定位置
        t.sety(r.randint(-100,350))   #将当前y轴移动到指定位置
        t.pendown()                   #放下画笔
        dens = 6
        snowsize = r.randint(1,10)    #生成随机数
        for j in range(dens):
            t.forward(int(snowsize))
            t.backward(int(snowsize))
            t.right(int(360/dens))

8.画五角星

#画五角星
for i in range(5):
    forward(n/5)
    right(144)
    forward(n/5)
    left(72)

end_fill()
right(126)

color("dark green")
backward(n * 4.8)

9.写文字

#写文字
t.color("dark red", "red")
t.write("Merry Christmas", align="center", font=("Comic Sans MS", 40, "bold"))
#写 "Merry Christmas" 使成一条直线  居中   字体   似手写的字体   40  粗体

10.全部源代码

import turtle as  t
from turtle import *
import random as r
import  time

#定义几个函数先

#定义画彩灯的函数
def drawlight():
    if r.randint(0,30) == 0:
        color('tomato')
        circle(6)
    elif r.randint(0,30) == 1:
        color('orange')
        circle(3)
    else:
        linewidth = 5
        color('dark green')

#定义画圣诞树的函数
def tree(d,s):
    if d <= 0:  return
    forward(s)
    tree(d-1, s * .8)
    right(120)
    tree(d-3, s * .5)
    drawlight()
    right(120)
    tree(d-3, s * .5)
    right(120)
    backward(s)

#定义树下面小装饰的函数
def  xzs():
    for i in range(200):
        a = 200-400* r.random()
        b = 10 -20* r.random()
        up()
        forward(b)
        left(90)
        forward(a)
        down()
        if  r.randint(0,1) == 0:
            color('tomato')
        else:
            color('wheat')
        circle(2)
        up()
        backward(a)
        right(90)
        backward(b)

#定义一个画雪花的函数
def drawsnow():
    t.hideturtle()
    t.pensize(2)
    for i in range(200):
        t.pencolor("white")
        t.penup()
        t.setx(r.randint(-350,350))
        t.sety(r.randint(-100,350))
        t.pendown()
        dens = 6
        snowsize = r.randint(1,10)
        for j in range(dens):
            t.forward(int(snowsize))
            t.backward(int(snowsize))
            t.right(int(360/dens))


n=100.0
t.pensize(10)
speed("fastest")
t.screensize(800,600, "black")
left(90)
forward(3 * n)
color("orange", "yellow")
begin_fill()
left(126)


#画五角星
for i in range(5):
    forward(n/5)
    right(144)
    forward(n/5)
    left(72)

end_fill()
right(126)

color("dark green")
backward(n * 4.8)


#调用画树的函数
tree(15 , n)
backward(n/2)

xzs()

#写文字
t.color("dark red", "red")
t.write("Merry Christmas", align="center", font=("Comic Sans MS", 40, "bold"))



# 调用雪花函数
drawsnow()

t.done()    #收笔

11.html圣诞树代码实现(动态音乐)

操作过程
首先在桌面创建一个后缀为txt的文件,然后将下面的代码复制进去保存,再将.txt后缀改为html,最后点击这个文件就会出现爱心特效啦~
效果:
在这里插入图片描述
在这里插入图片描述

代码:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
 
  <title>圣诞树</title>
 
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
 
  <style>
   * 
   {
    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;
   }
  </style>
 
  <script>
   window.console = window.console || function(t) {};
  </script>
 
 
 
  <script>
   if (document.location.search.match(/type=embed/gi)) {
    window.parent.postMessage("resize", "*");
   }
  </script>
 
 
 </head>
 
 <body translate="no" >
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/build/three.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/EffectComposer.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/RenderPass.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/ShaderPass.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/shaders/CopyShader.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/shaders/LuminosityHighPassShader.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/three@0.115.0/examples/js/postprocessing/UnrealBloomPass.js"></script>
 
  <div id="overlay">
   <ul>
    <li class="title">请选择音乐</li>
    <li>
     <button class="btn" id="btnA" type="button">
      Snowflakes Falling Down by Simon Panrucker
     </button>
    </li>
    <li><button class="btn" id="btnB" type="button">This Christmas by Dott</button></li>
    <li><button class="btn" id="btnC" type="button">No room at the inn by TRG Banks</button></li>
    <li><button class="btn" id="btnD" type="button">Jingle Bell Swing by Mark Smeby</button></li>
    <li class="separator">或者</li>
    <li>
     <input type="file" id="upload" hidden />
     <label for="upload">Upload File</label>
    </li>
   </ul>
  </div>
 
  <script id="rendered-js" >
   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 =
       '<div class="text-loading">正在下载音乐,请稍等...</div>';
       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 =
       '<div class="text-loading">请稍等...</div>';
       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);
 
      }
 </script>
 
 </body>
 
 </html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/266358.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Java LocalDateTime转Json报错处理

在项目中LocalDateTime 进行json转换时&#xff0c;抛出序列化异常&#xff0c;查找解决方案&#xff0c;记录下来&#xff0c;方便备查。 报错信息 Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type java.time.LocalDateT…

【小白攻略】php 小数转为百分比,保留两位小数的函数

php 小数转为百分比 首先&#xff0c;最简单直观的方法是利用PHP内置的number_format函数。该函数可以对一个数字进行格式化&#xff0c;并可以设置小数点后的精度。通过将小数乘以100&#xff0c;再用number_format函数将结果格式化为百分比形式&#xff0c;即可达到将小数转为…

基于Java SSM框架实现多人试卷批改考试命题系统项目【项目源码+论文说明】计算机毕业设计

基于java的SSM框架实现多人试卷批改考试命题系统演示 摘要 多人命题系统是高校为教师、学生试卷的重要组成部分&#xff0c;是实现人才培养目标、培养学生科研能力与创新思维、检验学生综合素质与实践能力的重要手段与综合性实践教学环节。我所在学院多采用半手工管理学生试卷…

什么是动态代理?

目录 一、为什么需要代理&#xff1f; 二、代理长什么样&#xff1f; 三、Java通过什么来保证代理的样子&#xff1f; 四、动态代理实现案例 五、动态代理在SpringBoot中的应用 导入依赖 数据库表设计 OperateLogEntity实体类 OperateLog枚举 RecordLog注解 上下文相…

车云TCP链路偶现链接失联问题排查

一、问题分析 1.1 车云tcp长连接分析排查 在15:37:32.039上线&#xff0c; 在 16:07:26.527下线&#xff0c;车云长连接通道稳定&#xff0c;且该期间心跳数据正常。 1.2 云向驾仓推送数据分析 在15:37:42 进行车辆接管后&#xff0c;该车辆下线&#xff0c;且无法在上线&am…

Java语法---使用sort进行排序

目录 一、升序 二、降序 &#xff08;1&#xff09;类实现接口 &#xff08;2&#xff09;匿名内部类 三、自定义排序规则 四、集合中的sort排序 &#xff08;1&#xff09;升序 &#xff08;2&#xff09;降序 &#xff08;3&#xff09;自定义排序 一、升序 升序排…

vue3+Ts

安装 命令含义可参考typescript文章中的自动编译部分 npm create vitelatest vuets-project -- --template vue-tsvs code插件 Vue Language Features (Volar)对.vue文件进行实时的类型错误反馈TypeScript Vue Plugin (Volar) 用于支持在TS中import*.vue文件&#xff08;mai…

08-JVM调优实战及常量池详解

文章目录 阿里巴巴Arthas详解Arthas使用场景Arthas使用 GC日志详解打印GC日志方法如何分析GC日志CMSG1 JVM参数汇总查看命令Class常量池与运行时常量池字面量符号引用 字符串常量池字符串常量池的设计思想三种字符串操作(Jdk1.7 及以上版本)字符串常量池位置字符串常量池设计原…

C语言——高精度除法

一、引子 1、引言 高精度除法相较于加减乘法更加复杂&#xff0c;它需要处理的因素更多&#xff0c;在这里我们先探讨高精度数除以低精度数&#xff0c;即大数除小数。这已满足日常所需&#xff0c;如需大数除以大数&#xff0c;可以使用专门的库&#xff0c;例如&#xff1a…

3.Redis持久化

文章目录 RDB&#xff08;Redis DataBase&#xff09;&#xff1a;RDB是什么&#xff1f;RDB能干嘛&#xff1f;RDB自动触发RDB手动触发RDB优点RDB缺点什么情况会触发RDB快照 AOF&#xff08;Append Only File&#xff09;&#xff1a;AOF是什么&#xff1f;AOF能干嘛&#xff…

【Hadoop】 YARN 运行过程/YARN设计目标

YARN 运行过程剖析YARN设计目标 YARN 运行过程剖析 一个Job在YARN中的处理过程&#xff1a; 客户端向RM提交一个job&#xff0c;进入RM中的调度器队列以供调度RM中的AppManager与NM协商协商好一个容器&#xff0c;以启动一个App Master实例App Master启动之后向RM注册并根据Jo…

刷题第五十一天 84. 柱状图中最大矩形

好难&#xff0c;看解析&#xff1a; # 双指针 class Solution:def largestRectangleArea(self, heights: List[int]) -> int:size len(heights)# 两个DP数列储存的均是下标indexmin_left_index [0] * sizemin_right_index [0] * sizeresult 0# 记录每个柱子的左侧第一…

量化服务器 - 后台挂载运行

服务器 - 后台运行 pip3命令被kill 在正常的pip命令后面加上 -no-cache-dir tmux 使用教程 https://codeleading.com/article/40954761108/ 如果你希望在 tmux 中后台执行一个 Python 脚本&#xff0c;你可以按照以下步骤操作&#xff1a; 启动 tmux: tmux这将会创建一个新…

Ubuntu 常用命令之 ps 命令用法介绍

&#x1f4d1;Linux/Ubuntu 常用命令归类整理 ps命令是Linux下的一个非常重要的命令&#xff0c;它用于查看系统中的进程状态。ps是Process Status的缩写&#xff0c;可以显示系统中当前运行的进程的状态。 以下是一些常用的参数 a&#xff1a;显示所有进程&#xff08;包括…

【机器学习】决策树

参考课程视频&#xff1a;https://www.icourse163.org/course/NEU-1462101162?tid1471214452 1 概述 样子&#xff1a; 2 分裂 2.1 分裂原则 信息增益 信息增益比 基尼指数 3 终止 & 剪枝 3.1 终止条件 无需分裂 当前节点内样本同属一类 无法分裂 当前节点内…

【数据结构】四、串

目录 一、定义 二、表示与实现 定长顺序存储 堆分配存储 链式存储 三、BF算法 四、KMP算法 1.求next数组 方法一 方法二&#xff08;考试方法&#xff09; 2.KMP算法实现 方法一 方法二 3.nextval 4.时间复杂度 本节最重要的就是KMP算法&#xff0c;其他要求不高…

融资项目——swagger2的注解

1. ApiModel与ApiModelProperty(在实体类中使用) 如上图&#xff0c;ApiModel加在实体类上方&#xff0c;用于整体描述实体类。ApiModelProperty(value"xxx",example"xxx")放于每个属性上方&#xff0c;用于对属性进行描述。swagger2网页上的效果如下图&am…

c++内存池项目

文章目录 一、内存池介绍二、ThreadCache实现三、CentralCache实现四、PageCache实现五、回收内存六、大于256KB的内存申请与释放七、将new和delete换为定长内存池八、多线程环境下对比malloc进行基准测试九、使用基数树进行性能优化 一、内存池介绍 二、ThreadCache实现 下面…

Wordpress插件WP-Statistics无法识别来访IP国家和城市处理方法

Wordpress插件WP-Statistics&#xff0c;可以识别网站访问者的IP物理地址&#xff0c;统计出城市、国家&#xff0c;但最近发现都显示unknown/未知&#xff1a; 更新GeoIP数据库到最新还是不行&#xff1a; 偶然找到了之前能用的数据库&#xff0c;恢复回去&#xff0c;竟然大…

基于SpringBoot的桃花峪滑雪场租赁系统 JAVA简易版

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 游客服务2.2 雪场管理 三、数据库设计3.1 教练表3.2 教练聘请表3.3 押金规则表3.4 器材表3.5 滑雪场表3.7 售票表3.8 器材损坏表 四、系统展示五、核心代码5.1 查询教练5.2 教练聘请5.3 查询滑雪场5.4 滑雪场预定5.5 新…