


HTML5 Advanced Programming Graphic Distortion and Its Application 1 (Principles)
Several deformations in HTML5
There are several methods for deformation in HTML5:
scale() scaling
rotate() rotation
translate() translation
transform() Matrix transformation
setTransform() Reset matrix
These methods can complete the following processing of pictures
However, if you want to achieve the following irregular deformation, it will not work
Let’s take a step by step, first look at HTML5 of these methods.
1, the scaling method is as follows
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="800" height="280"></canvas> <script type="text/javascript"> var c=document.getElementById('myCanvas'); var ctx=c.getContext('2d'); var img = new Image(); img.src="face.jpg"; img.onload = function(){ ctx.drawImage(img,0,0); ctx.scale(0.5,0.5); ctx.drawImage(img,500,0); }; </script> </body> </html>
Effect
2, the rotation code
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="800" height="400"></canvas> <script type="text/javascript"> var c=document.getElementById('myCanvas'); var ctx=c.getContext('2d'); var img = new Image(); img.src="face.jpg"; img.onload = function(){ ctx.rotate(20*Math.PI/180); ctx.drawImage(img,200,0); }; </script> </body> </html>
Effect
3, translation code
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="800" height="400"></canvas> <script type="text/javascript"> var c=document.getElementById('myCanvas'); var ctx=c.getContext('2d'); var img = new Image(); img.src="face.jpg"; img.onload = function(){ ctx.drawImage(img,0,0); ctx.translate(100,100); ctx.drawImage(img,0,0); }; </script> </body> </html>
Effect
4, tilt code
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="800" height="400"></canvas> <script type="text/javascript"> var c=document.getElementById('myCanvas'); var ctx=c.getContext('2d'); var img = new Image(); img.src="face.jpg"; img.onload = function(){ ctx.setTransform(1.3,0.1,-0.2,1,80,40); ctx.drawImage(img,0,0); }; </script> </body> </html>
Effect
Irregular deformation
mentioned above Note that HTML5 cannot directly implement irregular deformation, but it can be achieved through a series of combinations, such as decomposing the following deformation
Following this idea, I followed AS3 and decomposed a picture into multiple small triangles. The effect is as follows

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
