zoukankan      html  css  js  c++  java
  • Bezier 曲线参数方程

    Bezier参数方程

    {
    
    randomRange: function (min, max) {
     return min + Math.random() * (max - min);
    },
    
    quadraticBezier: function (p0, p1, p2, t, pFinal) {
                    pFinal = pFinal || {};
                    pFinal.x = Math.pow(1 - t, 2) * p0.x +
                        (1 - t) * 2 * t * p1.x +
                        t * t * p2.x;
                    pFinal.y = Math.pow(1 - t, 2) * p0.y +
                        (1 - t) * 2 * t * p1.y +
                        t * t * p2.y;
    return pFinal;
    },
    
    cubicBezier: function (p0, p1, p2, p3, t, pFinal) {
                    pFinal = pFinal || {};
                    pFinal.x = Math.pow(1 - t, 3) * p0.x +
                        Math.pow(1 - t, 2) * 3 * t * p1.x +
                        (1 - t) * 3 * t * t * p2.x +
                        t * t * t * p3.x;
                    pFinal.y = Math.pow(1 - t, 3) * p0.y +
                        Math.pow(1 - t, 2) * 3 * t * p1.y +
                        (1 - t) * 3 * t * t * p2.y +
                        t * t * t * p3.y;
     return pFinal;
    }
    }
    
          window.onload = function () {
                let canvas = document.getElementById("canvas"),
                    context = canvas.getContext("2d"),
                    width = canvas.width = window.innerWidth,
                    height = canvas.height = window.innerHeight,
    
                    p0 = {
                        x: utils.randomRange(0, width),
                        y: utils.randomRange(0, height)
                    }
                p1 = {
                    x: utils.randomRange(0, width),
                    y: utils.randomRange(0, height)
                }
                p2 = {
                    x: utils.randomRange(0, width),
                    y: utils.randomRange(0, height)
                }
                p3 = {
                    x: utils.randomRange(0, width),
                    y: utils.randomRange(0, height)
                }
    
                context.beginPath()
                context.arc(p0.x, p0.y, 4, 0, Math.PI * 2, false)
                context.fill()
    
                context.beginPath()
                context.arc(p1.x, p1.y, 4, 0, Math.PI * 2, false)
                context.fill()
    
                context.beginPath()
                context.arc(p2.x, p2.y, 4, 0, Math.PI * 2, false)
                context.fill()
    
                context.beginPath()
                context.arc(p3.x, p3.y, 4, 0, Math.PI * 2, false)
                context.fill()
    
                // context.beginPath()
                // context.moveTo(p0.x,p0.y)
                // context.bezierCurveTo(p1.x,p1.x,p2.x,p2.y,p3.x,p3.y)
                // context.stroke()
    
                let pFinal = {}
    
                for(let t = 0; t <= 1; t+=0.01){
                    utils.cubicBezier(p0,p1,p2,p3,t,pFinal);
                    context.beginPath();
                    context.arc(pFinal.x, pFinal.y, 10, 0, Math.PI * 2, false)
                    context.stroke()
                }
            }
    
  • 相关阅读:
    log4net使用封装,无缝切换 dotnet 和 dotnetcore
    使用 certbot 申请泛域名https证书
    StackExchange.Redis中文使用文档
    在 asp.net core 中使用类似 Application 的服务
    不一样的 SQL Server 日期格式化
    你可能不知道的 docker 命令的奇淫怪巧
    [k8s]dashboard1.8.1搭建( heapster1.5+influxdb+grafana)
    [k8s]k8s 1.9(on the fly搭建) 1.9_cni-flannel部署排错 ipvs模式
    [k8s] kubelet单组件启动静态pod
    [svc]runinit管理多进程
  • 原文地址:https://www.cnblogs.com/pluslius/p/13545272.html
Copyright © 2011-2022 走看看