实战: 跨年烟花代码的实现(附源码)

2023-11-18

目录

前言

一、pandas是什么?

二、代码结构

1.介绍主html代码

2. js文件介绍

GameCanvas.js

script.js

运行效果


前言

本文章将介绍跨年烟花代码的实现以及源代码


提示:以下是本篇文章正文内容

一、pandas是什么?

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

二、代码结构

1.介绍主html代码

代码如下:

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>2023新年快乐</title>
</head>

<body>

<script src='js/gameCanvas-4.0.js'></script>
<script src="js/script.js"></script>

<setTimeout(function() {
    setInterval(function() {
      fireworks.push(new Firework(Math.random() * width, height, Math.random() - 0.5, -(Math.random() * 7 + 5)));
    }, 200);
  }, 2000);
  
  fireworks.push(new Firework(width / 2, height, 0, -9.5, 10, "gold", true));
  setInterval(function() {
    fireworks.push(new Firework(width / 2, height, 0, -9.5, 10, "gold", true));
  }, 5000);
  
  for (var i = 0; i < 250; i++) {
    circle(
      Math.random() * width,
      Math.random() * height,
      1,
      "rgb(200, 200, 200)"
    );
  }
  var starImage = canvasToImage();
  
  background("black");
  loop();
  function loop() {
    gc.ctx.globalCompositeOperation = "source-over";
    background("rgba(0, 0, 0, 0.1)");
    gc.ctx.drawImage(starImage, 0, 0);
    gc.ctx.globalCompositeOperation = "lighter";
    
    for (var i = 0; i < fireworks.length; i++) {
      var firework = fireworks[i];
      firework.update();
      firework.render();
    }
    
    for (var i = 0; i < particles.length; i++) {
      var particle = particles[i];
      particle.update();
      particle.render();
    }
    
    for (var i = 0; i < titleParticles.length; i++) {
      var p = titleParticles[i];
      p.update();
      p.render();
    }
    
    requestAnimationFrame(loop);
  }
  
  function TitleParticle(x, y, vx, vy) {
    this.x = x;
    this.y = y;
    this.vx = vx;
    this.vy = vy;
    this.ay = 0.2;
    this.radius = 4;
    this.maxHealth = 200;
    this.health = 200;
    
    this.update = function() {
      this.x += this.vx;
      this.y += this.vy;
      this.vx *= 0.95;
      this.vy *= 0.95;
      this.vy += this.ay;
      this.ay *= 0.95;
      
      this.radius = (this.health / this.maxHealth) * 4;
      this.health--;
      if (this.health <= 0) {
        titleParticles.splice(titleParticles.indexOf(this), 1);
      }
    }
    
    this.render = function() {
       circle(this.x, this.y, this.radius, "rgba(255, 255, 255, " + (this.health / this.maxHealth) + ")");
    }
  }
  
  function Firework(x, y, vx, vy, radius = 5, color = "white", title = false) {
    this.x = x;
    this.y = y;
    this.vx = vx;
    this.vy = vy;
    this.radius = radius;
    this.title = title;
    this.color = color;
</body>

</html>

可以看到引入了两个js文件,也同样在本地。 

2. js文件介绍

代码如下:

GameCanvas.js

function GameCanvas(settings) {
  let top = this;
  
  this.functions = [];
  this.keys = [];
  this.images = [];
  this.spheres = [];
  this.font = "Arial";
  this.imageData = undefined;
  this.imageDataData = undefined;
  this.lastLoop = performance.now();
  this.calculateFPS = true;
  this.fps = -1;
  this.deltaTime = 1;
  let mouseLookupTable = [
    "left",
    "middle",
    "right"
  ];
  this.contextMenuDisabled = false;
  this.disableScrollOnMobile = false;
  this.eventFunctions = {
    "mousedown": typeof OnMouseDown !== "undefined",
    "mouseup": typeof OnMouseUp !== "undefined",
    "mousemove": typeof OnMouseMove !== "undefined",
    "contextmenu": typeof OnContextMenu !== "undefined",
    "touchstart": typeof OnTouchStart !== "undefined",
    "touchend": typeof OnTouchEnd !== "undefined",
    "touchmove": typeof OnTouchMove !== "undefined",
  };
  this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
  
  this.createCanvas = function() {
    let canvas = document.createElement("canvas");
    document.body.appendChild(canvas);
    return canvas;
  }
  this.setSize = function(width, height) {
    if (top.canvas) {
      top.canvas.width = top.width = width;
      top.canvas.height = top.height = height;
      window.width = this.width;
      window.height = this.height;
    }
    else {
      console.error("There is no canvas!");
    }
  }
  this.fillPageWithCanvas = function() {
    top.canvas.style.position = "fixed";
    top.canvas.style.top = "0px";
    top.canvas.style.left = "0px";
    top.setSize(window.innerWidth, window.innerHeight);
    top.disableScrollOnMobile = true;
    top.contextMenuDisabled = true;
    this.updateSizeOnResize = true;
  }
  this.requestFullscreen = function() {
    if (top.canvas.requestFullscreen)
      top.canvas.requestFullscreen();
    else if (top.canvas.mozRequestFullScreen)
      top.canvas.mozRequestFullScreen();
    else if (top.canvas.webkitRequestFullscreen)
      top.canvas.webkitRequestFullscreen();
    else if (top.canvas.msRequestFullscreen)
      top.canvas.msRequestFullscreen();
  }
  this.exitFullscreen = function() {
    if(document.exitFullscreen)
      document.exitFullscreen();
    else if(document.mozCancelFullScreen)
      document.mozCancelFullScreen();
    else if(document.webkitExitFullscreen)
      document.webkitExitFullscreen();
    else if(document.msExitFullscreen)
      document.msExitFullscreen();
  }
  this.lockPointer = function() {
    top.canvas.requestPointerLock = top.canvas.requestPointerLock || top.canvas.mozRequestPointerLock;
    top.canvas.requestPointerLock();
  }
  this.unlockPointer = function() {
    document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock;
    document.exitPointerLock();
  }
  this.disableContextMenu = function() {
    top.contextMenuDisabled = true;
  }
  this.enableContextMenu = function() {
    top.contextMenuDisabled = false;
  }
  
  this.key = function(key) {
    return top.keys[key];
  }
  
  this.update = function() {
    if (top.calculateFPS) {
      var thisLoop = performance.now();
      top.fps = 1000 / (thisLoop - top.lastLoop);
      top.deltaTime = 60 / top.fps;
      top.lastLoop = thisLoop;
      
      if (top.globalFunctions) {
        window.fps = top.fps;
        window.deltaTime = top.deltaTime;
      }
    }
    
    top.mouse.movementX = 0;
    top.mouse.movementY = 0;
    top.mouse.lastX = top.mouse.x;
    top.mouse.lastY = top.mouse.y;
  }
  
  /******************
  
       Rendering
     
   ******************/
  
  this.clearScreen = function() {
    top.ctx.clearRect(0, 0, top.width, top.height);
  }
  
  this.background = function(color) {
    top.ctx.fillStyle = color;
    top.ctx.fillRect(0, 0, top.width, top.height);
  }
  
  this.circle = function(x, y, radius, color, strokeColor, lineWidth) {
    top.ctx.beginPath();
    top.ctx.arc(x, y, radius, 0, Math.PI * 2);
    top.ctx.fillStyle = color;
    if (strokeColor) top.ctx.strokeStyle = strokeColor;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    top.ctx.fill();
    if (strokeColor) top.ctx.stroke();
  }
  
  this.ring = function(x, y, radius, color, lineWidth) {
    top.ctx.beginPath();
    top.ctx.arc(x, y, radius, 0, Math.PI * 2);
    top.ctx.strokeStyle = color;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    top.ctx.stroke();
  }
  
  this.ellipse = function(x, y, radiusX, radiusY, color, rotation = 0, strokeColor, lineWidth) {
    top.ctx.beginPath();
    top.ctx.ellipse(x, y, radiusX, radiusY, rotation, 0, Math.PI * 2);
    top.ctx.fillStyle = color;
    if (strokeColor) top.ctx.strokeStyle = strokeColor;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    top.ctx.fill();
    if (strokeColor) top.ctx.stroke();
  }
  
  this.rectangle = function(x, y, width, height, color, strokeColor, lineWidth) {
    top.ctx.fillStyle = color;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    if (strokeColor) {
      top.ctx.beginPath();
      top.ctx.strokeStyle = strokeColor;
      top.ctx.rect(x, y, width, height);
      top.ctx.fill();
      top.ctx.stroke();
    }
    else
      top.ctx.fillRect(x, y, width, height);
  }
  
  this.triangle = function(x1, y1, x2, y2, x3, y3, color, strokeColor, lineWidth) {
    top.ctx.beginPath();
    top.ctx.moveTo(x1, y1);
    top.ctx.lineTo(x2, y2);
    top.ctx.lineTo(x3, y3);
    top.ctx.closePath();
    top.ctx.fillStyle = color;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    top.ctx.fill();
    if (strokeColor) {
      top.ctx.strokeStyle = strokeColor;
      top.ctx.stroke();
    }
  }
  
  this.setLineCap = function(lineCap) {
    top.ctx.lineCap = lineCap;
  }
  
  this.resetLineCap = function() {
    top.ctx.lineCap = "butt";
  }
  
  this.line = function(x1, y1, x2, y2, strokeWeight, color) {
    top.ctx.beginPath();
    top.ctx.moveTo(x1, y1);
    top.ctx.lineTo(x2, y2);
    if (color) top.ctx.strokeStyle = color;
    if (strokeWeight) top.ctx.lineWidth = strokeWeight;
    top.ctx.stroke();
  }
  
  this.picture = function(url, x, y, width, height) {
    var imageElement = top.images[url];
    if (!imageElement) {
      var img = new Image();
      img.src = url;
      img.onload = function() {
        top.ctx.drawImage(img, x, y, width, height);
      }
      top.images[url] = img;
    }
    else if (imageElement.complete) {
      top.ctx.drawImage(imageElement, x, y, width, height);
    }
  }
  
  this.setFont = function(font) {
    top.font = font;
  }
  
  this.setTextAlign = function(align) {
    top.ctx.textAlign = align;
  }
  
  this.setTextXAlign = function(align) {
    top.ctx.textAlign = align;
  }
  
  this.setTextYAlign = function(align) {
    top.ctx.textBaseline = align;
  }
  
  this.resetTextXAlign = function() {
    top.ctx.textAlign = "left";
  }
  
  this.resetTextYAlign = function() {
    top.ctx.textBaseline = "alphabetic";
  }
  
  this.text = function(textString, x, y, fontSize, color, strokeColor, lineWidth) {
    top.ctx.beginPath();
    top.ctx.font = fontSize + "px " + top.font;
    top.ctx.fillStyle = color;
    if (lineWidth) top.ctx.lineWidth = lineWidth;
    top.ctx.fillText(textString, x, y);
    if (strokeColor) {
      top.ctx.strokeStyle = strokeColor;
      top.ctx.strokeText(textString, x, y);
    }
  }
  
  this.getPixelData = function() {
    top.imageData = top.ctx.getImageData(0, 0, top.width, top.height);
    top.imageDataData = top.imageData.data;
  }
  
  this.updatePixel = function(x, y, r, g, b, a = 255) {
    let i = (x + y * top.width) * 4;
    top.imageDataData[i] = r;
    top.imageDataData[i + 1] = g;
    top.imageDataData[i + 2] = b;
    top.imageDataData[i + 3] = a;
  }
  
  this.updatePixelIndex = function(index, r, g, b, a = 255) {
    var i = index * 4;
    top.imageDataData[i] = r;
    top.imageDataData[i + 1] = g;
    top.imageDataData[i + 2] = b;
    top.imageDataData[i + 3] = a;
  }
  
  this.getPixel = function(x, y) {
    let i = (x + y * top.width) * 4;
    return [
      top.imageDataData[i],
      top.imageDataData[i + 1],
      top.imageDataData[i + 2],
      top.imageDataData[i + 3]
    ];
  }
  
  this.getPixelIndex = function(index) {
    let i = index * 4;
    return [
      top.imageDataData[i],
      top.imageDataData[i + 1],
      top.imageDataData[i + 2],
      top.imageDataData[i + 3]
    ];
  }
  
  this.renderPixelData = function() {
    /*createImageBitmap(top.imageData).then(function(imgBitmap) {
      top.ctx.drawImage(imgBitmap, 0, 0);
    });*/
    
    top.ctx.putImageData(top.imageData, 0, 0);
  }
  
  this.save = function() {
    top.ctx.save();
  }
  
  this.restore = function() {
    top.ctx.restore();
  }
  
  this.rotate = function(angle) {
    top.ctx.rotate(angle);
  }
  
  this.translate = function(x, y) {
    top.ctx.translate(x, y);
  }
  
  this.beginPath = function() {
    top.ctx.beginPath();
  }
  
  this.closePath = function() {
    top.ctx.closePath();
  }
  
  this.moveTo = function(x, y) {
    top.ctx.moveTo(x, y);
  }
  
  this.lineTo = function(x, y) {
    top.ctx.lineTo(x, y);
  }
  
  this.fill = function() {
    top.ctx.fill();
  }
  
  this.stroke = function() {
    top.ctx.stroke();
  }
  
  this.fillStyle = function(color) {
    top.ctx.fillStyle = color;
  }
  
  this.strokeStyle = function(color) {
    top.ctx.strokeStyle = color;
  }
  
  this.setLineWidth = function(lineWidth) {
    top.ctx.lineWidth = lineWidth;
  }
  
  /******************
  
       3D
     
   ******************/
  
  this.drawSphere = function(screenX, screenY, radius, color, lightDir = {x: 0, y: 0, z: 1}) {
    var id = (screenX + screenY) * radius * (color[0] + 1) * (color[1] + 1) * (color[2] + 1) * (lightDir.x + 1) * (lightDir.y + 1) * (lightDir.z + 1);
    if (top.spheres[id]) {
      if (top.spheres[id].imageData)
        top.ctx.putImageData(top.spheres[id].imageData, screenX - radius, screenY - radius);
      else if (top.spheres[id].image)
        top.ctx.drawImage(top.spheres[id].image, screenX - radius, screenY - radius);
    }
    else {
      var imageData = top.ctx.createImageData(radius * 2, radius * 2);

      for (var y = 0; y < radius * 2; y++) {
        for (var x = 0; x < radius * 2; x++) {
          var line = {
            origin: {x: x, y: y, z: 0},
            direction: {x: 0, y: 0, z: 1}
          };
          var o = {
            position: {x: radius, y: radius, z: radius * 2}
          }

          var oc = {
            x: line.origin.x - o.position.x,
            y: line.origin.y - o.position.y,
            z: line.origin.z - o.position.z
          };
          var loc = top.dot3D(line.direction, oc);
          var ocLength = top.getLength(oc.x, oc.y, oc.z);
          var underSqrt = loc * loc - (ocLength * ocLength - radius * radius);

          if (underSqrt >= 0) {
            var d = -loc - Math.sqrt(underSqrt);
            if (d > 0) { // Circle is not behind player and is closest to player
              var hitPoint = {
                x: line.origin.x + line.direction.x * d,
                y: line.origin.y + line.direction.y * d,
                z: line.origin.z + line.direction.z * d
              };
              var surfaceNormal = top.normalize3DVector({
                x: o.position.x - hitPoint.x,
                y: o.position.y - hitPoint.y,
                z: o.position.z - hitPoint.z
              });

              var diffuse = top.dot3D(lightDir, surfaceNormal);

              var index = (x + y * radius * 2) * 4;
              imageData.data[index] = color[0] * diffuse;
              imageData.data[index + 1] = color[1] * diffuse;
              imageData.data[index + 2] = color[2] * diffuse;
              imageData.data[index + 3] = 255;
            }
          }
        }
      }

      if (window.createImageBitmap) {
        top.spheres[id] = {imageData: undefined, image: undefined};
        createImageBitmap(imageData).then(function(imgBitmap) {
          top.ctx.drawImage(imgBitmap, screenX - radius, screenY - radius);
          top.spheres[id] = {imageData: undefined, image: imgBitmap};
        });
      }
      else {
        top.ctx.putImageData(imageData, screenX - radius, screenY - radius);
        top.spheres[id] = {imageData, image: undefined};
      }
    }
  }
  
  /******************
  
       Audio
     
   ******************/
  
  this.createSound = function(url, volume = 1, startTime = 0, looping = false) {
    var audio = new Audio(url);
    audio.loop = looping;
    audio.currentTime = startTime;
    audio.volume = volume;
    
    return {
      volume,
      startTime,
      audio
    };
  }
  
  this.playSound = function(sound) {
    sound.audio.currentTime = sound.startTime;
    sound.audio.volume = sound.volume;
    sound.audio.play();
  }
  
  this.stopSound = function(sound) {
    sound.audio.stop();
  }
  
  this.pauseSound = function(sound) {
    sound.audio.pause();
  }
  
  this.backgroundMusic = function(url) {
    var audio = new Audio(url);
    audio.loop = true;
    audio.play();
    return audio;
  }
  
  this.fadeOutSound = function(sound, time = 1) {
    var startVolume = sound.volume;
    var count = 0;
    var interv = setInterval(() => {
      sound.audio.volume = (startVolume / (time * 20)) * (time * 20 - count);
      count++;
      if (count > time * 20) {
        sound.audio.pause();
        clearInterval(interv);
      }
    }, 50);
  }
  
  this.playTone = function(freq = 440, time = 1, volume = 1, type = "sine") {
    var oscillator = top.audioContext.createOscillator();
    
    var gainNode = top.audioContext.createGain()
    gainNode.gain.value = volume;
    gainNode.connect(top.audioContext.destination);

    oscillator.type = type;
    oscillator.frequency.value = freq;
    oscillator.connect(gainNode);
    oscillator.start();

    setTimeout(() => {
      oscillator.stop();
    }, time * 1000);
  }
  
  /******************
  
       Math
     
   ******************/
  
  this.DegToRad = Math.PI / 180;
  this.RadToDeg = 180 / Math.PI;
  this.PI = Math.PI;
  this.TWO_PI = Math.PI * 2;
  this.TAU = this.TWO_PI;
  
  this.getDistanceSqr = function(x1, y1, x2, y2) {
    var a = x1 - x2;
    var b = y1 - y2;
    return a * a + b * b;
  }
  
  this.getDistanceSqr3D = function(x1, y1, x2, y2, z1, z2) {
    var a = x1 - x2;
    var b = y1 - y2;
    var c = z1 - z2;
    return a * a + b * b + c * c;
  }
  
  this.getDistance = function(x1, y1, x2, y2) {
    return Math.sqrt(top.getDistanceSqr(x1, y1, x2, y2));
  }
  
  this.getDistance3D = function(x1, y1, x2, y2, z1, z2) {
    return Math.sqrt(top.getDistanceSqr3D(x1, y1, x2, y2, z1, z2));
  }
  
  this.getAngle = function(x1, y1, x2, y2) {
    return Math.atan2(y2 - y1, x2 - x1);
  }
  
  this.normalize = function(x, y) {
    var len = Math.sqrt(x * x + y * y);
    return {
      x: x / len,
      y: y / len
    };
  }
  
  this.normalize3D = function(x, y, z) {
    var len = Math.sqrt(x * x + y * y + z * z);
    return {
      x: x / len,
      y: y / len,
      z: z / len
    };
  }
  
  this.normalize3DVector = function(x) {
    var len = Math.sqrt(x.x * x.x + x.y * x.y + x.z * x.z);
    return {
      x: x.x / len,
      y: x.y / len,
      z: x.z / len
    };
  }
  
  this.lengthVector = function(v) {
    return Math.sqrt(v.x * v.x + v.y * v.y);
  }
  
  this.length3DVector = function(v) {
    return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
  }
  
  this.getLength = function() {
    var sum = 0;
    for (var i = 0; i < arguments.length; i++) {
      var arg = arguments[i];
      sum += arg * arg;
    }
    return Math.sqrt(sum);
  }
  
  this.dot = function(a, b) {
    return a.x * b.x + a.y * b.y;
  }
  
  this.dot3D = function(a, b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
  }
  
  this.crossProduct3D = function(v1, v2) {
    return {
      x: v1.y * v2.z - v1.z * v2.y,
      y: v1.z * v2.x - v1.x * v2.z,
      z: v1.x * v2.y - v1.y * v2.x
    }
  }
  
  //Intersection
  this.rectanglesIntersect = function(x1, y1, w1, h1, x2, y2, w2, h2) {
    return x1 + w1 > x2 && x1 < x2 + w2 && y1 + h1 > y2 && y1 < y2 + h2;
  }
  
  this.circlesIntersect = function(x1, y1, r1, x2, y2, r2) {
    return top.getDistance(x1, y1, x2, y2) < r1 + r2;
  }
  
  this.circleRectangleIntersect = function(x1, y1, r1, x2, y2, w2, h2) {
    var circleDistanceX = Math.abs(x1 - (x2 + w2 / 2));
    var circleDistanceY = Math.abs(y1 - (y2 + h2 / 2));

    if (circleDistanceX > (w2 / 2 + r1)) return false;
    if (circleDistanceY > (h2 / 2 + r1)) return false;

    if (circleDistanceX <= (w2 / 2)) return true; 
    if (circleDistanceY <= (h2 / 2)) return true;

    var a = circleDistanceX - w2 / 2;
    var b = circleDistanceY - h2 / 2;
    var cornerDistance_sq = a * a + b * b;

    return cornerDistance_sq <= (r1 * r1);
  }
  
  //Random
  this.random = function(max) {
    return Math.random() * max;
  }
  
  this.randomInt = function(max) {
    return Math.random() * max >> 0;
  }
  
  this.randomArray = function(array) {
    return array[Math.random() * array.length >> 0];
  }
  
  this.randomColor = function(colorDepth) {
    if (colorDepth) {
      var colorStep = 256 / colorDepth;
      var r = Math.ceil((Math.random() * 256 >> 0) / colorStep) * colorStep;
      var g = Math.ceil((Math.random() * 256 >> 0) / colorStep) * colorStep;
      var b = Math.ceil((Math.random() * 256 >> 0) / colorStep) * colorStep;
      
      return "rgb(" + r + "," + g + "," + b + ")";
    }
    else {
      return "rgb(" + (Math.random() * 256 >> 0) + "," + (Math.random() * 256 >> 0) + "," + (Math.random() * 256 >> 0) + ")";
    }
  }
  
  this.create2DArray = function(w, h, value = () => 0) {
    var array = new Array(w);
    for (var i = 0; i < w; i++) {
      array[i] = new Array(h);
      for (var j = 0; j < h; j++) {
        array[i][j] = value(i, j);
      }
    }
    
    return array;
  }
  
  /******************
  
       Export
     
   ******************/
  
  this.canvasToURL = function() {
    return top.canvas.toDataURL();
  }

  this.canvasToImage = function() {
    var img = new Image();
    img.src = top.canvas.toDataURL();
    return img;
  }

  this.saveToFile = function(filename = "canvas.png") {
    var a = document.createElement("a");
    a.download = filename;
    a.href = top.canvas.toDataURL();
    a.click();
  }
  
  /******************
  
       Cookies
     
   ******************/
  
  this.setCookie = function(name, value, expireDays = 36500) {
    let d = new Date();
    d.setTime(d.getTime() + (expireDays * 24 * 60 * 60 * 1000));
    let expires = "expires=" + d.toUTCString();
    document.cookie = name + "=" + value + ";" + expires + ";path=/";
  }
  
  this.getCookie = function(name) {
    if (name.length == 0)
      return false;
    
    var cname = name + "=";
    var split = document.cookie.split(";");
    for (let i = 0; i < split.length; i++) {
      let s = split[i];
      var index = s.indexOf(cname);
      if (index > 0) {
        return s.substr(index + cname.length);
      }
    }
    return false;
  }
  
  this.deleteCookie = function(name) {
    document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/";
  }
  
  /******************
  
       Misc.
     
   ******************/
  
  //Battery level
  if (navigator.getBattery) {
    navigator.getBattery().then(function (battery) {
      battery.addEventListener('levelchange', function() {
        top.batteryLevel = battery.level * 100;
      });
      top.batteryLevel = battery.level * 100;
    });
  }
  
  this.getBatteryLevel = function() {
    return top.batteryLevel;
  }
  
  /******************
  
       Functions
     
   ******************/
  
  this.functions = [
    {func: this.createCanvas, name: "createCanvas"},
    {func: this.setSize, name: "setSize"},
    {func: this.fillPageWithCanvas, name: "fillPageWithCanvas"},
    {func: this.requestFullscreen, name: "requestFullscreen"},
    {func: this.exitFullscreen, name: "exitFullscreen"},
    {func: this.lockPointer, name: "lockPointer"},
    {func: this.unlockPointer, name: "unlockPointer"},
    {func: this.disableContextMenu, name: "disableContextMenu"},
    {func: this.enableContextMenu, name: "enableContextMenu"},
    {func: this.key, name: "key"},
    {func: this.update, name: "update"},
    
    {func: this.clearScreen, name: "clearScreen"},
    {func: this.background, name: "background"},
    {func: this.circle, name: "circle"},
    {func: this.ring, name: "ring"},
    {func: this.ellipse, name: "ellipse"},
    {func: this.rectangle, name: "rectangle"},
    {func: this.triangle, name: "triangle"},
    {func: this.picture, name: "picture"},
    {func: this.setLineCap, name: "setLineCap"},
    {func: this.resetLineCap, name: "resetLineCap"},
    {func: this.line, name: "line"},
    {func: this.setFont, name: "setFont"},
    {func: this.setTextAlign, name: "setTextAlign"},
    {func: this.setTextXAlign, name: "setTextXAlign"},
    {func: this.setTextYAlign, name: "setTextYAlign"},
    {func: this.resetTextXAlign, name: "resetTextXAlign"},
    {func: this.resetTextYAlign, name: "resetTextYAlign"},
    {func: this.text, name: "text"},
    {func: this.getPixelData, name: "getPixelData"},
    {func: this.updatePixel, name: "updatePixel"},
    {func: this.updatePixelIndex, name: "updatePixelIndex"},
    {func: this.getPixel, name: "getPixel"},
    {func: this.getPixelIndex, name: "getPixelIndex"},
    {func: this.renderPixelData, name: "renderPixelData"},
    {func: this.save, name: "save"},
    {func: this.restore, name: "restore"},
    {func: this.rotate, name: "rotate"},
    {func: this.translate, name: "translate"},
    {func: this.beginPath, name: "beginPath"},
    {func: this.closePath, name: "closePath"},
    {func: this.moveTo, name: "moveTo"},
    {func: this.lineTo, name: "lineTo"},
    {func: this.fill, name: "fill"},
    {func: this.stroke, name: "stroke"},
    {func: this.fillStyle, name: "fillStyle"},
    {func: this.strokeStyle, name: "strokeStyle"},
    {func: this.setLineWidth, name: "setLineWidth"},
    
    {func: this.drawSphere, name: "drawSphere"},
    
    {func: this.createSound, name: "createSound"},
    {func: this.playSound, name: "playSound"},
    {func: this.stopSound, name: "stopSound"},
    {func: this.pauseSound, name: "pauseSound"},
    {func: this.fadeOutSound, name: "fadeOutSound"},
    {func: this.playTone, name: "playTone"},
    
    {func: this.getDistanceSqr, name: "getDistanceSqr"},
    {func: this.getDistance, name: "getDistance"},
    {func: this.getDistanceSqr3D, name: "getDistanceSqr3D"},
    {func: this.getDistance3D, name: "getDistance3D"},
    {func: this.getAngle, name: "getAngle"},
    {func: this.normalize, name: "normalize"},
    {func: this.normalize3D, name: "normalize3D"},
    {func: this.normalize3D, name: "normalize3DVector"},
    {func: this.getLength, name: "getLength"},
    {func: this.dot, name: "dot"},
    {func: this.dot3D, name: "dot3D"},
    {func: this.crossProduct3D, name: "crossProduct3D"},
    {func: this.lengthVector, name: "lengthVector"},
    {func: this.length3DVector, name: "length3DVector"},
    
    {func: this.rectanglesIntersect, name: "rectanglesIntersect"},
    {func: this.circlesIntersect, name: "circlesIntersect"},
    {func: this.circleRectangleIntersect, name: "circleRectangleIntersect"},
    
    {func: this.random, name: "random"},
    {func: this.randomInt, name: "randomInt"},
    {func: this.randomArray, name: "randomArray"},
    {func: this.randomColor, name: "randomColor"},
    
    {func: this.create2DArray, name: "create2DArray"},
    
    {func: this.canvasToURL, name: "canvasToURL"},
    {func: this.canvasToImage, name: "canvasToImage"},
    {func: this.saveToFile, name: "saveToFile"},
    
    {func: this.setCookie, name: "setCookie"},
    {func: this.getCookie, name: "getCookie"},
    {func: this.deleteCookie, name: "deleteCookie"},
    
    {func: this.getBatteryLevel, name: "getBatteryLevel"}
  ];
  
  this.variables = [
    {variable: this.RadToDeg, name: "RadToDeg"},
    {variable: this.DegToRad, name: "DegToRad"},
    {variable: this.PI, name: "PI"},
    {variable: this.TWO_PI, name: "TWO_PI"},
    {variable: this.TAU, name: "TAU"}
  ];
  
  this.makeFunctionsGlobal = function() {
    this.globalFunctions = true;
    this.functions.forEach(item => {
      window[item.name] = item.func;
    });
    this.variables.forEach(item => {
      window[item.name] = item.variable;
    });
    
    window.fps = this.fps;
    window.deltaTime = this.deltaTime;
  }
  
  /******************
  
       Init
     
   ******************/
  
  this.settings = settings;
  if (typeof this.settings === 'undefined') {
    //Create a canvas and make it fullscreen
    this.canvas = this.createCanvas();
    this.fillPageWithCanvas();
    
    this.makeFunctionsGlobal();
  }
  else {
    if (typeof this.settings.canvas !== "undefined")
      this.canvas = this.settings.canvas;
    else {
      this.canvas = this.createCanvas();
      if (typeof this.settings.width === "undefined" &&
          typeof this.settings.height === "undefined")
        this.fillPageWithCanvas();
      
      if (typeof this.settings.globalFunctions === "undefined" || (typeof this.settings.globalFunctions !== "undefined" && this.settings.globalFunctions))
        this.makeFunctionsGlobal();
    }
    if (typeof this.settings.width !== "undefined") {
      this.width = this.settings.width;
      this.canvas.width = window.width = this.width;
    }
    if (typeof this.settings.height !== "undefined") {
      this.height = this.settings.height;
      this.canvas.height = window.height = this.height;
    }
    if (typeof this.settings.updateSizeOnResize !== "undefined") {
      this.updateSizeOnResize = this.settings.updateSizeOnResize;
    }
  }
  
  document.addEventListener("keydown", event => {
    this.keys[event.key] = this.keys[event.keyCode] = true;
  });
  document.addEventListener("keyup", event => {
    this.keys[event.key] = this.keys[event.keyCode] = false;
  });
  
  if (this.canvas) {
    this.ctx = this.canvas.getContext("2d");
    
    if (this.updateSizeOnResize) {
      window.addEventListener("resize", () => {
        this.setSize(window.innerWidth, window.innerHeight);
      });
    }
    
    this.mouse = {x: 0, y: 0, lastX: 0, lastY: 0, movementX: 0, movementY: 0, left: false, middle: false, right: false, down: false};
    this.touches = [];
    if (this.globalFunctions) {
      window.mouse = this.mouse;
      window.touches = this.touches;
    }
    
    this.canvas.addEventListener("mousemove", event => {
      let br = this.canvas.getBoundingClientRect();
      this.mouse.x = (event.clientX - br.left) / (br.width / this.width);
      this.mouse.y = (event.clientY - br.top) / (br.height / this.height);
      this.mouse.movementX = event.movementX;
      this.mouse.movementY = event.movementY;
      
      this.eventFunctions["mousemove"] && OnMouseMove(event);
    });
    
    this.canvas.addEventListener("mousedown", event => {
      let button = event.button;
      if (button < 3)
        this.mouse[mouseLookupTable[button]] = true;
      
      if (!this.audioContext)
        this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
      
      this.eventFunctions["mousedown"] && OnMouseDown(event);
    });
    
    this.canvas.addEventListener("mouseup", event => {
      let button = event.button;
      if (button < 3)
        this.mouse[mouseLookupTable[button]] = false;
      
      this.eventFunctions["mouseup"] && OnMouseUp(event);
    });
    
    this.canvas.addEventListener("contextmenu", event => {
      this.eventFunctions["contextmenu"] && OnContextMenu(event);
      
      if (this.contextMenuDisabled) {
        event.preventDefault();
        return false;
      }
      return true;
    });
    
    //Touch
    
    this.updateTouches = function() {
      let br = this.canvas.getBoundingClientRect();
      
      this.touches = [];
      for (let i = 0; i < event.touches.length; i++) {
        var e = event.touches[i];
        var x = (e.pageX - br.left) / (br.width / this.width);
        var y = (e.pageY - br.top) / (br.height / this.height);
        this.touches[i] = {x, y, id: e.identifier, force: e.force};
      }
      
      if (this.globalFunctions)
        window.touches = this.touches;
    }
    
    this.canvas.addEventListener("touchmove", event => {
      if (this.disableScrollOnMobile)
        event.preventDefault();
     
      this.updateTouches();
      this.mouse.x = this.touches[0].x;
      this.mouse.y = this.touches[0].y;
      
      this.eventFunctions["touchmove"] && OnTouchMove(event);
    });
    
    this.canvas.addEventListener("touchend", event => {
      if (this.disableScrollOnMobile)
        event.preventDefault();
      
      this.touches = [];
      if (this.globalFunctions)
        window.touches = this.touches;
      
      this.mouse.left = false;
      
      this.eventFunctions["touchend"] && OnTouchEnd(event);
    });
    
    this.canvas.addEventListener("touchstart", event => {
      if (this.disableScrollOnMobile)
        event.preventDefault();
      
      this.updateTouches();
      this.mouse.x = this.touches[0].x;
      this.mouse.y = this.touches[0].y;
      this.mouse.left = true;
      
      if (!this.audioContext)
        this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
      
      this.eventFunctions["touchstart"] && OnTouchStart(event);
    });
  }
}

script.js

修改var points中包裹的文本可以改变烟花爆炸时出现的文字


var gc = new GameCanvas();

var points = textToPoints(" 2023新年快乐!", 15, "Anton");


var titleParticles = [];
var fireworks = [];
var particles = [];

var gravity = 0.1;

setTimeout(function() {
  setInterval(function() {
    fireworks.push(new Firework(Math.random() * width, height, Math.random() - 0.5, -(Math.random() * 7 + 5)));
  }, 200);
}, 2000);

fireworks.push(new Firework(width / 2, height, 0, -9.5, 10, "gold", true));
setInterval(function() {
  fireworks.push(new Firework(width / 2, height, 0, -9.5, 10, "gold", true));
}, 5000);

for (var i = 0; i < 250; i++) {
  circle(
    Math.random() * width,
    Math.random() * height,
    1,
    "rgb(200, 200, 200)"
  );
}
var starImage = canvasToImage();

background("black");
loop();
function loop() {
  gc.ctx.globalCompositeOperation = "source-over";
  background("rgba(0, 0, 0, 0.1)");
  gc.ctx.drawImage(starImage, 0, 0);
  gc.ctx.globalCompositeOperation = "lighter";
  
  for (var i = 0; i < fireworks.length; i++) {
    var firework = fireworks[i];
    firework.update();
    firework.render();
  }
  
  for (var i = 0; i < particles.length; i++) {
    var particle = particles[i];
    particle.update();
    particle.render();
  }
  
  for (var i = 0; i < titleParticles.length; i++) {
    var p = titleParticles[i];
    p.update();
    p.render();
  }
  
  requestAnimationFrame(loop);
}

function TitleParticle(x, y, vx, vy) {
  this.x = x;
  this.y = y;
  this.vx = vx;
  this.vy = vy;
  this.ay = 0.2;
  this.radius = 4;
  this.maxHealth = 200;
  this.health = 200;
  
  this.update = function() {
    this.x += this.vx;
    this.y += this.vy;
    this.vx *= 0.95;
    this.vy *= 0.95;
    this.vy += this.ay;
    this.ay *= 0.95;
    
    this.radius = (this.health / this.maxHealth) * 4;
    this.health--;
    if (this.health <= 0) {
      titleParticles.splice(titleParticles.indexOf(this), 1);
    }
  }
  
  this.render = function() {
     circle(this.x, this.y, this.radius, "rgba(255, 255, 255, " + (this.health / this.maxHealth) + ")");
  }
}

function Firework(x, y, vx, vy, radius = 5, color = "white", title = false) {
  this.x = x;
  this.y = y;
  this.vx = vx;
  this.vy = vy;
  this.radius = radius;
  this.title = title;
  this.color = color;
  
  this.update = function() {
    this.x += this.vx;
    this.y += this.vy;
    this.vy += gravity;
    
    if (this.vy >= 0) {
      fireworks.splice(fireworks.indexOf(this), 1);
      
      if (this.title) {
        var scale = 0.3;
        for (var i = 0; i < points.length; i++) {
          var p = points[i];
          var v = {
            x: (p.x - 60) * scale + (Math.random() - 0.5) * 0.1,
            y: (p.y - 20) * scale + (Math.random() - 0.5) * 0.1
          }
          var particle = new TitleParticle(this.x, this.y, v.x, v.y);
          titleParticles.push(particle);
        }
      }
      else {
        var color = [Math.random() * 256 >> 0, Math.random() * 256 >> 0, Math.random() * 256 >> 0];
        for (var i = 0; i < Math.PI * 2; i += 0.1) {
          var power = (Math.random() + 0.5) * 4;
          var vx = Math.cos(i) * power;
          var vy = Math.sin(i) * power;
          particles.push(new Particle(this.x, this.y, vx, vy, Math.random() + 3, color));
        }
      }
    }
  }
  
  this.render = function() {
    circle(this.x, this.y, this.radius, this.color);
  }
}

function Particle(x, y, vx, vy, radius, color) {
  this.x = x;
  this.y = y;
  this.vx = vx;
  this.vy = vy;
  this.life = 100;
  this.color = color;
  this.radius = radius;
  
  this.update = function() {
    this.x += this.vx;
    this.y += this.vy;
    this.vy += gravity;
    
    this.vx *= 0.95;
    this.vy *= 0.95;
    
    this.life--;
    if (this.life <= 0) {
      particles.splice(particles.indexOf(this), 1);
    }
  }
  
  this.render = function() {
    circle(this.x, this.y, 3 * (this.life / 100), "rgba(" + this.color[0] + ", " + this.color[1] + ", " + this.color[2] + ", " + (this.life / 100) + ")");
  }
}

function textToPoints(text, textSize, font) {
  var canvas = document.createElement("canvas");
  canvas.width = 1024;
  canvas.height = textSize * 1.3;
  var ctx = canvas.getContext("2d");
  
  ctx.textBaseline = "middle";
  ctx.font = textSize + "px " + font;
  ctx.fillText(text, 0, canvas.height / 2);
  
  var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  var data = imageData.data;
  
  var points = [];
  var index = (x, y) => (x + canvas.width * y) * 4;
  var threshold = 50;
  
  for (var i = 0; i < data.length; i += 4) {
    if (data[i + 3] > threshold) {
      var p = {
        x: (i / 4) % canvas.width,
        y: (i / 4) / canvas.width >> 0
      };
      
      if (data[index(p.x + 1, p.y) + 3] < threshold ||
          data[index(p.x - 1, p.y) + 3] < threshold ||
          data[index(p.x, p.y + 1) + 3] < threshold ||
          data[index(p.x, p.y - 1) + 3] < threshold) {
        points.push({
          x: (i / 4) % canvas.width,
          y: (i / 4) / canvas.width >> 0
        });
      }
    }
  }
  
  return points;
}

运行效果

光说不练假把式,看图:

运行效果如下

 


总结

以上就是今天要讲的内容,本文介绍了跨年烟花代码使用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

实战: 跨年烟花代码的实现(附源码) 的相关文章

  • 使用 CSS 使一行 div 高度相同

    我有一排必须具有相同高度的 div 但我无法提前知道该高度可能是多少 内容来自外部源 我最初尝试将 div 放置在封闭的 div 中并将它们向左浮动 然后我将它们的高度设置为 100 但这没有明显的效果 通过将封闭 div 的高度设置为固定
  • 在f字符串中转义字符[重复]

    这个问题在这里已经有答案了 我遇到了以下问题f string gt gt gt a hello how to print hello gt gt gt f a a gt gt gt f a File
  • python获取上传/下载速度

    我想在我的计算机上监控上传和下载速度 一个名为 conky 的程序已经在 conky conf 中执行了以下操作 Connection quality alignr wireless link qual perc wlan0 downspe
  • 如何解决 Typescript 构建中的错误“找不到模块 'jquery'”

    我目前在 ts 文件的顶部有这个import require jquery 我这样做是因为我试图在我的打字稿文件中使用 jquery 但我似乎无法编译它 因为它返回标题中所述的错误 我正在使用 ASP NET CORE 脚本文件夹 tsco
  • Javascript split 不是一个函数

    嘿朋友们 我正在使用 javascript sdk 通过 jQuery facebook 多朋友选择器在用户朋友墙上发布信息 但是我收到此错误friendId split 不是函数 这是我的代码 function recommendToFr
  • Pandas:merge_asof() 对多行求和/不重复

    我正在处理两个数据集 每个数据集具有不同的关联日期 我想合并它们 但因为日期不完全匹配 我相信merge asof 是最好的方法 然而 有两件事发生merge asof 不理想的 数字重复 数字丢失 以下代码是一个示例 df a pd Da
  • DataTables row.add 到特定索引

    我正在替换这样的行项目 var targetRow entity row dataTable targetRow closest table dataTable DataTable dataTable row targetRow remov
  • Javascript 假值(null、未定义、false、空字符串:“”或 '' 和 0)和比较(==)运算符 [重复]

    这个问题在这里已经有答案了 当我使用任何一个值时 null undefined false 0 in a if陈述 它总是被评估为谬误 false 另外 这些值的否定 null undefined false 0 in a if语句总是被评
  • Firebase 函数 onWrite 未被调用

    我正在尝试使用 Firebase 函数实现一个触发器 该触发器会复制数据库中的一些数据 我想观看所有添加的内容votes user vote 结构为 我尝试的代码是 const functions require firebase func
  • 代码镜像错误:未捕获错误:扩展集中无法识别扩展值([对象对象])

    全部 我目前正在从事一个React Electron项目 该项目的目标是完成一个Markdown编辑器 当我配置codemirror 该程序报告错误说 Uncaught Error Unrecognized extension value
  • 如何使用 crypto-js 解密 AES ECB

    我正在尝试将加密数据从 flash 客户端 发送到服务器端的 javascript 在 asp 中作为 jscript 运行 有几个 javascript Aes 库 但它们实际上没有文档记录 我正在尝试使用 crypto js 但无法让代
  • 在 Shopify 商店中嵌入 Vue 组件

    在产品页面中 我尝试显示自定义 Vue 组件 为简洁起见 该组件根据给定的产品 ID 显示 Firebase 数据库中的一些信息 我最初尝试将其制作为 Shopify 应用程序 以便我可以访问他们的 API 我实现了 OAuth 并且可以检
  • 如何隐藏/禁用 Highcharts.js 中的图例框?

    我想问是否可以使用 HighCharts js 库隐藏图表中的所有图例框 var chart object chart renderTo render to type graph type colors graph colors title
  • 带参数的事件监听器

    我想将参数传递给 JavaScript 中的事件侦听器 我已经找到了解决方案 但我无法理解它们为什么或如何工作以及为什么其他解决方案不起作用 我有 C C 背景 但是 Javascript 函数的执行有很大不同 您能否帮助我理解以下示例如何
  • HTML 锚点,禁用样式

    我有一些 html 锚链接代码 与文档的其余部分不同 我希望它看起来不是链接 有没有一种简单的方法可以禁用由于将文本包装在锚标记中而引起的样式更改 而不必强行使其相同 即 如果我更改正文字体样式 我不必也更改其他一些 link东西 将颜色设
  • 在 CKEditor 中设置字体大小和字体系列

    我正在使用 ckeditor 我想问一下这个插件如何设置font family和font size 我尝试过使用 CKEDITOR config font defaultLabel Arial CKEDITOR config fontSiz
  • JavaScript 相对路径

    在第一个 html 文件中 我使用了一个变量类别链接 var categoryLinks Career prospects http localhost Landa DirectManagers 511 HelenaChechik Dim0
  • 导入错误:没有名为 site 的模块 - mac

    我已经有这个问题几个月了 每次我想获取一个新的 python 包并使用它时 我都会在终端中收到此错误 ImportError No module named site 我不知道为什么会出现这个错误 实际上 我无法使用任何新软件包 因为每次我
  • Jquery - 选择选项后如何获取选项的特定数据类型?

    我将直接跳到标记 然后解释我想要做什么 HTML 选择选项
  • Statsmodels.formula.api OLS不显示截距的统计值

    我正在运行以下源代码 import statsmodels formula api as sm Add one column of ones for the intercept term X np append arr np ones 50

随机推荐

  • python水仙花数的编程讲解_Python语言生成水仙花数代码示例

    水仙花数是指一个 n 位数 n 3 它的每个位上的数字的 n 次幂之和等于它本身 本文将通过Python代码实现打印水仙花数 具体如下 水仙花数 narcissistic number 水仙花数是指一个 n 位数 n 3 它的每个位上的数字
  • 如何彻底卸载Anaconda?

    文章目录 0 前言 1 解决方案 1 1方案1 1 2方案2 2 参考文档 0 前言 本机Win10 最好的参考文档是官方文档Uninstalling Anaconda 除此以外 再辅助以其他文档 就能达到如标题所示的目的 整个删除过程不难
  • Unity手游资源修改流程

    最近接到一个Android手游汉化需求 研究了一下 特此记录 开发环境 AssetStudioGUI 该软件可解析 定位压缩后的Unity 资源 下载 https github com Perfare AssetStudio AssetBu
  • 攻防世界-Web新手区- simple_php

    攻防世界 Web新手区 simple php 题目链接 https adworld xctf org cn challenges details hash 97ccaf1c b0ba 4152 88c1 10da78135303 2 tas
  • 通过wiki进行企业内部的知识共享

    其实企业内部的知识共享是一个很复杂的问题 每个人都有自己的经验和Key Knowledge 每次开发也能积累到很多有用的开发经验或者教训 可是怎样才能进行有效的知识共享呢 一个完善的知识共享系统应该具有以下几种特性 易于使用的界面 好的知识
  • 突如其来的C#重新学习(2)

    突如其来的C 重新学习 2 关于Main入口点的问题 Main在C 中不能单独声明 所以必须声明在同一个类中 而且必须声明静态方法 返回可以是void或者int 正常执行应当返回0 对于一个命名空间之内有很多的类的情况下 就可以手动选择从哪
  • 前端网页设置视频背景

    视频设置自动播放 循环播放 静音 一定要设置静音不设置静音的话不会自动播放 video元素设置width 100 height auto 如果height设置100 的话 定位之后会看不到
  • pycharm常用快捷键及快捷键自定义修改

    一 常用快捷键 编辑类 Ctrl D 复制选定的区域或行 Ctrl Y 删除选定的行 Ctrl Alt L 代码格式化 Ctrl Alt O 优化导入 去掉用不到的包导入 Ctrl 鼠标 简介 进入代码定义 Ctrl 行注释 取消注释 Ct
  • 关闭WIN10的wsappx进程服务

    关闭原因 打开电脑登录系统后 发现wsappx进程服务占用CPU极高 并且一直没有降低 如下图所示 解决办法 将以下注册表的值由3修改为4重启系统即可 计算机 HKEY LOCAL MACHINE SYSTEM CurrentControl
  • 手把手帮助你通过Vue+Springboot+MybatisPlus实现一个简单的登录注册页面,0基础

    创建前端vue项目 首先通过脚手架创建vue文件夹 前提 安装好node js软件 安装好后 通过node V 查看版本号 npm V查看npm版本 通过命令安装脚手架 npm install g vue cli g代表全局安装 s代表本地
  • 浅谈Nginx相关HTTP杂项模块(一)

    浅谈Nginx相关HTTP杂项模块 一 1 ngx http access module 2 ngx http auth basic module 3 ngx http stub status module 4 ngx http log m
  • 拷贝本地文件到docker容器

    查找所有容器 docker ps a 找出我们想要的容器名字 查找容器长ID docker inspect f ID python 拷贝本地文件到容器 docker cp 本地路径 容器长ID 容器路径 docker cp Users xu
  • c++ 打印当前时间(精确到毫秒)

    打印时间精确到毫秒好实现 但是那种对用户可读性不好 更适合开头记一次结尾记一次 打印中间减出来的程序运行时间 但是因为一些情况 我开多线程开的不方便打印结束时间 同事跟我说那你把开始时间打印一下 结束他自己接受那边打印 最好精确到毫秒 那就
  • (电赛电源方向)怎么样从零开始准备全国大学生电子设计竞赛

    提示 文章写完后 目录可以自动生成 如何生成可参考右边的帮助文档 文章目录 前言 一 电赛是什么 二 电源方向是什么 三 该怎么去学习电源方向的知识 1 博主的劝诫 2 硬件该准备些什么 3 软件该准备些什么 总结 前言 我建了一个群 分享
  • selenium 常用操作总结

    谷歌驱动下载 http chromedriver storage googleapis com index html 参数设置options opt Options opt add argument headless 无头模式 opt ad
  • 在腾讯连拿六个五星

    刚毕业入职腾讯工作 2 3 年 半年 年终绩效每次都是 5 4 星 不一定年薪百万 主要薪资 奖金无法决定 这个取决于股票是否上涨不少 但晋升肯定是最快的 在阿里拿 375 跟在腾讯拿 5 4 星的比例差不多 应届毕业能拿一次确实很优秀了
  • 15. unity官网资源商店的免费资源引入自己项目中

    1 说明 在unity开发中可以在官网引入一些免费的资源 免得自己找不到合适的素材 第一步 首先进入Unity资源商店官网 https assetstore unity com 计入并登录自己的unity账号 如果没账号 可以注册一个 然后
  • Fisco Bcos区块链五(WeBase结点前置服务)

    文章目录 区块链开荒 技术文档 https webasedoc readthedocs io zh CN latest docs WeBASE Front install html 三 WeBase节点前置服务 1 前提条件 2 拉取代码
  • AIGC驱动产品开发创新,改变你所知的一切!

    你是否想过 3000年后的饮料是什么味道 9月12日 可口可乐全球创意平台 乐创无界 再度推出全新限定产品 首款联合人工智能 AI 打造的无糖可口可乐 未来3000年 从口味研发到包装设计都体现了AI的深度参与打造 Y3000与AI共创这一
  • 实战: 跨年烟花代码的实现(附源码)

    目录 前言 一 pandas是什么 二 代码结构 1 介绍主html代码 2 js文件介绍 GameCanvas js script js 运行效果 前言 本文章将介绍跨年烟花代码的实现以及源代码 提示 以下是本篇文章正文内容 一 pand