LASICT Programming Q4 w504.25
LASICT Programming Q4 w504.25
11
ICT-PROGRAMMING.NET
FOURTH-QUARTER, WEEK 5
Name: _________________________________________________________________________________________________
Grade & Section: ______________________________________________________________________________________
Important Reminders: Read and follow directions. Do not put unnecessary markings on this material.
Always follow the standard health protocols.
Let’s Explore!
Using CSS3 to create scalable graphics and
animated user interface
In this Activity, we will practice the step-by-step how to animate an SVG
(Scalable Vector Graphic) icon using CSS. This lesson will give you valuable insight
into using SVG as your preferred graphic format. Also, you can improve the UI and
UX of your web applications by incorporating subtle animations into your SVG's.
With a little CSS and JavaScript, you can apply cool animations and effects to your
front end without requiring the user to install bulky plugins.
Scalable Vector Graphics and its uses - SVG stands for scalable vector graphics,
and it is a file format that allows you to display vector images on your website. This
means that you can scale an SVG image up and down as needed without losing any
quality, making it an excellent choice for responsive web design. (Circle 2017)
Drawing Complex graphics on HTML5 Canvas element- <canvas> is an HTML
element which can be used to draw graphics via scripting (usually JavaScript). This
can, for instance, be used to draw graphs, combine photos, or create simple (and not
so simple) animations. Canvas has several methods for drawing paths, boxes, circles,
text, and adding images. (Mozilla and individual contributors n.d.) (Refsnes Data
2021)
1
Writing and Using JavaScript code - When you see JavaScript code on the Web,
you will sometimes see some JavaScript code between the <head></head> tags. Or
you may see it in the <body></body> tags (or even in both places). To separate
JavaScript code from HTML code, you need to enclose it within a set of
<script></script> tags. The opening <script> tag has one required attribute and one
optional attribute. The required attribute is the type attribute, while the optional
attribute is src (which allows you to point to an external script file, covered later in
this answer). The value of the type of attribute is set to text/javascript, as shown
below. (Computer Hope 2021)
<script type="text/javascript">
Your JavaScript code goes here.
</script>
• translate()
• rotate()
• scale()
• skew()
• matrix()
3D transitions – The main part of the 3D Transform using CSS is the perspective.
To activate a 3D space to make the 3D transformation, you need to active it. This
activation can be done in two ways as follows:
transform: perspective(500px);
or
perspective: 500px;
3D transform includes Z-axis transformation of the HTML elements.
2
Using CSS key-frames - The @keyframes CSS at-rule controls the intermediate steps
in a CSS animation sequence by defining styles for keyframes (or waypoints) along
the animation sequence. This gives more control over the intermediate steps of the
animation sequence than transitions. (Mozilla and individual contributors n.d.)
Implementation of Complex animations - With CSS animation, elements can be
shifted, rotated, slanted, squashed, spun, and stretched on the page. They can be
bounced across the page and interact with each other in all sorts of interesting ways.
(Fitzgerald n.d.)
3
Let’s engage and work!
Practice 1- Using Scalable Vector Graphics to add interactive graphics to an
application
SVG is a platform for two-dimensional graphics. It has two parts: an XML-based file
format and a programming API for graphical applications. Key features include
shapes, text, and embedded raster graphics, with many different painting styles. It
supports scripting through languages such as ECMAScript and has comprehensive
support for animation.
As a simple practice of an SVG image file, here is a circle with a gradient to give it a
3D appearance, Open your HTML editor and have a try on these codes. (W3c 2016)
<defs>
<radialGradient id="rg" cx="100" cy="100" fx="80" fy="80"
gradientUnits="userSpaceOnUse">
<stop offset="5%" stop-color="lightskyblue" />
<stop offset="100%" stop-color="darkblue" />
</radialGradient>
</defs>
</svg>
(Luna, 2021)
4
Practice 2 - Using HTML 5 to Create Scalable Vector Graphics Files
• circle - defined as x and y point of the center (cx,cy) and the radius (cr)
• ellipse - similar to circle, but has two radius (rx,ry)
• line - defined as 4 numbers (coordinates for start and endpoints of the line)
plus a stroke color
• polygon - A polygon is effectively a series of points with lines joining them.
The last point is joined to the first point.
• polyline - similar to polygon, but the last point doesn't join the first.
• rect - A rectangle with a minimum of width and height and optional x,y, and
a radius (rx) to define a rounded rectangle.
There are additional attributes within most of these basic shapes, color being the
most common one and stroke being another. (O'Nolan n.d.)
A. Practice the image below that shows 5 shapes. From left to right, top to bottom
they are <circle>, <ellipse>, <polygon>, <polyline>, <rect>.
(Luna, 2021)
1. <svg>
2. <circle cx='50' cy='50' r='40'/>
3. <ellipse cx='180' cy='50' rx='80' ry='40' />
4. <polygon points='10,100 80,115 50,145 20,120' fill='none'
stroke='black'/>
5. <polyline points='110,100 180,115 150,145 120,120' fill='none'
stroke='black' />
6. <rect x='190' y='100' width='70' height='50'/>
7. </svg>
1. <svg>
2. <line x1='10' y1='5' x2='125' y2='90' stroke='black' />
3. </svg>
5
Practice 3 - Applying CSS transitions to elements on an HTML5 page, and
write JavaScript code to detect when a transition has occurred
Note: If the duration part is not specified, the transition will have no effect,
because the default value is 0. (w3schools n.d.)
Example A. Shows a 100px * 100px red <div> element. The <div> element has also
specified a transition effect for the width property, with a duration of 2 seconds:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
div:hover {
width: 300px;
}
</style>
</head>
<body>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
</body>
</html>
6
Example B. Adds a transition effect for both the width and height property, with a
duration of 2 seconds for program
Running the width and 4 seconds for the height:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s, height 4s;
}
div:hover {
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
</body>
</html>
7
Practice 4 - Implementing complex animations by using CSS key-frames and
JavaScript code
When you specify CSS styles inside the @keyframes rule, the animation will
gradually change from the current style to the new style at certain times. (w3schools
n.d.)
Example A. will change the background-color of the <div> element when the
animation is 25% complete, 50% complete, and again when the animation is 100%
complete:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {background-color: red;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
</style>
</head>
<body>
<h1>CSS Animation</h1>
<div></div>
</body>
</html>
8
Example B. will change both the background-color and the position of the <div>
element when the animation is 25% complete, 50% complete, and again when the
animation is 100% complete:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<h1>CSS Animation</h1>
<div></div>
</body>
</html>
Note: The animation-duration property defines how long an animation should take to
complete. If the animation-duration property is not specified, no animation will occur,
because the default value is 0s (0 seconds).
9
Let’s apply now!
WRITTEN WORKS
General Instruction: Write your answer on a separate sheet of paper.
PERFORMANCE TASK
General Instruction:
• Provide the missing code and execute the program on your text editor,
• Include your name and date of submission on the footer,
• Submit the screenshot of the complete code and running program.
3. Add a 2-second transition effect for width changes of the <div> element.
<style>
div {
width: 100px;
height: 100px;
background: red;
: ;
}
div:hover {
width: 300px;
}
</style>
<body>
<div>This is a div</div>
</body>
4. Add a 2-second animation for the <div> element, which changes the color from
red to blue. Call the animation "example".
10
<style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: ;
: 2s;
}
@keyframes example {
from { : red;}
to { : blue;}
}
</style>
<body>
<div>This is a div</div>
</body>
5. Add the following 5 steps to the animation "example" (using 0%, 25%, 50%, 75%,
and 100%):
<style>
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% { ;}
25% { ;}
50% { ;}
75% { ;}
100% { ;}
}
</style>
<body>
<div>This is a div</div>
</body>
11
RUBRIC FOR SCORING (IF NECESSARY):
Program (Excellent - 5) (Good-4) (Fair-3) (Poor- 2)
(20 pts)
Program The program The program The program The program
execution executes runs correctly runs with a does not
correctly with with syntax or minor (easily execute
no syntax or runtime errors fixed error)
runtime errors
Correct The program Output has Output has Output is
output displays minor errors multiple incorrect
correct output errors
with no errors
Design of Program The program The program Output is
output displays more displays does not poorly
than expected minimally display the designed
desired output required
output
Design of logic The program The program The program Program is
is logically has slight logic has significant incorrect
well designed errors that do logic errors
not
significantly
affect the
results
REFLECTION
12
13
1. Written Works 1 – Key Points/Concept
• 2D Transforms allow elements rendered by CSS to be transformed in two-dimensional space.
• 3D Transforms extends CSS Transforms to allow elements rendered by CSS to be transformed
in three-dimensional space
• The 3D transform functions build on the 2D functions in a rather predictable way, mostly by adding
one or 2 new functions to each group that shouldn’t require explanation.
2. Written Works 2 – Key Points/Concept
• the Web was originally just text, which was very boring, so images were introduced — first via
the <img> element and later via CSS properties such as background-image, and SVG.
• While you could use CSS and JavaScript to animate (and otherwise manipulate) SVG vector images
— as they are represented by markup — there was still no way to do the same for bitmap images,
and the tools available were rather limited. The Web still had no way to effectively create
animations, games, 3D scenes, and other requirements commonly handled by lower-level
languages such as C++ or Java.
3. Performance Task 1- Transition : width 2s
4. Example; animation-duration : background-color : background-color
5.
• left:0px; top:0px
• left:0px; top:200px
• left:200px; top:200px
• left:200px; top:0px
• left:0px; top:0px
ANSWER KEY
REFERENCES FOR LEARNERS
Circle, Kayleigh. 2017. tbh. June 15. Accessed December 11, 2021.
https://blog.tbhcreative.com/2017/06/benefits-of-using-svg.html.
Computer Hope. 2021. Accessed December 11, 2021.
https://www.computerhope.com/issues/ch001344.htm.
n.d. CSS Basic Properties. Accessed December 11, 2021.
http://web.simmons.edu/~grabiner/comm244/weekthree/css-basic-
properties.html.
Fitzgerald, Anna. n.d. The Ultimate Guide to Animations in CSS. Accessed December
2021. https://blog.hubspot.com/website/css-animation.
Mozilla and individual contributors. n.d. Accessed December 11, 2021.
https://developer.mozilla.org/en-
US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions.
—. n.d. Accessed 2021. https://developer.mozilla.org/en-
US/docs/Web/CSS/@keyframes.
O'Nolan, Conor. n.d. Using HTML 5 to Create Scalable Vector Graphics Files. Accessed
December 11, 2021. https://study.com/academy/lesson/using-html-5-to-
create-scalable-vector-graphics-files.html.
W3c. 2016. WEB DESIGN AND APPLICATIONS. Accessed December 11, 2021.
https://www.w3.org/standards/webdesign/graphics.
w3schools. n.d. www.w3schools.com. Accessed December 11, 2021.
https://www.w3schools.com/css/css3_transitions.asp.
—. n.d. www.w3schools.com. Accessed December 11, 2021.
https://www.w3schools.com/css/css3_animations.asp.
14
Prepared By:
Nestor D. Luna
ICT-Programming.net
Isabel National Comprehensive School
15