Multimedia &AnimationS NEP Notes
Multimedia &AnimationS NEP Notes
HTML was created by Sir Tim Berners-Lee in late 1991 but was not officially
released. It was published in 1995 as HTML 2.0. HTML 4.01 was published in
late 1999 and was a major version of HTML.
HTML is a very evolving markup language and has evolved with various versions
updating. Long before its revised standards and specifications are carried in, each
version has allowed its user to create web pages in a much easier and prettier way
and make sites very efficient.
• HTML 1.0 was released in 1993 with the intention of sharing information
that can be readable and accessible via web browsers. But not many of the
developers were involved in creating websites. So the language was also
not growing.
• Then comes HTML 2.0, published in 1995, which contains all the features
of HTML 1.0 along with a few additional features, which remained the
standard markup language for designing and creating websites until January
1997 and refined various core features of HTML.
• Then comes HTML 3.0, where Dave Raggett introduced a fresh paper or
draft on HTML. It included improved new features of HTML, giving more
powerful characteristics for webmasters in designing web pages. But these
powerful features of the new HTML slowed down the browser in applying
further improvements.
• Then comes HTML 4.01, which is widely used and was a successful version
of HTML before HTML 5.0, which is currently released and used
worldwide. HTML 5 can be said for an extended version of HTML 4.01,
which was published in the year 2012.
What is html?
HTML (Hypertext Markup Language) is the only markup language for creating
web pages. It provides some titles, headings, paragraphs, lists, tables, embedded
images, etc., to describe the structure of text-based and multimedia information
in HTML documents.
NDRK FGC AAV
DEPT OF COMPUTER SCIENCE MULTIMEDIA &ANIMATIONS
Example Explained
• The <!DOCTYPE html> declaration defines that this document is an HTML5
document
• The <html> element is the root element of an HTML page
• The <head> element contains meta information about the HTML page
• The <title> element specifies a title for the HTML page (which is shown in the
browser's title bar or in the page's tab)
• The <body> element defines the document's body, and is a container for all the
visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
• The <h1> element defines a large heading
• The <p> element defines a paragraph
Web Browsers
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML documents
and display them correctly.
A browser does not display the HTML tags, but uses them to determine how to display the
document:
Example 2
<img src="img_girl.jpg" alt="Girl in a jacket">
Example 3
<img src="img_chania.jpg" alt="Flowers in Chania">
LISTS
• In HTML, there are three types of lists:
1) Ordered lists,
2) Unordered lists and
3) Definition lists
Ordered Lists
• An ordered list is a numbered list where each item is numbered sequentially.
• You can create an ordered list using the <ol> tag.
• Each item within the list should be wrapped in <li> tags.
• Example:
Unordered Lists
• An unordered list is a list of items with a bullet point next to each one.
• You can create an unordered list using the <ul> tag.
• Each item within the list should be wrapped in <li> tags.
• Example:
Definition Lists
• A definition list is a list of terms and their corresponding definitions.
• You can create a definition list using the <dl> tag.
• Each term should be wrapped in a <dt> tag.
NDRK FGC AAV
DEPT OF COMPUTER SCIENCE MULTIMEDIA &ANIMATIONS
TABLES
• <table> tag is used to create a table in a web-page.
• It allows you to display data in a tabular format, with rows and columns.
• Syntax:
Where
<table>: defines the table.
• The <table> element can also have several optional attributes, such as: border: specifies
the width of the border around the table cellspacing: specifies the space between
cells
cellpadding: specifies the space between cell borders and their content
width: specifies the width of the table
height: specifies the height of the table
Where
action: specifies the URL to which the form-data will be submitted.
method: specifies the HTTP method to be used when submitting the form-data.
This can be either "GET" or "POST"
<input type="password">: This creates a password input-field that hides the text entered.
<input type="radio">: This creates a set of radio buttons where only one can be selected at a time.
<select>: This creates a dropdown menu for selecting from a list of options.
<textarea>: This creates a multi-line text input-field.
Images are not technically inserted into a web page; images are linked to web pages.
The <img> tag creates a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
The uter
<img>Applications
tag has two required attributes:
Syntax
<img src="url" alt="alternatetext">
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
HTML <frame> tag (Not supported in HTML5)
HTML <frame> tag define the particular area within an HTML file where another HTML web
page can be displayed.
A <frame> tag is used with <frameset>, and it divides a webpage into multiple sections or frames,
and each frame can contain different web pages.
Note: Do not use HTML <frame> tag as it is not supported in HTML5, instead you can use <iframe> or <div>
with CSS to achieve similar effects in HTML.
Syntax
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
utersrc
< frame Applications
= "URL" >
Display Block
Usage Frames
Example 1
Create Vertical frames:
<!DOCTYPE html>
<html>
<head>
<title>Frame tag</title>
</head>
<frameset cols="25%,50%,25%">
<frame src="frame1.html" >
<frame src="frame2.html">
<frame src="frame3.html">
</frameset>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Frame1.html
<!DOCTYPE html>
<html>
<head>
<style>
div{
background-color: #7fffd4;
height: 500px;
}
</style>
</head>
<body>
<div>
<h2>This is first frame</h2>
</div>
</body>
</html>
Frame2.html
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<!DOCTYPE html>
<html>
<head>
<style>
div{
background-color: #2f4f4f;
height: 500px;
}
</style>
</head>
<body>
<div>
<h2>This is Second frame</h2>
</div>
</body>
</html>
Frame3.html
<!DOCTYPE html>
<html>
<head>
<style>
div{
background-color: #c1ffc1;
height: 500px;
}
</style>
</head>
<body>
<div>
<h2>This is Third frame</h2>
</div>
</body>
</html>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Example 2:Create Horizontal frames:
<!DOCTYPE html>
<html>
<head>
<title>Frame tag</title>
</head>
<frameset rows="30%, 40%, 30%">
<frame name="top" src="frame1.html" >
<frame name="main" src="frame2.html">
<frame name="bottom" src="frame3.html">
</frameset>
</html>
Output:
HTML <frameset> tag is used to contain the group of frames which can be controlled and styled
as a unit. The <frameset> element also specifies the number of rows and columns in the frameset,
and how much space they will occupy in a frame.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
Note: uter
Do Applications
not use HTML <frameset> element as it is deprecated and not supported by HTML5, but you can use
<iframe> tag instead.
Syntax
<frameset cols=" ">............</frameset>
Display Block
Usage Frames
Attribute
Tag-specific attribute
cols Pixels It specifies the number and size of column spaces in the frameset. (Not
% Supported in HTML5)
*
rows Pixels It specifies the number and size of the rows spaces in the frameset. (Not
% Supported in HTML5)
*
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
• uter Applications
Video and
Audio Features
• Header and Footer
• Input tag kinds have been expanded.
• Figure and figcaption
• Placeholders
• Preload Videos
• Controlling the display
• Regular Expressions
• Adaptability
• Elements that appear inline
• Support for Dynamic Pages
• Email as a property
• Cryptographic Nonces
• Reverse Links
• Images with a width of zero
• Canvas in HTML5
INTRODUCTION
• CSS stands for Cascading Style-sheets.
• CSS is used to describe the visual presentation of HTML.
• CSS is used to define the layout, colors, fonts, and other visual aspects of a web-page.
ADVANTAGES OF CSS
1) Separation of Content and Presentation
• CSS allows for the separation of the content and presentation of a web-page.
• This makes it easier to maintain and update the website.
Consistency
• CSS enables the consistent application of styles across multiple web-pages.
• This helps in creating a unified and professional look for the entire website.
Easy to Learn
• CSS has a relatively simple syntax.
• CSS is easy to learn for beginners.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Flexibility
• CSS provides flexibility in designing web-pages.
• With CSS, developers can
create complex layouts
adjust the size and position of elements and
apply various effects and animations.
Efficiency
• CSS reduces page load-time by separating the presentation from the content.
• This makes web-pages load faster.
• This improves the overall performance of the website.
Responsive Design
• CSS allows for the creation of responsive webpages.
• The webpages can adapt to different screen-sizes & devices.
• This ensures that the website is accessible and user-friendly across all devices.
HTML vs CSS
HTM CSS
L
Stands for HyperText Markup Language Stands for Cascading Style-sheets
Used for creating the structure and content of a Used for controlling the presentation and layout of
web-page the content
Uses tags to define elements such as headings, Uses selectors to target HTML-elements and apply
paragraphs, images, links, etc. styles
Provides a way to add text, images, and other Provides a way to add styles such as color, font,
media to a web-page spacing, and layout to a web-page
Supports attributes that provide additional Supports various types of selectors, including
information about HTML-elements, such as the element, class, and ID-selectors
source of an image or the target of a link
Allows for the creation of responsive web-pages Allows for the creation of complex layouts and
using media queries and other techniques animations using advanced CSS techniques
Can be used in conjunction with other technologies Can be used in conjunction with preprocessors like
such as JavaScript to create dynamic web- Sass or LESS to create more efficient and organized
applications style-sheets
What is CSS?
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
• uter
CSSApplications
stands for Cascading Style Sheets
• CSS describes how HTML elements are to be displayed on screen, paper, or in other media
• CSS saves a lot of work. It can control the layout of multiple web pages all at once
• External stylesheets are stored in CSS files
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Syntax
A CSS rule consists of a selector and a declaration block.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
CSS Syntax
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.
Example
In this example all <p> elements will be center-aligned, with a red text color:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: red;
text-align: center;
}
</style>
</head>
<body>
<p>Hello World!</p>
<p>These paragraphs are styled with CSS.</p>
</body>
</html>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Example Explained
• p is a selector in CSS (it points to the HTML element you want to style: <p>).
• color is a property, and red is the property value
• text-align is a property, and center is the property value
CSS Selectors
A CSS selector selects the HTML element(s) you want to style.
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color:
<!DOCTYPE html>
<html>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
<head>uter Applications
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
The id of an element is unique within a page, so the id selector is used to select one unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the element.
Example
The CSS rule below will be applied to the HTML element with id="para1":
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>
The CSS class Selector
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
<!DOCTYPE html>
<html>
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Example
In this example only <p> elements with class="center" will be red and center-aligned:
<!DOCTYPE html>
<html>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
<head>uter Applications
<style>
p.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
Example
In this example the <p> element will be styled according to class="center" and to class="large":
<!DOCTYPE html>
<html>
<head>
<style>
p.center {
text-align: center;
color: red;
}
p.large {
font-size: 300%;
}
</style>
</head>
<body>
</body>
</html>
Example
The CSS rule below will affect every HTML element on the page:
<!DOCTYPE html>
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
Look at the following CSS code (the h1, h2, and p elements have the same style definitions):
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
h1 { uter Applications
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p{
text-align: center;
color: red;
}
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</body>
</html>
Example
In this example we have grouped the selectors from the code above:
<!DOCTYPE html>
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
element,element,.. div, p Selects all <div> elements and all <p> elements
• Inline CSS
• Internal or Embedded CSS
• External CSS
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of the <p> element to
red:
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
</body>
</html>
Output:
Internal CSS
An internal CSS is used to define a style for a single HTML page.
The following example sets the text color of ALL the <h1> elements (on
that page) to blue, and the text color of ALL the <p> elements to red. In
addition, the page will be displayed with a "powderblue" background color
<html>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:
External CSS
An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the <head> section of each
HTML page.
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:
CSS Border
The CSS border property defines a border around an HTML element.
<html>
<head>
<style>
p{
border: 2px solid powderblue;
}
</style>
</head>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
CSS Padding
The CSS padding property defines a padding (space) between the text and
the border.
<html>
<head>
<style>
p{
border: 2px solid powderblue;
padding: 30px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
Output:
CSS Margin
The CSS margin property defines a margin (space) outside the border.
<html>
<head>
<style>
p{
border: 2px solid powderblue;
margin: 50px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</body>
</html>
Output:
CSS Lists:
Unordered Lists:
o Coffee
o Tea
o Coca Cola
▪ Coffee
▪ Tea
▪ Coca Cola
Ordered Lists:
1. Coffee
2. Tea
3. Coca Cola
I. Coffee
II. Tea
III. Coca Cola
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
HTML Lists and CSS List Properties
In HTML, there are two main types of lists:
• unordered lists (<ul>) - the list items are marked with bullets
• ordered lists (<ol>) - the list items are marked with numbers or letters
<html>
<head>
<style>
ul.a {
list-style-type: circle;
}
ul.b {
list-style-type: square;
}
ol.c {
list-style-type: upper-roman;
}
ol.d {
list-style-type: lower-alpha;
}
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</style>
</head>
<body>
<ul class="b">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
</ul>
<ol class="d">
<li>Coffee</li>
<li>Tea</li>
<li>Coca Cola</li>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
</ol>uter Applications
</body>
</html>
Output:
Anything added to the <ol> or <ul> tag, affects the entire list, while properties added to the <li> tag will affect
the individual list items:
ol {
background: #ff9999;
padding: 20px;
}
ul {
background: #3399ff;
padding: 20px;
}
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
ol li uter
{ Applications
background: #ffe5e5;
color: darkred;
padding: 5px;
margin-left: 35px;
}
ul li {
background: #cce5ff;
color: darkblue;
margin: 5px;
}
Output:
CSS Syntax
color: color|initial|inherit;
<html>
<head>
<style>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
bodyuter{Applications
color: red;
}
h1 {
color: #00ff00;
}
p.ex {
color: rgb(0,0,255);
}
</style>
</head>
<body>
<p>This is an ordinary paragraph. Notice that this text is red. The default
text-color for a page is defined in the body selector.</p>
</body>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
CSS Text Alignment
Text Alignment
The text-align property is used to set the horizontal alignment of a text.
h2 {
text-align: left;
}
h3 {
text-align: right;
}
</style>
</head>
<body>
<h1>Heading 1 (center)</h1>
<h2>Heading 2 (left)</h2>
<h3>Heading 3 (right)</h3>
<p>The three headings above are aligned center, left and right.</p>
</body>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</html>
Output:
p.b {
text-align-last: center;
}
p.c {
text-align-last: justify;
}
</style>
</head>
<body>
<h2>text-align-last: right:</h2>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<p class="a">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum
volutpat tellus diam, consequat gravida libero rhoncus ut.</p>
<h2>text-align-last: center:</h2>
<p class="b">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum
volutpat tellus diam, consequat gravida libero rhoncus ut.</p>
<h2>text-align-last: justify:</h2>
<p class="c">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum
volutpat tellus diam, consequat gravida libero rhoncus ut.</p>
</body>
</html>
Output:
Text Direction
The direction and unicode-bidi properties can be used to change the text
direction of an element:
<html>
<head>
<style>
p.ex1 {
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
direction: rtl;
unicode-bidi: bidi-override;
}
</style>
</head>
<body>
</body>
</html>
Output:
Vertical Alignment
The vertical-align property sets the vertical alignment of an element.
<html>
<head>
<style>
img.a {
vertical-align: baseline;
}
img.b {
vertical-align: text-top;
}
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
img.c {
vertical-align: text-bottom;
}
img.d {
vertical-align: sub;
}
img.e {
vertical-align: super;
}
</style>
</head>
<body>
<h2>vertical-align: text-top:</h2>
<p>An <img class="b" src="sqpurple.gif" width="9" height="9"> image
with a text-top alignment.</p>
<h2>vertical-align: text-bottom:</h2>
<p>An <img class="c" src="sqpurple.gif" width="9" height="9"> image
with a text-bottom alignment.</p>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
The <span> tag is much like the <div> element, but <div> is a block-level
element and <span> is an inline element.
<html>
<body>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</body>
</html>
Output:
The <div> tag is used as a container for HTML elements - which is then
styled with CSS or manipulated with JavaScript.
<div class="myDiv">
<h2>This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>
</body>
</html>
Output:
Program explained:
This example creates an object called the person that has three
properties which are: name, age, and job, and one method
(say_Name()). The say_Name() method displays the value of
this.name, which resolves to person.name.
The previous example can be rewritten using literal object notation
as follows:
var person = {
name: "Karlos",
age: 23,
job: "Network Engineer",
say_Name: function() {
alert(this.name);
}
};
The person object in the above example is equivalent to the object in the
previous example, with all those same properties and methods added.
These properties are all created with specific characteristics that define
their behavior in JavaScript.
JavaScript Syntax
JavaScript syntax is the set of rules, how JavaScript programs are
constructed:
Fixed values
Variable values
Fixed values are called Literals.
JavaScript Literals
The two most important syntax rules for fixed values are:
<h2>JavaScript Numbers</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 10.50;
</script>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
</body>
</html>
Output:
<h2>JavaScript Strings</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 'John Doe';
</script>
</body>
</html>
Output:
JavaScript Variables
In a programming language, variables are used to store data values.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
JavaScript uses the keywords var, let and const to declare variables.
<h2>JavaScript Variables</h2>
<p id="demo"></p>
<script>
let x;
x = 6;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
Output:
JavaScript Operators
JavaScript uses arithmetic operators ( + - * / ) to compute values: <html>
<body>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<h2>JavaScript Operators</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = (5 + 6) * 10;
</script>
</body>
</html>
Output:
JavaScript Expressions
An expression is a combination of values, variables, and operators, which
computes to a value.
5 * 10
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
JavaScript Keywords
JavaScript keywords are used to identify actions to be performed.
<p id="demo"></p>
<script>
let x, y;
x = 5 + 6;
y = x * 10;
document.getElementById("demo").innerHTML = y;
</script>
</body>
</html>
****************
The var keyword also tells the browser to create variables:
<html>
<body>
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
<script>
var x, y;
x = 5 + 6;
y = x * 10;
document.getElementById("demo").innerHTML = y;
</script>
</body>
</html>
JavaScript Operators:
JavaScript Operators
Operators are used to assign values, compare values, perform
arithmetic operations, and more.
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Conditional Operators
Type Operators
JavaScript Arithmetic Operators
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Arithmetic operators are used to perform arithmetic between
variables and/or values.
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The + Operator</h2>
<p id="demo"></p>
<script>
let y = 5;
let x = y + 2;
document.getElementById("demo").innerHTML = "Value of x is: "
+ x;
</script>
</body>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<h1>JavaScript Assignment</h1>
<h2>Simple Assignment</h2>
<h2>The = Operator</h2>
<p id="demo"></p>
<script>
let x = 10;
let y = 5;
x = y;
document.getElementById("demo").innerHTML = "Value of x is: " + x;
</script>
</body>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
<h1>JavaScript Operators</h1>
<h2>The + Operator</h2>
<p id="demo"></p>
<script>
let text1 = "Good ";
let text2 = "Morning";
let text3 = text1 + text2;
document.getElementById("demo").innerHTML = text3;
</script>
</body>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Logical Operators
Logical operators are used to determine the logic between variables
or values.
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The && Operator (Logical AND)</h2>
<p>The && operator returns true if both expressions are true, otherwise
false:</p>
<p id="demo"></p>
<script>
let x = 6;
let y = 3;
document.getElementById("demo").innerHTML =
(x < 10 && y > 1) + "<br>" +
(x < 10 && y < 1);
</script>
</body>
</html>
Output:
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
Primitives in JavaScript:
JavaScript has seven types. Types are values that JavaScript can have. Below is a list of data types
that JavaScript can have:
1. Number
2. String
3. Boolean
4. Undefined
5. Null
6. Object
7. Symbol
Numbers:
A number data type can be an integer, a floating point value, an exponential value, a ‘NaN’ or a
‘Infinity’.
String:
The string data type in JavaScript can be any group of characters enclosed by a single or double-
quotes or by backticks.
var str1 = “This is a string1”; // This is a string primitive type or string literal
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
Boolean:
The boolean data type has only two values, true and false. It is mostly used to check a logical
condition. Thus Booleans are logical data types which can be used for comparison of two variables
or to check a condition.
var a =5;
var a =5;
var b=6;
unit-II
Introduction to Animations:
Definition of Animation :
Animation is the process of creating an illusion of motion and
shape change by means of rapid display of various type of pictures
that were made to create a single scene.
The Start and End States
If visualizing change is an important part of an animation, we need
to create some reference points so that we can compare what has
changed. Let’s call these reference points the start state and
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
the uter
end state. To better explain what is going on, let’s come up with
Applications
You start off with a small blue circle located to the left of the
screen. At the end state,
.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
.
Interpolation
In order to make an animation out of what we have, we need a
smooth transition that creates all the intermediate states. The
process of creating these intermediate states is known
as interpolation.
This interpolation, which occurs over a period of time that we
specify
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
interpolation
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
interpolating between the two states, is take care of automatically
Scripted/JavaScript animations
If you want full control over what your animation does right down
to how it interpolates between states,
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
CSS Animations
• CSS Animations are a way to add visual effects to web pages.
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
• With CSS animations, you can animate the position, size and
color of HTML elements.
• With CSS animations, you can specify
1) Duration of an animation
2) Speed of an animation
3) Number of iterations of an animation
4) Direction of an animation
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
animation-fill- Specifies what styles are applied to the
mode element before and after
the animation.
animation-play-
state Specifies
running orwhether
paused.the animation is
animation A shorthand property used for setting
all the animation
properties (except the animation-play-
state and the animation- fill- mode
property).
AAV
COMPUTER SCIENCE Multimedia&Animations
SCIENCE&APPLICATIONS
uter Applications
AAV
Computer Applications Multimedia Animation
AAV
Computer Applications Multimedia Animation
@keyframes
changecolor {
0%
{background:
red;}
100% {background: green; }
}
Explanation of above code:
• changecolor is a user-defined name for the animation.
• 0% specifies the starting state of the animation where the
occur
AAV
Computer Applications Multimedia Animation
AAV
[Type here] [Type here] [Type here]
SESSION 3
<html>
<head>
<style>
@keyframes movebox {
from {left: 0px; top:0px }
to {left: 600px; top:0px} }
div { width: 100px;
height:
100px;
background:
red; position:
relative;
animation-name: movebox;
animation-duration: 10s;
animation-timing-function :
linear; animation-delay: 5s; }
</style>
</head>
<body>
<div></div>
</body>
</html>
[Type here] [Type here] [Type here]
1|P a g e
Computer Applications Multimedia Animation
clockwise direction.
<html>
<head>
<style>
to
animation-name: movebox;
animation-duration: 5s; animation-
iteration-count : 3;
</style>
</head>
<body>
<div></div></body>
3|P a g e
Computer Applications Multimedia Animation
4|P a g e
Computer Applications Multimedia Animation
1|P a g e
Computer Applications Multimedia Animation
<head>
<style>
@keyframes changecolor {
from {background: red;
to
div {
2|P a g e
Computer Applications Multimedia Animation
animation-
name: movebox
animation-
duration: 5s
animation-
timing-function:
linear animation-
delay: 1s
animation-
iteration-count:
infinite
animation-
direction: normal
5|P a g e
Computer Applications Multimedia Animation
<head>
<style>
@keyframes changecolor {
@keyframes movebox {
from {left: 0px; top:0px
</style>
</head>
Explanation of the Program
• <html>: This tag denotes the beginning of an HTML document.
• <head>: This tag is used to contain meta-data about the
6|P a g e
Computer Applications Multimedia Animation
7|P a g e
MULTIMEDIA & ANIMATIONS
CSS Transitions
• CSS transitions are a way to make web page elements
change smoothly from one style to another
• A transition effect could typically occur when a user hover over
an element.
• With CSS transitions, you can specify
1) Duration of transition
2) Speed of transition
3) CSS property for transition
AAV
MULTIMEDIA & ANIMATIONS
AAV
MULTIMEDIA & ANIMATIONS
they are being hovered over by the cursor, and applies the
following styles to them:
background:yellow;: Sets the background color of the div
element to yellow.
• div : This selector targets all div elements and applies the
following styles to them:
transition-property:background;: This property specifies
which CSS properties should be transitioned when
changes occur. In this case, it's the background
property. transition-duration:1s;: This property
specifies the duration of the transition in seconds. In this
case, it's 1 second.
AAV
Computer Applications Multimedia Animation
SESSION 8
transition-timing-function: linear|ease|ease-in|ease-out|ease-in-
out
5|P a g e
Computer Applications Multimedia Animation
<html>
<head>
<style>
div {
width:100px;
height: 100px;
background:blue;
}
div:hover {
width:200px;
}
div {
transition-property:width;
transition-duration:5s;
transition-timing-function: linear;
transition-delay: 1s;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
6|P a g e
Computer Applications Multimedia Animation
7|P a g e
Computer Applications Multimedia Animation
(ms).
timing-function specifies the speed curve of the transition.
This can be one of the following values: linear, ease, ease-
in, ease-out, or ease-in-out
delay specifies the delay before the transition starts.
This can also be expressed in seconds or milliseconds.
• When using the shorthand notation for transitions, the
AAV
Computer Applications Multimedia Animation
AAV
Computer Applications Multimedia Animation
transition-
property: height;
transition-
duration: 5s;
transition-timing-
function: linear;
transition-delay: 1s;
<html>
<head>
<style>
div {
width:100px; height:
100px;
background:blue;
}
div:hover { width:200px;
height: 200px;
}
div { transition: width 5s linear 1s,
transition: height 5s linear 1s;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
AAV
Computer Applications Multimedia Animation
• div : This selector targets all div elements and applies the
following styles to them:
width:100px;: Sets the width of the div element to 100
pixels.
height: 100px;: Sets the height of the div element to 100
pixels.
background:blue;: Sets the background color of the div
element to blue.
•div:hover : This selector targets all div elements when
they are being hovered over by the cursor, and applies the
following styles to them:
width:200px;: Sets the width of the div element to 200
pixels
height:200px;: Sets the height of the div element to 200
pixels
• div : This selector targets all div elements and applies the
following styles to them:
transition: width 5s linear 1s, height 5s linear 1s;: This
property specifies the duration, timing function, and
delay for the transition of the width and height
properties. Specifically, it means that the transition of
the width and height properties should take
5 seconds, have a linear timing function, and begin 1
second after the change is triggered.
AAV
Computer Applications Multimedia Animation
HTML5 – SVG
• SVG stands for Scalable Vector Graphics.
• SVG is a vector-based image format.
• Mathematical equations are used to create SVG images.
• SVG images can be scaled up or down without losing quality.
• SVG images are commonly used in webpages to display logos,
icons, maps etc.
available that allow you to open, edit, and view SVG files.
Some popular options include Adobe Illustrator, Inkscape,
Sketch, and Figma.
height="height">
[SVG elements]
</svg>
Where width and height : specify the dimensions of
the SVG image
width and height: can be specified in pixels or %
SVG elements : can be <line>, <rect>, <circle> etc
1|P a g e
Computer Applications Multimedia Animation
1|P a g e
Computer Applications Multimedia Animation
<!DOCTYPE html>
<html>
<body>
1|P a g e
Computer Applications Multimedia Animation
<html>
<body>
2|P a g e
Computer Applications Multimedia Animation
<html>
<body>
• We use the <svg> tag to create an SVG graphic with a width and
height of 200 pixels.
• We then use the <circle> tag to create a circle with
i) center at (cx, cy) = (100, 100) and
ii) radius of 50 pixels.
• The fill attribute is set to "blue", which fills the circle with the
color blue.
AAV
Computer Applications Multimedia Animation
<html>
<body>
2|P a g e
Computer Applications Multimedia Animation
<!DOCTYPE html>
<html>
<body>
<svg width="200" height="200">
<polygon points="25,25 100,100 175,25" fill="blue" />
</svg>
</body>
Output:
3|P a g e
Computer Applications Multimedia Animation
<html>
<body>
• We use the <svg> tag to create an SVG graphic with a width and
height of 200 pixels.
• We then use the <polyline> tag to create a polyline with
<html>
<body>
5|P a g e
Computer Applications Multimedia Animation
LinearGradient
• This defines a linear gradient.
• Two types of linear gradients are: horizontal and vertical
gradients.
• Syntax:
<svg>
</svg> Where,
6|P a g e
Computer Applications Multimedia Animation
<html>
<body>
<defs>
7|P a g e
Computer Applications Multimedia Animation
RadialGradient
• This defines a radial gradient.
• Syntax:
<svg>
<radialGradient
id="gradientID"
cx=“[cx]"
cy=“[cy]"
r=“[r]">
</sv <stop offset="0%" stop-color="start-color" />
g> <stop offset="100%" stop-color="end-color" />
Where, </radialGradient>
9|P a g e
MULTIMEDIA AND ANIMATIONS
Output:
Introduction to Animations:
Definition of Animation :
Animation is the process of creating an illusion of motion and
shape change by means of rapid display of various type of pictures
that were made to create a single scene.
The Start and End States
If visualizing change is an important part of an animation, we need
to create some reference points so that we can compare what has
changed. Let’s call these reference points the start state and
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
the end state. To better explain what is going on, let’s come up with
an easy-to-understand example as well.
Let’s say our start state looks like Figure 1-3.
You start off with a small blue circle located to the left of the
screen. At the end state,
.
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
.
Interpolation
In order to make an animation out of what we have, we need a
smooth transition that creates all the intermediate states. The
process of creating these intermediate states is known
as interpolation.
This interpolation, which occurs over a period of time that we
specify
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
interpolation
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
interpolating between the two states, is take care of automatically
Scripted/JavaScript animations
If you want full control over what your animation does right down
to how it interpolates between states,
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
UNIT-III
HTML CANVAS
HTML <canvas> element is used to draw graphics, on the fly, via
JavaScript. <canvas> element is only a container for graphics. You must use JavaScript to actually
draw the graphics.Canvas has several methods for drawing paths, boxes, circles, text, and adding
images.HTML5 introduces canvas and svg tags to draw graphical content such as graphs,
animation, geometrical shapes etc. using javascript API.
1.
Canvas
2. Svg
• The HTML <canvas> element is used to draw graphics on a web page.
• The <canvas> element is only a container for graphics which is drawn using JavaScript API
to actually draw the graphics.
• Javascript is used to draw the graphics in the container.
• Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
• <canvas id="identification" width="width" height="height"></canvas>
Rendering Context
Browser Support
The numbers in the table specify the first browser version that fully supports the <canvas>
element.
Drawing Paths
2
Learn how to make shapes using paths in HTML5 <canvas> element
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Drawing Lines
3
Learn how to draw lines using HTML5 <canvas> element
Drawing Bezier
4
Learn how to draw Bezier curve using HTML5 <canvas> element
Drawing Quadratic
5
Learn how to draw quadratic curve using HTML5 <canvas> element
Using Images
6
Learn how to use images with HTML5 <canvas> element
Create Gradients
7
Learn how to create gradients using HTML5 <canvas> element
Canvas States
11 Learn how to save and restore canvas states while doing complex drawings on a
canvas.
Canvas Translation
12 This method is used to move the canvas and its origin to a different point in the
grid.
Canvas Rotation
13
This method is used to rotate the canvas around the current origin.
Canvas Scaling
14
This method is used to increase or decrease the units in a canvas grid.
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Canvas Transform
15
These methods allow modifications directly to the transformation matrix.
Canvas Composition
16
This method is used to mask off certain areas or clear sections from the canvas.
Canvas Animation
17
Learn how to create basic animation using HTML5 canvas and JavaScript.
Drawing Rectangles:
The rect() method is used to create a rectangle. The stroke() or the fill() method is used to draw
the rectangle on the canvas.
JavaScript syntax: context.rect(x,y,width,height);
Drawing Paths
There are one or more points in each subpath that are connected by straight lines or curves. To
create a custom shape perform the following steps :
• Use beginPath() method to start drawing the path.
• Draw the path that makes a shape using lines, curves and other primitives
Drawing Lines
To draw a straight line on a canvas, use the following methods:
Drawing circle
To draw a circle on a canvas, use the following methods:
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Center
arc(100,75,50,0*Math.PI,1.5*Math.PI)
Start angle
arc(100,75,50,0,1.5*Math.PI)
End angle
arc(100,75,50,0*Math.PI,1.5*Math.PI)
Drawing Bezier canvas
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Using Images
The drawImage() method draws an image into the canvas. The drawImage() method can also
draw parts of an image, and/or increase/reduce the image size.
Syntax
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
HTML program to import an external Image into a canvas and then to draw on that image
<!DOCTYPE html>
<html>
<body>
<p>Image to use:</p>
<img id="flower" width="100" height="100"
src="flower.jpg" alt="flower">
<p>Canvas:</p>
<canvas id="myCanvas" width="100" height="100"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Create gradients
Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the canvas are not limited
to solid colors.
Once we have a gradient object, we must add two or more color stops.
The addColorStop() method specifies the color stops, and its position along the gradient. Gradient
positions can be anywhere between 0 to 1.
To use the gradient, set the fillStyle or strokeStyle property to the gradient, then draw the shape
(rectangle, text, or a line).
Linear Gradients
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid grey;"></canvas>
<script>
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
// Create gradient
var grdient = ctx.createLinearGradient(0,0,200,0);
grdient.addColorStop(0,"red");
grdient.addColorStop(1,"blue");
// Fill with gradient
ctx.fillStyle = grdient;
ctx.fillRect(10,10,150,80);
</script>
</body>
</html>
Radial Gradients
• createRadialGradient() method used to produce aradial gradient with HTMl5 canvas.
• Radial gradients are described with two fictional circles- a beginning circle and an ending
circle
• Gradient begins with the start circle and goes towards the end circle
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Syntax:
var gradients=object.createRadialGradient(x0,y0,x1,y1,r1);
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
fillStyle
1
This attribute represents the color or style to use inside the shapes.
strokeStyle
2
This attribute represents the color or style to use for the lines around shapes
By default, the stroke and fill color are set to black which is CSS color value #000000.
1.fillstyle
The fillStyle property sets or returns the color, gradient, or pattern used to fill the drawing.
Default value: #000000
Property Values
Value Description
Color A CSS color value that indicates the fill color of the
drawing. Default value is #000000
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(20, 20, 150, 100);
</script>
</body></html>
2.Stroke Style
The strokeStyle property sets or returns the color, gradient, or pattern used for strokes.
Default value: #000000
Property Values
Value Description
color A CSS color value that indicates the stroke color of the
drawing. Default value is #000000
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "#FF0000";
ctx.strokeRect(20, 20, 150, 100);
</script> </body> </html>
Output:
Text
To draw text on a canvas, the most important property and methods are:
• font - defines the font properties for the text
• fillText(text,x,y) - draws "filled" text on the canvas
• strokeText(text,x,y) - draws text on the canvas (no fill)
fillText() is used to render filled text to the canvas by using the existing fill style and font
syntax: ctx.fillText(text,x,y);
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #d3d3d3;">
Your browser does not support the canvas element.
</canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("Hello World",10,50);
</script>
</body>
</html>
Ouput:
strokeText()
strokeText() is used to render the specified text at the specifies position by using current font,
lineWidth and strokeStyle property.
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Syntax: ctx.strokeText(text,x,y);
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid grey;"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
Shadow
1. shadow color
2. shadowoffsetX
3.shadowoffsetY
4.shadowblur
1. Shadowcolor : The shadowColor property sets or returns the color to use for shadows.
context.shadowColor = color
2. shadowblur :The shadowBlur property sets or returns the blur level for shadows.
The default value is 0.
3. shadowoffsetX : The shadowOffsetX property sets or returns the
horizontal distance of the shadow from the shape.
Syntax: context.shadowOffsetX = number
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
4. shadowOffsetY : The shadowOffsetY property sets or returns the vertical distance of the
shadow from the shape.
Default value is 0.
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The createPattern() Method</h2>
<p>Image to use:</p>
<img src="\D:\p.png" id="lamp" width="50" height="50">
<p>
<button onclick="draw('repeat')">Repeat</button>
<button onclick="draw('repeat-x')">Repeat-x</button>
<button onclick="draw('repeat-y')">Repeat-y</button>
<button onclick="draw('no-repeat')">No-repeat</button>
</p>
<canvas id="myCanvas" width="1000" height="1050" style="border:1px solid
#d3d3d3;">
</canvas>
<script>
function draw(direction)
{
const c = document.getElementById("myCanvas");
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
const img = document.getElementById("lamp")
const pat = ctx.createPattern(img, direction);
ctx.rect(0, 0, 600, 600);
ctx.fillStyle = pat;
ctx.fill();
}
</script>
</body>
</html>
Canvas Translation
This method is used to move the canvas and its origin to a different point in the grid.
Synatx:
context.translate(x, y)
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The translate() Method</h2>
Canvas Scaling
This method is used to increase or decrease the units in a canvas grid. If you scale a context, all
future drawings will be scaled. If you scale(2,2), drawings will be positioned twice as far from the
0,0 position of the canvas as you specify.
Synatx:
context.scale(scalewidth, scaleheight)
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The scale() Method</h2>
<canvas id="myCanvas" width="500" height="550" style="border:1px solid grey"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(10,10,50,50);
ctx.scale(2,2);
ctx.fillStyle="blue";
ctx.fillRect(40,40,50,50);
</script>
</body>
</html>
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Canvas Rotation
The rotate() method rotates the context. This method is used to rotate the canvas around
the current origin.
Syntax: context.rotate(angle)
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The rotate() Method</h2>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid grey"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.rotate(20 * Math.PI / 180);
ctx.fillRect(50, 20, 100, 50);
</script>
</body>
</html>
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
Canvas Transform
These methods allow modifications directly to the transformation matrix.
The transform() method scales, rotates, moves, and skews the
context.
Each object on the canvas has a transformation matrix.
The transform() method replaces the transformation matrix, and multiplies the it with a matrix
described by:
ace
bdf
001
Synatx:
context.transform(a, b, c, d, e, f)
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The transform() Method</h2>
<canvas id="myCanvas" width="500" height="550" style="border:1px solid grey"></canvas>
<script>
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
ctx.fillStyle = "yellow";
ctx.fillRect(0, 0, 250, 100)
ctx.transform(1, 0.5, -0.5, 1, 30, 10);
ctx.fillStyle = "red";
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
ctx.fillRect(0, 0, 250, 100);
Canvas Composition :- This method is used to mask off certain areas or clear sections from the
canvas The globalCompositeOperation property sets or returns how a source are drawn over a
destination.
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<!DOCTYPE html>
<html>
<body>
<h1>HTML5 Canvas</h1>
<h2>The globalCompositeOperation Property</h2>
<canvas id="myCanvas" width="500" height="550" style="border:1px solid grey"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(40, 40, 250, 100);
ctx.globalCompositeOperation = "source-over";
//ctx.globalCompositeOperation = "source-in";
//ctx.globalCompositeOperation = "source-out";
//ctx.globalCompositeOperation = "source-atop";
//ctx.globalCompositeOperation = "lighter";
//ctx.globalCompositeOperation = "xor";
//ctx.globalCompositeOperation = "destination-in";
//ctx.globalCompositeOperation = "destination-out";
//ctx.globalCompositeOperation = "destination-atop";
//ctx.globalCompositeOperation = "copy";
ctx.fillStyle = "blue";
ctx.fillRect(90, 90, 250, 100);
</script>
</body>
</html>
Canvas animations
1. setinterval
2. settimeout
Setinterval :The setInterval() method calls a function at specified intervals (in milliseconds).
The setInterval() method continues calling the function until clearInterval() is called, or the
window is closed.
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
1 second = 1000 milliseconds.
2.settimeout:
<!DOCTYPE html>
<html>
<body>
<h1>The Window Object</h1>
<h2>The setInterval() Method</h2>
<p id="demo"></p>
<script>
var element = document.getElementById("demo");
setInterval(function(){element.innerHTML += "Hello"}, 1000);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
NDRK FGC
MM AAV
MULTIMEDIA AND ANIMATIONS
<body>
NDRK FGC
MM AAV