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

从设计到开发一个小程序页面

巧妇难为无米之炊,想写功能但是没有好看的设计,边写边设计效率又不够高。mastergoAi生成的页面又不够好看,而且每月给的免费积分用得又超快,so决定自给自足。能有多难,先做,做了再改。

于是决定踏足设计,本期话题新手如何用mastergo设计小程序页面。

先去小红书上找找模子,看能否复原。摸了一晚上,感觉效果还行,比ai生成的要好看那么一点。只是想画个时钟出来不知道怎么画好,还的看怎么用canvas实现时钟动画。

附上mastergo网址:MasterGo 莫高设计 - AI 时代的数字界面生产平台

有了UI页面画起来就是快多了

今天用canvas绘制了时钟,然后调整了下整体的布局更简洁直观了

另外再附上canvas绘制时钟代码,canvas越写越有意思了

// components/stars/stars.ts
let timer = null
Component({lifetimes: {attached() {this.createSelectorQuery().select("#myCanvas2").fields({node: true,size: true}).exec(res => this.init(res));},detached() {if (timer) {clearInterval(timer)}}},/*** 组件的方法列表*/methods: {init(res) {const width = res[0].widthconst height = res[0].height// 设置画布宽高const canvas = res[0].nodeconst ctx = canvas.getContext('2d')canvas.width = widthcanvas.height = heightconst r = width / 2const hourNeedle = r * 1 / 2const minuteNeedle = r * 2.5 / 4const secondNeedle = r * 4 / 5// 帧渲染回调const draw = () => {const now = new Date();const hour = now.getHours();const minute = now.getMinutes();const second = now.getSeconds();const secondDeg = (second / 60) * Math.PI * 2;const minuteDeg = ((second / 60 + minute) / 60) * Math.PI * 2;const hourDeg = ((((second / 60 + minute) / 60) + hour) / 12) * Math.PI * 2;this.render(ctx, width, height, secondDeg, secondNeedle, minuteDeg, minuteNeedle, hourDeg, hourNeedle)// 注册下一帧渲染// canvas.requestAnimationFrame(draw)}timer = setInterval(() => {draw()}, 1000)},//画背景框renderCircle(ctx, width) {ctx.beginPath()ctx.lineWidth = '1'ctx.arc(width / 2, width / 2, width / 2 - 2, 2, 4 * Math.PI);ctx.strokeStyle = '#000'ctx.stroke()ctx.beginPath()ctx.arc(width / 2, width / 2, width / 2 - 6, 2, 4 * Math.PI);ctx.strokeStyle = '#000'ctx.stroke()ctx.beginPath()ctx.arc(width / 2, width / 2, 3, 2, 4 * Math.PI);ctx.strokeStyle = '#000'ctx.stroke()ctx.fillStyle = '#000'ctx.fill()let count = 0while (count < 60) {const deg = (Math.PI / 30) * countconst r = width / 2 - 6const r1 = r - 4const r2 = r - 8const r3 = r - 18let R = r1if (count % 5 == 0) {R = r2let word = count / 5 == 0 ? 12 : count / 5let w = ctx.measureText(word).width;ctx.fillText(word, width / 2 + r3 * Math.sin(deg) - w / 2, width / 2 - r3 * Math.cos(deg) + w / 2)}ctx.beginPath()ctx.moveTo(width / 2 + r * Math.sin(deg), width / 2 - r * Math.cos(deg))ctx.lineTo(width / 2 + R * Math.sin(deg), width / 2 - R * Math.cos(deg))ctx.strokeStyle = '#000'ctx.stroke()count++}ctx.font = '12px bold'},// 画时针render(ctx, width, height, secondDeg, secondNeedle, minuteDeg, minuteNeedle, hourDeg, hourNeedle) {ctx.clearRect(0, 0, width, height)this.renderCircle(ctx, width)ctx.beginPath()ctx.moveTo(width / 2 + (-10) * Math.sin(minuteDeg), width / 2 - (-10) * Math.cos(minuteDeg));ctx.lineTo(width / 2 + minuteNeedle * Math.sin(minuteDeg), width / 2 - minuteNeedle * Math.cos(minuteDeg));ctx.lineCap = 'round'ctx.lineWidth = '2'ctx.stroke();ctx.beginPath()ctx.moveTo(width / 2 + (-10) * Math.sin(hourDeg), width / 2 - (-10) * Math.cos(hourDeg));ctx.lineTo(width / 2 + hourNeedle * Math.sin(hourDeg), width / 2 - hourNeedle * Math.cos(hourDeg));ctx.lineCap = 'round'ctx.lineWidth = '3'ctx.stroke();ctx.beginPath()ctx.moveTo(width / 2 + (-10) * Math.sin(secondDeg), width / 2 - (-10) * Math.cos(secondDeg));ctx.lineTo(width / 2 + secondNeedle * Math.sin(secondDeg), width / 2 - secondNeedle * Math.cos(secondDeg));ctx.lineCap = 'round'ctx.lineWidth = '1'ctx.strokeStyle = 'red'ctx.stroke();},}
})

时钟效果可查看微信小程序“哆喵口袋”

http://www.lryc.cn/news/578244.html

相关文章:

  • 鸿蒙NEXT-鸿蒙三层架构搭建,嵌入HMRouter,实现便捷跳转,新手攻略。(2/3)
  • HTML之常用基础标签
  • JavaScript异步编程的五种方式
  • 力扣 hot100 Day30
  • Spring生态:云原生与AI的革新突破
  • 七天学会SpringCloud分布式微服务——06——Sentinel
  • 从零到一通过Web技术开发一个五子棋
  • CSDN博客大搬家(本地下载markdown合适和图片本地化)
  • Stable Diffusion 项目实战落地:从0到1 掌握ControlNet 第四篇 风格化字体大揭秘:从线稿到涂鸦,ControlNet让文字焕发新生
  • 【机器人】复现 HOV-SG 机器人导航 | 分层 开放词汇 | 3D 场景图
  • 文心大模型正式开源,开启AI普惠新时代
  • vue上传各种文件,并预览组件,(预览,下载),下载resources目录下文件
  • 云上攻防—Docker安全容器逃逸特权模式危险挂载
  • 计算机网络(一)层
  • 3.前端和后端参数不一致,后端接不到数据的解决方案
  • 基于C#的OPCServer应用开发,引用WtOPCSvr.dll
  • 中钧科技亮相2025 亚欧商品贸易博览会,赋能数字经济新未来!
  • C#索引和范围:简化集合访问的现代特性详解
  • 2025年 UI 自动化框架使用排行
  • 深度模型结构选择和应用分析
  • 多重性校正:临床试验统计的关键防线
  • 自由学习记录(65)
  • 【算法】动态规划:1137. 第 N 个泰波那契数
  • python训练打卡DAY40
  • 时序数据集---UWave
  • 《燕云十六声》全栈技术架构深度解析
  • docker搭建minio和python使用minio
  • Java web1(黑马)
  • 【知识图谱构建系列7】:结果评价(1)
  • K8s环境下基于Nginx WebDAV与TLS/SSL的文件上传下载部署指南