当前位置: 首页 > 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.dtcms.com/a/263534.html

相关文章:

  • JavaScript异步编程的五种方式
  • RocketMQ第五节(springboot整合MQ)
  • C语言main函数的原理:程序入口的奥秘
  • docker使用容器网络
  • 华为云Flexus+DeepSeek征文 | 对接华为云ModelArts Studio大模型:AI赋能投资理财分析与决策
  • 【软考高项论文】信息系统项目的人力资源管理
  • springboot中多个定时任务(@Scheduled)如何互不影响
  • P1967 [NOIP 2013 提高组] 货车运输
  • localStorage 和 sessionStorage
  • 编译原理——运行时存储组织与内存管理
  • Zookeeper安装使用教程
  • 回写缓存为何需要脏位?
  • SimLOD代码精读(二)建立Octree之Splitting Pass分裂阶段
  • 英国研究团队启动合成完整人类基因组的前沿项目
  • Java-包-访问修饰符-封装
  • Redis Lua 调试器(LDB)完全指南
  • 深度剖析 LNK 参数隐藏攻击 (ZDI-CAN-25373)
  • C++ Vector的使用(下)
  • 贪心算法在C++中的应用与实践
  • 基于动漫数据的可视化分析与推荐系统实现
  • Pyhton-EXCEL与Mysql数据对比
  • Monorepo+Pnpm+Turborepo
  • Vue Vue-route (1)
  • jvm的调优命令jstack打印堆栈信息阐述以及调优
  • Linux信号量
  • 基础算法合集-图论
  • 《AI的“三体进化”:数字基因与超人类思维的奇点降临》
  • Windows 11 24H2更新系统后WiFi不显示故障处理
  • AI编程实战:Cursor黑科技全解析
  • Python 数据分析与机器学习入门 (二):NumPy 核心教程,玩转多维数组