当前位置: 首页 > wzjs >正文

杭州企业网站设计制作怎么自己用手机做网站

杭州企业网站设计制作,怎么自己用手机做网站,郫县做网站,百度做网站好吗这是第二次写canvas,基于微信小程序文档demo进行改写 demo效果为方块横向来回循环移动 我想做的是直播间那种点赞效果,竖向曲线移动、方块换成图片、点击添加绘制元素 第一阶段实现竖向曲线移动、点击添加绘制元素;下一阶段讲方块替换为图…

这是第二次写canvas,基于微信小程序文档demo进行改写

demo效果为方块横向来回循环移动

我想做的是直播间那种点赞效果,竖向曲线移动、方块换成图片、点击添加绘制元素

第一阶段实现竖向曲线移动、点击添加绘制元素;下一阶段讲方块替换为图片

import { formatDate, getRandomInt } from "../../utils/util";// components/stars/stars.ts
Component({lifetimes: {attached() {this.createSelectorQuery().select("#myCanvas2").fields({node: true,size: true}).exec(res => this.init(res));},},/*** 组件的属性列表*/properties: {},/*** 组件的初始数据*/data: {click: [{ startTime: Date.now(), img: '', fd: getRandomInt(-3, 3), c: getRandomInt(100, 200) }]},/*** 组件的方法列表*/methods: {handleAdd() {this.data.click.push({ startTime: Date.now(), img: '', fd: getRandomInt(-3, 3), c: getRandomInt(0, 200) })},init(res) {const width = res[0].widthconst height = res[0].height// 设置画布宽高const canvas = res[0].nodeconst ctx = canvas.getContext('2d')canvas.width = widthcanvas.height = height// 帧渲染回调const draw = () => {const w = 40const time = Date.now()this.data.click = this.data.click.map((item, index) => {// 计算经过的时间const elapsed = time - item.startTime// 计算动画位置const n = Math.floor(elapsed / 3000)const m = elapsed % 3000const dy = m / 1500const bl = 1 - dy / 3const y = height - (height) * dy / 2// -2 随机生成 dy如何确定呢const x = item.fd * Math.sin(dy * Math.PI / 4) * (width - w * bl) / 2 + (width - w * bl) / 2return { ...item, x, y, bl, w, n }})this.data.click = this.data.click.filter(item => {if (item.y < 5) {return false}return true})this.render(ctx, width, height, this.data.click)// 注册下一帧渲染canvas.requestAnimationFrame(draw)}draw()},render(ctx, width, height, click) {ctx.clearRect(0, 0, width, height)// 渲染for (let i = 0; i < click.length; i++) {if (!this.data.click[i]) continue;const { x, y, bl, w, c } = this.data.click[i]ctx.fillStyle = 'rgba(' + c + ', 0, 0,' + bl + ')';ctx.fillRect(x, y, w * bl, w * bl);}}}
})

 替换图片

import { formatDate, getRandomInt } from "../../utils/util";
import { defaultIcon } from '../../pages/clockIn/defaultImg'
let imgsList: any = []// components/stars/stars.ts
Component({lifetimes: {attached() {this.createSelectorQuery().select("#myCanvas2").fields({node: true,size: true}).exec(res => this.init(res));},},/*** 组件的属性列表*/properties: {},/*** 组件的初始数据*/data: {click: [{ startTime: Date.now(), img: '', fd: getRandomInt(-3, 3), c: getRandomInt(100, 200) }]},/*** 组件的方法列表*/methods: {handleAdd() {this.data.click.push({ startTime: Date.now(), img: imgsList[getRandomInt(0, imgsList.length - 1)], fd: getRandomInt(-3, 3), c: getRandomInt(0, 200) })},init(res) {const width = res[0].widthconst height = res[0].height// 设置画布宽高const canvas = res[0].nodeconst ctx = canvas.getContext('2d')canvas.width = widthcanvas.height = height// 加载图片资源let imgKeys = Object.keys(defaultIcon)for (let k of imgKeys) {const image = canvas.createImage()image.onload = () => {imgsList.push(image)// ctx.drawImage(image, 0, 0, 40,40)console.log(imgsList.length)}image.src = defaultIcon[k]}// 帧渲染回调const draw = () => {const w = 40const time = Date.now()this.data.click = this.data.click.map((item, index) => {// 计算经过的时间const elapsed = time - item.startTime// 计算动画位置const n = Math.floor(elapsed / 3000)const m = elapsed % 3000const dy = m / 1500const bl = (1 - dy / 3) * 2const y = height - (height) * dy / 2// -2 随机生成 dy如何确定呢const x = item.fd * Math.sin(dy * Math.PI / 4) * (width - w / bl) / 2 + (width - w / bl) / 2return { ...item, x, y, bl, w, n }})this.data.click = this.data.click.filter(item => {if (item.y < 5) {return false}return true})this.render(ctx, width, height, this.data.click)// 注册下一帧渲染canvas.requestAnimationFrame(draw)}draw()},render(ctx, width, height, click) {ctx.clearRect(0, 0, width, height)// 渲染for (let i = 0; i < click.length; i++) {if (!this.data.click[i]) continue;const { x, y, bl, w, c, img } = this.data.click[i]if (img) {ctx.drawImage(img, x, y, w / bl, w / bl)ctx.globalAlpha = bl}}},}
})
<!--components/stars/stars.wxml-->
<view class="conponent-stars flex-cloumn-center"><canvas type="2d" id="myCanvas2" style="width: 150px;height: 200px;"></canvas><view class="add" bind:tap="handleAdd"></view>
</view>

接下来的问题是canvas绘制的图片有锯齿,找了下解决办法:清晰多了

const dpr = wx.getSystemInfoSync().pixelRatio;canvas.width = width * dpr;canvas.height = height * dpr;ctx.scale(dpr, dpr);

由于找不到透明背景的切图,为了美观想给图片画个圆

目前只能加个边框,裁剪还不能多个同时裁剪

// 渲染for (let i = 0; i < click.length; i++) {if (!this.data.click[i]) continue;const { x, y, bl, w, c, img } = this.data.click[i]// ctx.fillStyle = 'rgba(' + c + ', 0, 0,' + bl + ')';// ctx.fillRect(x, y, w / (3 * bl), w / (3 * bl));if (img) {ctx.drawImage(img, x, y, w / bl, w / bl)ctx.globalAlpha = blctx.beginPath()ctx.arc(x + 0.5 * w / bl, y + 0.5 * w / bl, 20 / bl, 0, 2 * Math.PI)ctx.stroke()ctx.closePath()// ctx.clip()}}

点击效果可以查看小程序打卡模块


文章转载自:

http://fR2VeBgr.kqnwy.cn
http://xSFTM6Pu.kqnwy.cn
http://fWq02bSL.kqnwy.cn
http://mXraSKZj.kqnwy.cn
http://DGPNoOFV.kqnwy.cn
http://08ApnUgU.kqnwy.cn
http://ZH8DryQX.kqnwy.cn
http://gavJ28Gt.kqnwy.cn
http://0pt7QhRB.kqnwy.cn
http://oDOm44fa.kqnwy.cn
http://DFicgfg9.kqnwy.cn
http://rj2WGqa6.kqnwy.cn
http://paOxjuKI.kqnwy.cn
http://ZAE90m0W.kqnwy.cn
http://RcjKjB26.kqnwy.cn
http://dtmEadIC.kqnwy.cn
http://U12BronX.kqnwy.cn
http://Iau020Mx.kqnwy.cn
http://MxgUXbKy.kqnwy.cn
http://qszALsJe.kqnwy.cn
http://mI49d0Br.kqnwy.cn
http://QAALEeRd.kqnwy.cn
http://vrpvIQG0.kqnwy.cn
http://LZ4D5SJI.kqnwy.cn
http://Mk0MOIJA.kqnwy.cn
http://a4HVFqOd.kqnwy.cn
http://LfBXqYfC.kqnwy.cn
http://5PBQmlJf.kqnwy.cn
http://fguNAHaC.kqnwy.cn
http://HFwonYVk.kqnwy.cn
http://www.dtcms.com/wzjs/648396.html

相关文章:

  • 用php做的网站人才市场招聘网站
  • 合肥企业网站网站开发需要的编程软件
  • 专业网站制作软件saas智能营销云平台
  • 赣州房产网站建设国外建站程序
  • 青浦专业做网站公司2022有创意的广告
  • 网站建设一般步骤遵义网站制作教程
  • 使用nas建设网站专业团队电影
  • 商城网站程序微商系统软件开发
  • 网站整体架构php 免费企业网站
  • 网站app公众号先做哪个比较好中国化学第九建设公司网站
  • 山东网页制作网站html5网站app开发
  • 郑州高新区建设环保局网站网页设计考研院校
  • 招聘信息网站建设怎么做公司网站
  • 一家专门做动漫的网站在网上做软件挣钱的网站
  • 网站建设公司制作网站Net网站开发多少钱
  • 广州骏域网站建设专家做网站的业务逻辑
  • 自己如何建设一个彩票网站微信企业app手机下载安装
  • 山东德州做网站丹东发布最新通告
  • 如何用discuz做网站山东省建设厅注册中心网站
  • 域名制作网站吗建自己的网站做外贸
  • 网站栏目描述怎么写深圳网站建设 名片设计 网站管理
  • 网站建设设计公elementor wordpress
  • 一般网站建设都用什么字体织梦如何做二级网站
  • 沈阳做网站多少钱西安网站建设的费用
  • 广州市官网网站建设平台郑州网站优化软件
  • 网站建设全部代码免费网站建设有哪些
  • 无忧seo青岛seo结算
  • 中国做的电脑系统下载网站好什么网站能免费
  • 网站右侧浮动导航成都网站优化步骤
  • 如何用kali做网站渗透wordpress只备份数据