zoukankan      html  css  js  c++  java
  • (七)渐变 矩形渐变 放射渐变

    createLinearGradient() 【4个参数,1起点x坐标,2起点y坐标,3终点x 4终点y】
    addColorStop(0,"white")【接收两个参数,1开始渐变的位置0代表开始的位置】
    addColorStop(1,"black")【参数同上,1代表结束的位置(可以写小数点)】

    createRadialGradient() 【6个参数。1(x)/2(y) 开始渐变的中心点,3,圆的半径,4(x)/5(y)结束渐变圆的中心点,6结束渐变圆的半径】
    addColorStop(0,"white")【同上】
    addColorStop(1,"black")【同上】
    【放射渐变的两个圆是同心圆,也就是参数 1,2 === 4,5】

    var canvas = document.getElementById("canvas");
    
        if(canvas.getContext){
            var ctx = canvas.getContext("2d");
    
            //【要确保渐变元素的开始坐标和结束坐标与渐变对象的一致】
    
            //////////////////
            /////矩形渐变
            /////////////////
    
            // 编写渐变1:
            var gradient1 = ctx.createLinearGradient(70,70,120,120);//规定开始渐变跟结束渐变的坐标点
            gradient1.addColorStop(0,"blue");//规定开始渐变的颜色
            gradient1.addColorStop(1,"red");//规定结束渐变的颜色
    
            // 编写渐变2:
            var gradient2 = ctx.createLinearGradient(50,50,100,100);
            gradient2.addColorStop(0,"grey");
            gradient2.addColorStop(1,"black");
    
            ctx.beginPath();
    
            ctx.fillStyle = gradient2;//使用渐变
            ctx.fillRect(50,50,50,50);
    
            ctx.fillStyle = gradient1;//使用渐变
            ctx.fillRect(70,70,50,50);
    
            ctx.stroke();
            ctx.closePath();
    
            ////////////////////
            ////// 放射渐变
            ///////////////////
    
            var gradientArc = ctx.createRadialGradient(75,225,10,75,225,50);
                gradientArc.addColorStop(0,"white");
                gradientArc.addColorStop(1,"black");
            ctx.beginPath();
    
            ctx.fillStyle = gradientArc;
            ctx.fillRect(50,200,50,50);
    
            ctx.stroke();
            ctx.closePath();
        }
  • 相关阅读:
    P1031 均分纸牌
    P1130 红牌
    P1094 纪念品分组
    win32 公用对话框
    高性能完成端口socket服务(IOCP)
    一个简单的调试日志功能
    UI设计工具
    windows平台(不包括ARM的CE)通用的压缩和解压缩
    win api 实现 AES加密、解密,获取HASH
    win32sdk 编程整理的些资料
  • 原文地址:https://www.cnblogs.com/chefweb/p/6046482.html
Copyright © 2011-2022 走看看