Computer Multimedia & Animation
Computer Multimedia & Animation
UNIT 1:
Web Design: Origins and evolution of HTML, Basic syntax, Basic text markup, Images, Lists,
Tables, Forms, Frame, Overview and features of HTML5. CSS: Introduction, Levels of style
sheets, Style specification formats, Selector forms, Property value forms, Font properties, List
properties, Color, Alignment of text, The <span> and <div> tags; Overview and features of CSS3.
JavaScript: Object orientation and JavaScript; General syntactic characteristics; Primitives,
operations, and expressions; Screen output and keyboard input
UNIT 2:
Animation: What is an Animation? The Start and End States, Interpolation, Animations in HTML.
All About CSS Animations, Creating a Simple Animation, Detailed Look at the CSS Animation
Property, Key frames, Declaring Multiple Animations, Wrap-up. All about CSS Transitions,
Adding a Transition, Looking at Transitions in Detail, the Longhand Properties, Longhand
Properties vs. Shorthand Properties, Working with Multiple Transitions
UNIT 3:
HTML5 – SVG: Viewing SVG Files, Embedding SVG in HTML5, HTML5 − SVG Circle,
HTML5 − SVG Rectangle, HTML5 − SVG Line, HTML5 − SVG Ellipse, HTML5 − SVG
Polygon, HTML5 − SVG Polyline, HTML5 − SVG Gradients, HTML5 − SVG Star.
UNIT 4:
HTML5 – CANVAS: The Rendering Context, Browser Support, HTML5 Canvas Examples,
Canvas - Drawing Rectangles, Canvas - Drawing Paths, Canvas - Drawing Lines, Canvas -
Drawing Bezier Curves, Canvas - Drawing Quadratic Curves, Canvas - Using Images, Canvas -
Create Gradients.
UNIT 5:
HTML5 - Styles and Colors, Canvas - Text and Fonts, Canvas - Pattern and Shadow, Canvas -
Save and Restore States, Canvas - Translation, Canvas - Rotation, Canvas - Scaling, Canvas -
Transforms, HTML5 Canvas - Composition, Canvas – Animations..
UNIT 1
WEB DESIGN
Web Design: Origins and evolution of HTML, Basic syntax, Basic text markup, Images, Lists,
Tables, Forms, Frame, Overview and features of HTML5. CSS: Introduction, Levels of style
sheets, Style specification formats, Selector forms, Property value forms, Font properties, List
properties, Color, Alignment of text, The <span> and <div> tags; Overview and features of
CSS3. JavaScript: Object orientation and JavaScript; General syntactic characteristics;
Primitives, operations, and expressions; Screen output and keyboard input
WEB DESIGN
Web design encompasses the process of creating and designing the visual appearance and
user experience of websites.
It involves various elements such as layout, colors, typography, graphics, and interactive
features to enhance the aesthetics and functionality of a website.
ORIGINS AND EVOLUTION OF HTML
HTML STRUCTURE
HTML (Hypertext Markup Language) provides a structured way to define the elements and
content of a web page.
The structure of an HTML document consists of several key components:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Web Page</title>
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="Image description">
<a href="https://www.example.com">Link</a>
</body>
</html>
BASIC SYNTAX
When it comes to web development and programming, different languages have their own
syntax rules.
Here are the basic syntax rules for a few popular languages:
FRAMES TAG
HTML: Frames are not commonly used in modern web design due to accessibility and
usability issues.
Instead, techniques like CSS and JavaScript are used for layout and content organization.
However, if needed, frames can be created using the <frame> or <iframe> tags.
The src attribute specifies the source URL of the content to be displayed within the frame.
CSS
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation and
visual appearance of HTML and XML documents.
It allows web developers to control the layout, colors, fonts, and other visual aspects of web
pages, separate from the underlying structure and content.
CSS works by selecting HTML elements and applying styles to them using various properties
and values.
Styles can be applied directly to HTML elements using inline styles, included within the
HTML file using internal stylesheets, or linked externally using external stylesheets.
Levels of CSS
SELECTOR FORMS
SL.No Selector Definition Example
Selects elements based on p selects all <p> elements.
1 Element Selector
their HTML tag name.
Selects elements based on .my-class selects all elements with
2 Class Selector the value of their class class="my-class"
attribute
Selects an element based on #my-id selects the element with
3 ID Selector
the value of its id attribute. id="my-id".
Selects elements based on [type="submit"] selects all elements
4 Attribute Selector the presence or value of an with type="submit".
attribute.
FONT PROPERTIES
SL.No Attribute Definition
1 font-family Specifies the font family or a list of fonts for text.
2 font-size Specifies the size of the font.
3 font-weight Specifies the thickness of the font.
4 font-style Specifies the style of the font (normal, italic, oblique).
5 text-decoration Specifies decorations like underline, overline, line-through.
6 text-align Specifies the horizontal alignment of text (left, right, center, justify).
LIST PROPERTIES
SL.No Attribute Definition
1 list-style-type Specifies the type of list marker (disc, decimal, square, etc.).
2 list-style-image Specifies an image as the list marker.
3 list-style-position Specifies the position of the list marker (inside or outside the list item).
COLOR
SL.No Attribute Definition
1 color Specifies the text color.
2 background-color Specifies the background color.
3 border-color Specifies the color of borders.
4 opacity Specifies the opacity of an element (0.0 to 1.0).
ALIGNMENT OF TEXT
SL.No Attribute Definition
1 text-align Specifies the horizontal alignment of text (left, right, center, justify).
Specifies the vertical alignment of inline elements (baseline, top, middle,
2 vertical-align
bottom).
3 line-height Specifies the height of a line of text, affecting vertical spacing.
JAVA SCRIPT
JavaScript is a high-level programming language primarily used for client-side web
development.
It allows developers to add interactivity, dynamic behavior, and functionality to web pages.
PRIMITIVES
In JavaScript, there are several primitive data types that are used to represent simple values.
These primitive types are:
SL.No Type Definition
1 Number The number type represents numeric values.
The string type represents textual data.
2 String
Strings are enclosed in single quotes (') or double quotes ("),
The boolean type represents logical values.
3 Boolean
It has two possible values: true and false
4 Null The null type represents the absence of any object value.
The undefined type represents a variable that has been declared but has not
Undefined
been assigned a value.
Example let numberValue = 42; // number
let stringValue = "Hello"; // string
let booleanValue = true; // boolean
let nullValue = null; // null
let undefinedValue = undefined; // undefined
let symbolValue = Symbol("unique"); // symbol
Operators:
Operators are symbols or keywords that perform operations on operands to produce a value.
JavaScript supports various types of operators, including:
SL.No Operators Definition
+ (addition), - (subtraction), * (multiplication), / (division), % (remainder),
1 Arithmetic
++ (increment), -- (decrement), etc.
== (equality), === (strict equality), != (inequality), !== (strict inequality),
2 Comparison > (greater than), < (less than), >= (greater than or equal to), <= (less than or
equal to), etc.
3 Logical && (logical AND), || (logical OR), ! (logical NOT), etc.
4 Assignment =, +=, -=, *=, /=, %=, etc.
& (bitwise AND), | (bitwise OR), ^ (bitwise XOR), << (left shift), >> (right
5 Bitwise
shift), >>> (unsigned right shift), etc.
(condition ? expression1 : expression2), typeof operator, instanceof
6 Ternary
operator, etc.
Expressions:
An expression is a combination of values, variables, operators, and function calls that
evaluates to a resulting value.
Expressions can be simple or complex, and they can include arithmetic, comparison, logical,
and other operators.
For example:
1. Arithmetic expression: 3 + 4 * 2 evaluates to 11.
2. Comparison expression: 5 > 3 evaluates to true.
3. Logical expression: (x > 0) && (y < 10) evaluates to either true or false.
Keyboard Input:
SL.No Type Definition
The prompt() function displays a dialog box that prompts the user to
1 prompt()
enter input. The user can enter text, which is then returned as a string.
Example document.getElementById("myElement").innerHTML = "Hello, World!";
You can attach event listeners to specific elements or the entire
2 Event Listeners document to listen for keyboard events such as key presses or key
releases. This allows you to respond to user input in real-time.
document.addEventListener("keydown", function(event) {
Example console.log("Key pressed: " + event.key);
});
UNIT 2
ANIMATION
Animation: What is an Animation? The Start and End States, Interpolation, Animations in
HTML. All About CSS Animations, Creating a Simple Animation, Detailed Look at the CSS
Animation Property, Key frames, Declaring Multiple Animations, Wrap-up. All about CSS
Transitions, Adding a Transition, Looking at Transitions in Detail, the Longhand Properties,
Longhand Properties vs. Shorthand Properties, Working with Multiple Transitions
WHAT IS AN ANIMATION
Animation refers to the process of creating the illusion of movement and bringing static
images or objects to life.
It involves a series of sequential images or frames that are displayed rapidly in succession,
creating the perception of motion.
Start state
The initial state or frame from which the animation begins.
Defines the position, appearance, and attributes of the animated elements before any
movement or transformation takes place.
End state
The final state or frame that the animated object or scene transitions to at the conclusion of
the animation sequence.
It defines the desired position, appearance, and attributes of the elements after all the intended
movements, transformations, or actions have been completed.
INTERPOLATION
Interpolation in the context of animation refers to the process of generating intermediate
frames or states between two key frames to create smooth and fluid motion.
It is a technique used to fill in the gaps between the start and end states in an animation
sequence.
ANIMATIONS IN HTML
In HTML, animations can be created using various techniques and technologies, including
CSS (Cascading Style Sheets) and JavaScript.
Here are a few methods commonly used for creating animations in HTML:
SL.No Animations Definition
CSS transitions allow you to define the change in style or property of
CSS an element over a specified duration.
1
Transitions Transitions are triggered by changes in CSS properties, such as hover,
focus, or class toggling.
CSS keyframe animations provide more complex and customizable
animations.
CSS Keyframe
2 keyframes at specific percentages of an animation's duration using the
Animations
@keyframes rule, you can control the intermediate states of an
element.
CSS animation libraries, like Animate.css or Hover.css, offer pre-built
CSS animation effects that can be easily added to HTML elements by
3 Animations applying predefined CSS classes.
with Libraries These libraries provide a wide range of animation options, including
fades, slides, rotations, and more.
JavaScript libraries, such as GreenSock (GSAP) or Anime.js, provide
JavaScript
powerful animation capabilities by leveraging JavaScript.
4 Animation
JavaScript animations are typically triggered by events or using
Libraries
functions to manipulate CSS properties directly.
For more intricate and game-like animations, the HTML5 canvas
HTML5 element can be utilized.
5
Canvas The canvas provides a drawing API that allows you to create dynamic
and interactive graphics using JavaScript.
CSS animations allow you to create dynamic and visually appealing animations directly
within your HTML and CSS code.
With CSS animations, you can animate various properties of HTML elements, such as
position, size, color, opacity, and more.
4. Wrap-up:
CSS animations provide a powerful and flexible way to create dynamic and
engaging visual effects on websites and web applications.
They allow you to bring elements to life by animating properties and
transitioning between states.
Keyframes define the intermediate steps of an animation, and the animation
property brings them together, controlling the animation's timing, duration, and
behavior.
By combining multiple animations and adjusting various animation properties,
you can achieve more complex and intricate animations.
Transition Timing:
2. The timing-function property within transitions determines the speed curve of
the transition.
syntax transition: property duration timing-function delay;
Ease Starts slow, accelerates in the middle, and slows down at the end (default).
Linear Progresses at a constant speed.
ease-in Starts slow and accelerates.
ease-out Starts fast and decelerates.
ease-in-out Starts slow, accelerates in the middle, and decelerates at the end.
Adding a Transition
Adding a transition to an element involves specifying the transition property and
values in CSS. Here's an example of adding a transition to change the background
color of a button when it's hovered over:
HTML: CSS:
<div class="box"></div> .box {
width: 100px;
height: 100px;
background-color: blue;
transition: background-color 1s;
}
.box:hover {
background-color: red;
}
Transition longhand:
The option to use longhand properties to individually control different aspects of the
transition.
.element {
Transition-property : color;
Transition-delay : 500ms;
Example Transition-duration : 2s;
Transition-time-function : ease-in;
}
Transition Shorthand:
Shorthand properties provide a concise way to define multiple aspects of the
transition in a single declaration.
.element {
Example Transition: color 2s ease-in 500ms
}
.element { .element {
transition-property: width; transition: width 1s ease-in-out 0.3s;
transition-duration: 1s; }
transition-timing-function: ease-in-out;
transition-delay: 0.3s;
}
Longhand properties offer more control and Shorthand properties are handy when you want
flexibility when you need different values for to apply the same transition settings to multiple
each aspect of the transition effect. properties, making the code shorter and more
readable.
UNIT 3
HTML5-SVG
HTML5 – SVG: Viewing SVG Files, Embedding SVG in HTML5, HTML5 − SVG Circle,
HTML5 − SVG Rectangle, HTML5 − SVG Line, HTML5 − SVG Ellipse, HTML5 − SVG
Polygon, HTML5 − SVG Polyline, HTML5 − SVG Gradients, HTML5 − SVG Star.
HTML5 SVG
SVG(Scalable Vector Graphics) is a markup language used to create vector-based graphics
and animations on the web.
It allows for the creation of scalable and resolution-independent images that can be
manipulated and animated using JavaScript or CSS.
SVG is supported by all modern web browsers and provides a wide range of features and
elements to create visually appealing and interactive graphics
6.HTML5− Polyline
To create an SVG polyline in HTML5, you can use the <polyline> element.
Example <!DOCTYPE html>
<html>
<head> <title>SVG Polyline</title>
</head> <body>
<svg width="400" height="400">
<polyline points="100,200 200,50 300,200 200,350" fill="none"
stroke="purple" stroke-width="2" />
</svg> </body> </html>
<svg> The <svg> element creates the SVG container with a width and height of 400 pixels.
<polyline> The <polyline> element represents the polyline shape.
points The points attribute defines the coordinates of the vertices of the polyline. In this case,
the polyline has four vertices: (100, 200), (200, 50), (300, 200), and (200, 350). The
coordinates are specified in pairs separated by spaces.
fill The fill="none" attribute specifies that the polyline should have no fill color.
stroke The stroke="purple" attribute sets the stroke color of the polyline (purple in this case).
stroke- The stroke-width="2" attribute specifies the thickness of the polyline (2 in this case).
width
UNIT 4
HTML5 – CANVAS
HTML5 – CANVAS: The Rendering Context, Browser Support, HTML5 Canvas Examples,
Canvas - Drawing Rectangles, Canvas - Drawing Paths, Canvas - Drawing Lines, Canvas -
Drawing Bezier Curves, Canvas - Drawing Quadratic Curves, Canvas - Using Images, Canvas
- Create Gradients.
HTML5 – CANVAS
HTML5 Canvas is a powerful feature introduced in HTML5 that allows you to dynamically
render graphics, animations, and images directly in a web page using JavaScript.
With the Canvas API, you have full control over individual pixels and can create complex
visualizations, games, data visualizations, and more.
To use the HTML5 Canvas, you need to add a <canvas> element to your HTML markup.
This element acts as a drawing surface and can be styled using CSS.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Canvas Example</title>
<style>
#myCanvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="500" height="500"></canvas>
<script>
// JavaScript code to draw on the canvas goes here
</script>
</body>
</html>
We have created a canvas element with an id of "myCanvas" and specified its width and height
as 500 pixels.
We have also added a simple border using CSS.
To draw on the canvas, you need to access the canvas element using JavaScript and obtain its
2D rendering context.
ctx.fillStyle = 'blue';
ctx.fillRect(50, 50, 100, 100);
</script>
1. 2D Rendering Context:
The 2D rendering context, accessed by using the string '2d' as the argument to get Context,
provides methods for drawing and manipulating 2D graphics.
This is the most commonly used rendering context in HTML5 Canvas.
Example
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
2. WebGL Rendering Context:
The WebGL rendering context, accessed by using the string 'webgl' or 'experimental-webgl' as
the argument to getContext, provides a 3D graphics rendering API based on OpenGL ES.
WebGL allows you to create interactive 3D graphics and games directly in the browser using
JavaScript.
Example
var canvas = document.getElementById('myCanvas');
var gl = canvas.getContext('webgl');
NOTE
The WebGL rendering context exposes a low-level API for working with shaders, buffers,
textures, and other WebGL-specific concepts.
It requires a good understanding of computer graphics and shader programming to use
effectively.
Each rendering context has its own set of methods and properties that are specific to its
capabilities.
BROWSER SUPPORT
HTML5 Canvas has excellent browser support and is widely supported across modern web
browsers.
It is supported in major desktop browsers, mobile browsers, and even in some older versions
of browsers.
Here is an overview of the browser support for HTML5 Canvas as of my knowledge cutoff
in September 2021:
2. Creating Animations:
HTML5 Canvas is great for creating animations.
By redrawing the canvas at regular intervals, you can create dynamic and interactive animations.
Here's an example of a bouncing ball animation:
Example
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
var x = canvas.width / 2;
var y = canvas.height / 2;
var dx = 2;
var dy = -2;
var ballRadius = 20;
function drawBall() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(x, y, ballRadius, 0, 2 * Math.PI);
ctx.fillStyle = 'blue';
ctx.fill();
ctx.closePath();
x += dx;
y += dy;
requestAnimationFrame(drawBall);
}
drawBall();
3. Image Manipulation:
load and manipulate images on the Canvas.
Here's an example of how to draw an image on the Canvas:
Example
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
img.onload = function() {
ctx.drawImage(img, 0, 0);
};
3. Interactive Drawing:
Allow users to draw on the Canvas using mouse or touch events.
Here's an example of a simple interactive drawing application:
Example
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
var isDrawing = false;
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseout', stopDrawing);
function startDrawing(e) {
isDrawing = true;
ctx.beginPath();
ctx.moveTo(e.clientX, e.clientY);
}
function draw(e) {
if (!isDrawing) return;
ctx.lineTo(e.clientX, e.clientY);
ctx.stroke();
}
function stopDrawing() {
isDrawing = false;
}
ctx.quadraticCurveTo(450, 200, 500, 100); // Quadratic curve from (450, 200) to (500, 100)
ctx.strokeStyle = 'green';
ctx.lineWidth = 3;
ctx.stroke();
Canvas - Drawing Paths (above code)
1. We first obtain the 2D rendering context from the canvas element.
2. Then, we use the beginPath method to start a new path.
3. We can then define the path by calling different methods:
4. moveTo sets the starting point of the path.
5. lineTo connects the current point to the specified point with a straight line.
6. arc creates an arc or circle.
7. bezierCurveTo creates a curve using cubic Bezier control points.
8. quadraticCurveTo creates a curve using quadratic Bezier control points.
9. After defining the path, we can style and render it using fill or stroke operations. fill fills the
path with a specified color, while stroke outlines the path.
10. You can set the fill and stroke styles using the fillStyle and strokeStyle properties.
11. Remember to use beginPath before starting a new path to ensure that the previous path is not
connected to the new one unintentionally.
12. By combining different path creation methods, you can create complex shapes, curves, and
lines on the canvas.
ctx.lineWidth = 3;
ctx.stroke();
Canvas - Drawing Lines (above code)
1. We first obtain the 2D rendering context from the canvas element.
2. Then, for each line we want to draw, we start a new path using beginPath.
3. We set the starting point of the line using moveTo, specifying the initial coordinates.
4. We then use lineTo to draw a line from the starting point to the desired end point.
5. After defining the line, we can set the stroke style using the strokeStyle property to specify
the color of the line.
6. The lineWidth property allows us to set the thickness of the line.
7. Finally, we call stroke to render the line on the canvas.
8. You can repeat these steps to draw multiple lines with different positions, colors, and
thicknesses.
9. Remember to call beginPath before starting a new line to ensure that the previous line is not
connected to the new one unintentionally.
10. By combining the moveTo and lineTo methods, you can create complex line patterns, shapes,
and even curves on the canvas.
4. To define the quadratic curve, we use quadraticCurveTo method, which takes two arguments:
the control point's coordinates and the end point's coordinates.
5. The control point influences the shape and direction of the curve.
6. After defining the curve, we can set the stroke style using the strokeStyle property to specify
the color of the curve.
7. The lineWidth property allows us to set the thickness of the curve.
8. Finally, we call stroke to render the curve on the canvas.
9. You can experiment with different control point and end point coordinates to create various
quadratic curves and shapes on the canvas.
10. Remember to call beginPath before starting a new curve to ensure that the previous curve is
not connected to the new one unintentionally.
11. By utilizing quadratic curves, you can achieve smooth and rounded shapes, lines, and
animations on the canvas.
9. Remember that the image must be hosted on the same domain as the web page to avoid
security restrictions due to cross-origin resource sharing (CORS).
10. By incorporating image loading and drawing into your canvas applications, you can create
dynamic visualizations, games, and interactive experiences that incorporate image assets.
5. After creating the gradient, we set the fillStyle property of the context to the gradient and
draw a rectangle using the fillRect method.
6. The rectangle will be filled with the linear gradient.
7. Next, we create a radial gradient using the createRadialGradient method, specifying the
center and radius of the inner and outer circles of the gradient.
8. Again, we use addColorStop to define color stops along the gradient.
9. Finally, we set the fillStyle property to the radial gradient and draw a circle using the arc and
fill methods.
10. The circle will be filled with the radial gradient.
11. You can customize the positions, colors, and number of color stops to create various gradient
effects on the canvas.
12. By leveraging gradients, you can enhance the visual appeal of your canvas-based applications
and create smooth color transitions in your drawings and shapes.
UNIT 5
HTML5 - STYLES AND COLORS
HTML5 - Styles and Colors, Canvas - Text and Fonts, Canvas - Pattern and Shadow, Canvas -
Save and Restore States, Canvas - Translation, Canvas - Rotation, Canvas - Scaling, Canvas -
Transforms, HTML5 Canvas - Composition, Canvas – Animations..
For example:
<head>
3 External Stylesheets
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Welcome!</h1>
</body>
2. Canvas - Pattern
Patterns in Canvas allow you to fill shapes with repeating images or custom patterns.
You can create a pattern using the createPattern() method, which takes an image or another
canvas as the pattern source.
Here's an example:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
3. Canvas Shadows:
Shadows in Canvas allow you to add a visual shadow effect to your drawings.
You can set the shadow properties using the shadowOffsetX, shadowOffsetY, shadowBlur, and
shadowColor properties.
Here's an example:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.translate(100, 100);
ctx.rotate(Math.PI / 4);
5. Canvas - Translation
In HTML5 Canvas, translation refers to the process of moving the canvas origin to a different
position.
It allows you to shift the starting point (0, 0) of the coordinate system on the canvas.
The translate() method is used to perform translation.
Here's an example that demonstrates how to use translation in canvas:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
// Perform translation
ctx.translate(100, 50);
6. Canvas -Rotation
In HTML5 Canvas, rotation allows you to rotate the canvas or individual objects around a
specific point.
The rotate() method is used to perform rotation.
Here's an example that demonstrates how to use rotation in canvas:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
7. Canvas - Scaling
In HTML5 Canvas, scaling allows you to resize and scale the canvas or individual objects.
The scale() method is used to perform scaling.
Here's an example that demonstrates how to use scaling in canvas:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
5. We draw a rectangle using fillRect() at the position (50, 50) on the scaled canvas.
6. The dimensions of the rectangle are also affected by the scaling, resulting in a rectangle that
is twice as large as it would be without scaling.
7. Scaling can also be applied to individual objects on the canvas, allowing you to resize and
transform specific elements independently.
8. By adjusting the scaling factors, you can increase or decrease the size of the canvas or objects
within it, creating interesting visual effects and transformations.
8. Canvas - Transforms
In HTML5 Canvas, transforms allow you to perform complex transformations on the canvas,
including translation, rotation, scaling, and arbitrary transformations.
The transform() and setTransform() methods are used to apply transformations.
Here's an example that demonstrates how to use transforms in canvas:
Example
// Get the canvas element
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
10. Additionally, the setTransform() method allows you to set the transformation matrix directly,
providing even more control over transformations.
9. By changing the composition mode, you can create complex compositions, layering effects,
and compositing operations to achieve the desired visual effects on the canvas.
10. Experiment with different composition modes and drawing operations to create interesting
and unique compositions.