Lufylegend: Graphics deformation 1

Source: Internet
Author: User

Several variants in the HTML5

In HTML5, there are several methods

Scale () scaling rotate () rotation translate () translation transform () matrix warp settransform () Reset matrix

These several methods, to the picture can complete the following several processing

However, if you want to achieve the following irregular deformation, it is not

Let's take a step-by-step look at HTML5 's methods first.

1, the scaling method is as follows

[HTML]View Plaincopyprint?
  1. <! DOCTYPE HTML>
  2. <html>
  3. <body>
  4. <canvas id="MyCanvas" width="height=" 280 "></canvas >
  5. <script type="Text/javascript">
  6. var c=document.getElementById (' MyCanvas ');
  7. var ctx=c.getcontext (' 2d ');
  8. var img = new Image ();
  9. img.src="Face.jpg";
  10. Img.onload = function () {
  11. Ctx.drawimage (img,0,0);
  12. Ctx.scale (0.5,0.5);
  13. Ctx.drawimage (img,500,0);
  14. };
  15. </Script>
  16. </body>
  17. </html>
<! DOCTYPE html>

Effect

2, rotate the code

[HTML]View Plaincopyprint?
  1. <! DOCTYPE HTML>
  2. <html>
  3. <body>
  4. <canvas id="MyCanvas" width="height=" ></Canvas >
  5. <script type="Text/javascript">
  6. var c=document.getElementById (' MyCanvas ');
  7. var ctx=c.getcontext (' 2d ');
  8. var img = new Image ();
  9. img.src="Face.jpg";
  10. Img.onload = function () {
  11. Ctx.rotate (20*math.pi/180);
  12. Ctx.drawimage (img,200,0);
  13. };
  14. </Script>
  15. </body>
  16. </html>
<! DOCTYPE html>
Effect

3, panning the code

[HTML]View Plaincopyprint?
  1. <! DOCTYPE HTML>
  2. <html>
  3. <body>
  4. <canvas id="MyCanvas" width="height=" ></Canvas >
  5. <script type="Text/javascript">
  6. var c=document.getElementById (' MyCanvas ');
  7. var ctx=c.getcontext (' 2d ');
  8. var img = new Image ();
  9. img.src="Face.jpg";
  10. Img.onload = function () {
  11. Ctx.drawimage (img,0,0);
  12. Ctx.translate (100,100);
  13. Ctx.drawimage (img,0,0);
  14. };
  15. </Script>
  16. </body>
  17. </html>
<! DOCTYPE html>

Effect

4, Tilt Code

[HTML]View Plaincopyprint?
  1. <! DOCTYPE HTML>
  2. <html>
  3. <body>
  4. <canvas id="MyCanvas" width="height=" ></canvas >
  5. <script type="Text/javascript">
  6. var c=document.getElementById (' MyCanvas ');
  7. var ctx=c.getcontext (' 2d ');
  8. var img = new Image ();
  9. img.src="Face.jpg";
  10. Img.onload = function () {
  11. Ctx.settransform (1.3,0.1,-0.2,1,80,40);
  12. Ctx.drawimage (img,0,0);
  13. };
  14. </Script>
  15. </body>
  16. </html>
<! DOCTYPE html>

Effect

Irregular deformation

As mentioned earlier, HTML5 can not directly achieve irregular deformation, however, a series of combinations to achieve irregular deformation, such as the following this deformation decomposition

After decomposition becomes

It can actually be seen as a combination of two variants, such as

In fact, it is the combination of multiple variants together, so that a few of the deformation of the part taken out, and then pieced together into a new shape, it becomes a special figure just now

Along this line of thought, I modeled AS3, a graph into a number of small triangles, the effect is as follows

In this way, it is easy to implement the Drawtriangles function, used to distort the graph, it is basically consistent with the function of AS3 drawtriangles function, the difference is that the meaning of the parameter after the 4th is different, where its 4th parameter represents the line thickness of the split line, The 5th parameter represents the color of the split line, if not set, the split line is not displayed, the function is as follows, you can achieve any distortion, even 3D deformation can also

This is a test connection, you can drag the red dots in the graph to make the image distort arbitrarily

Lufylegend: Graphics deformation 1

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.