美文网首页Canvas
canvas-04 着色

canvas-04 着色

作者: 呆桃冲鸭冲鸭 | 来源:发表于2020-08-12 09:14 被阅读0次

一、图形着色区域:

描边区域:strokeStyle代表了描边样式,描边区域的绘制方法是stroke()、strokeRect()、strokeText();

填充区域:fillStyle代表了填充样式,填充区域的绘制方法是fill()、fillRect()、fillText()。

二、图形的着色方式:

纯色:与css一致 ; ctx.fillStyle = "gray"; ctx.strokeStyle = "gray";

        let canvas = document.querySelector("#canvas");

        const ctx = canvas.getContext("2d"); 

        ctx.fillStyle = "gray";

        ctx.beginPath();

        ctx.arc(300,200,100,0,Math.PI*2)

        ctx.fill();

三、渐变:

步骤:建立渐变对象的方式;为渐变添加颜色节点;赋值;

线性渐变: ctx.createLinearGradient(x1,y1,x2,y2) ;

        let canvas = document.querySelector("#canvas");

        const ctx = canvas.getContext("2d"); 

        // 建立渐变对象的方式: 线性渐变

        const gr = ctx.createLinearGradient(50,50,300,300)  //左上角到右下角

        // 为渐变添加颜色节点

        gr.addColorStop(0,"red");

        gr.addColorStop(0.5,"yellow");

        gr.addColorStop(1,"green");

        //为样式赋值

        ctx.fillStyle = gr ;

        //绘图

        ctx.fillRect(50,50,350,350)

线性渐变

径向渐变: createRadialGradient(圆心1x,圆心1y,半径1,圆心2x,圆心2y,半径2,)

        const gr = ctx.createRadialGradient(300,300,50,300,300,200) 

        gr.addColorStop(0,"red");

        gr.addColorStop(0.5,"yellow");

        gr.addColorStop(1,"green");

        ctx.fillStyle = gr ;

        ctx.fillRect(50,50,600,600)

径向渐变

纹理: const gr = ctx.createPattern(image,"repeat|repeat-x|repeat-y|no-repeat");ctx.createPattern(图像源,重复方式)

        const img = new Image();

        img.src = "./images/floor.jpg";

        img.onload = function(){

            const pt = ctx.createPattern(img,"repeat");

            ctx.fillStyle = pt;

            ctx.fillRect(0,0,canvas.width,canvas.height)

        }

纹理

相关文章

  • canvas-04 着色

    一、图形着色区域: 描边区域:strokeStyle代表了描边样式,描边区域的绘制方法是stroke()、stro...

  • OpenGL学习--着色器使用

    单元着色器 平面着色器 上色着色器 默认光源着色器 点光源着色器 纹理替换矩阵着色器 纹理调整着色器 纹理光源着色器

  • OpenGL存储着色器

    1、初始化 2、存储着色器种类 单元着色器 平面着色器 上色着色器 默认光源着色器 点光源着色器 纹理替换矩阵着色...

  • OpenGL ES 自定义着色器

    着色器 创建着色器 删除着色器 编译着色器 将着色器的源代码附着到着色器对象上。 开始编译着色器源代码。 创建与链...

  • OpenGL 固定管线下的着色器

    OpenGL 固定管线下为开发者提供了几种着色器:单元着色器、平面着色器、上色着色器、默认光源着色器、点光源着色器...

  • OpenGL ES 之 GLSL和滤镜

    着色器的渲染过程在渲染过程中,必须存储2中着色器,分别是顶点着色器、片元着色器。顶点着色器是第一个着色器、片元着色...

  • Unity3Dshader中的RenderType

    Opaque: 用于大多数着色器(法线着色器、自发光着色器、反射着色器以及地形的着色器)。Transparent:...

  • OpenGL的一些学习

    资料来源:逻辑教育 OpenGL 固定管线中常见的几种着色器 单元着色器 平面着色器 上色着色器 默认光源着色器 ...

  • 《WebGL 编程指南》笔记 —— 第九章 层次模型

    着色器对象与程序对象着色器对象:着色器对象管理一个顶点着色器或一个片元着色器。每一个着色器都有一个着色器对象。程序...

  • WebGL 3D概念讲解(着色器)

    着色器 1、顶点着色器 2、片元着色器

网友评论

    本文标题:canvas-04 着色

    本文链接:https://www.haomeiwen.com/subject/klyydktx.html