Detailed description and source code sharing of the Canvas enhancement component instance of WeChat Applet

Source: Internet
Author: User
This article mainly introduces the details of the Canvas enhancement component instance of the applet and relevant information about source code sharing. WeZRender is a Canvas enhancement component of the applet, for more information about the Canvas enhancement components and source code sharing, WeZRender is a Canvas enhancement component, for more information, see

WeZRender is a Canvas enhancement component based on the HTML5 Canvas class library ZRender.

Use

WXML:

 
 
  canvas>
 

JS:

 var wezrender = require('../../lib/wezrender');  zr = wezrender.zrender.init("line-canvas-1", 375, 600);

Features

Data-driven

With WeZRender, you only need to define the graphic data.

 var circle = new wezrender.graphic.shape.Circle(       shape: {      cx: 50,      cy: 50,      r: 50    },    style: {      fill: 'red',      lineWidth: 10    }  });

Rich graphic options

Multiple built-in graphic elements (Circular, elliptical, ring, slice, rectangle, polygon, straight line, curve, heart-shaped, water drop, Rose Line, Trochoid, text, pictures, etc ), the unified and rich graphic attributes fully meet Personalized Requirements.

 var droplet = new wezrender.graphic.shape.Droplet({    shape: {      cx: 200,      cy: 300,      width: 50,      height: 50    },    style: {        fill: '#ff9999'    }  });

Powerful animation support

It provides promise animation interfaces and common easing functions to easily meet various animation requirements.

var image = new wezrender.graphic.Image({    style: {      x: 0,      y: 0,      image: '../../images/koala.jpg',      width: 32,      height: 24,      text: 'koala'    }  });  zr.add(image);  image.animateStyle(true)    .when(2000, {      x: 350,      y: 450,      width: 360,      height: 270,    })    .start();


Easy to expand

The divide-and-conquer graphic definition policy allows you to expand graphic elements.

var Pin = wezrender.graphic.Path.extend({    type: 'pin',    shape: {      // x, y on the cusp      x: 0,      y: 0,      width: 0,      height: 0    },    buildPath: function (path, shape) {      var x = shape.x;      var y = shape.y;      var w = shape.width / 5 * 3;      // Height must be larger than width      var h = Math.max(w, shape.height);      var r = w / 2;      // Dist on y with tangent point and circle center      var dy = r * r / (h - r);      var cy = y - h + r + dy;      var angle = Math.asin(dy / r);      // Dist on x with tangent point and circle center      var dx = Math.cos(angle) * r;      var tanX = Math.sin(angle);      var tanY = Math.cos(angle);      path.arc(        x, cy, r,        Math.PI - angle,        Math.PI * 2 + angle      );      var cpLen = r * 0.6;      var cpLen2 = r * 0.7;      path.bezierCurveTo(        x + dx - tanX * cpLen, cy + dy + tanY * cpLen,        x, y - cpLen2,        x, y      );      path.bezierCurveTo(        x, y - cpLen2,        x - dx + tanX * cpLen, cy + dy + tanY * cpLen,        x - dx, cy + dy      );      path.closePath();    }  });

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

For more details about the Canvas enhancement component examples and source code sharing, please follow the PHP Chinese network!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.