大屏天气效果-台风

typhoon-weather

​ 因为可视化大屏的业务需求,需要绘制全屏的天气效果。共用canvas绘制了晴天、雨天、台风天三种天气。在此记录供参考。
在这里插入图片描述

  • html代码
<canvas id="weather"></canvas>
  • JavaScript代码
function typhoonWeather() {
  const canvas = document.getElementById('weather');
  const ctx = canvas.getContext('2d');
  
  // 设置 Canvas 大小
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  const width = canvas.width
  const height = canvas.height

  // 定义雨滴对象
  class Raindrop {
    constructor(x, y, speed, size) {
      this.x = x
      this.y = y
      this.speed = speed
      this.size = size
    }

    update() {
      // 雨滴下落
      this.y += this.speed
      // 如果雨滴超出屏幕,则重新从顶部开始下落
      if (this.y > height) {
        this.y = -this.size
        this.x = Math.random() * width
      }
    }

    draw() {
      // 绘制雨滴
      ctx.beginPath()
      ctx.moveTo(this.x, this.y)
      ctx.lineTo(this.x, this.y + this.size)
      ctx.strokeStyle = '#F5F5F5'
      ctx.lineWidth = 1.5
      ctx.globalAlpha = 0.5
      ctx.stroke()
    }
  }

  // 定义雨滴数组和数量
  const raindrops = []
  const NUM_RAINDROPS = 500

  // 初始化雨滴数组
  for (let i = 0; i < NUM_RAINDROPS; i++) {
    const x = Math.random() * width
    const y = Math.random() * height
    const speed = 10 + Math.random() * 10
    const size = 5 + Math.random() * 10
    const raindrop = new Raindrop(x, y, speed, size)
    raindrops.push(raindrop)
  }

  const img = new Image()
  img.src = './img/typhoon.png'
  img.width = 1000
  img.height = 1000
  // 图片加载完成后绘制
  img.onload = function() {
  // 设置 canvas 中心点
  const centerX = width / 2;
  const centerY = height / 2;

  // 定义旋转角度和每帧旋转的角度增量
  let angle = 0;
  const angleDelta = Math.PI / 1440;

  // 开始动画循环
  function animate() {
    // 清空画布
    ctx.clearRect(0, 0, width, height);
    raindrops.forEach(raindrop => {
      raindrop.update()
      raindrop.draw()
    })
    // 将坐标系移动到 canvas 中心点
    ctx.translate(centerX, centerY);

    // 旋转图片
    ctx.rotate(-angle);
    ctx.drawImage(img, -img.width / 2, -img.height / 2, img.width, img.height);

    // 恢复坐标系
    ctx.rotate(angle);
    ctx.translate(-centerX, -centerY);

    // 更新旋转角度
    angle += angleDelta;

    // 循环动画
    requestAnimationFrame(animate);
  }

    // 开始动画
    animate();
  }
}

typhoonWeather();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据大屏是一种数据展示和可视化工具,通过将大量的数据以图表、表格、地图等形式直观地展示在屏幕上,帮助用户快速了解数据的信息和趋势,并做出相应的决策和分析。 数据大屏通常包括以下几个方面的功能: 1. 数据展示:通过图表和可视化方式展示数据,如折线图、柱状图、饼图等。用户可以通过交互式操作查看不同的数据维度和时间范围,深入了解数据的细节和变化趋势。 2. 实时监控:可以实时监控某些关键指标的变化情况,比如销售额、用户活跃度等。用户可以通过数据大屏随时了解当前的数据状态,并及时做出决策和调整。 3. 数据分析:数据大屏还可以提供一些分析工具和算法,帮助用户对数据进行深入的分析和挖掘。用户可以通过数据大屏找到数据的规律和趋势,发现数据背后的价值和洞察。 4. 可视化配置:通过可视化配置工具,用户可以自定义数据大屏的布局和展示方式,适应不同的数据需求和展示方式。用户可以自由选择各类图表、颜色、样式等,让数据展示更具吸引力和可读性。 总结来说,数据大屏是一种利用图表和可视化方式将大量数据以直观形式展示在屏幕上的工具。通过数据大屏,用户可以更快速、直观地了解数据的信息、趋势和规律,做出更有力的决策和分析。同时,数据大屏还提供了实时监控、高度可配置的功能,满足不同用户的需求和偏好。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值