实现效果

源码
import Taro from "@tarojs/taro";
import { View, Canvas, Input, Button } from "@tarojs/components";
import { useState, useEffect } from "react";
// 画随机线函数
function drawline(canvas, context) {
// 随机线的起点x坐标是画布x坐标0位置,y坐标是画布高度的随机数
context.moveTo(
Math.floor(Math.random() * canvas.width),
Math.floor(Math.random() * canvas.height)
);
// 随机线的终点x坐标是画布宽度,y坐标是画布高度的随机数
context.lineTo(
Math.floor(Math.random() * canvas.width),
Math.floor(Math.random() * canvas.height)
);
// 线条的款
context.lineWidth = 0.5;
// 线条的描边属性:颜色透明度
context.strokeStyle = "rgba(50,50,50,0.3)";
// 在画布上画线
context.stroke();
}
// 画随机点函数
function drawDot(canvas, context) {
let px = Math.floor(Math.random() * canvas.width),
py = Math.floor(Math.random() * canvas.height);
context.moveTo(px,