1 CS101 Introduction to Computing Lecture 41 Images & Animation (Web Development Lecture 14)

Slides:



Advertisements
Similar presentations
Introduction to Web Design Lecture number:. Todays Aim: Introduction to Web-designing and how its done. Modelling websites in HTML.
Advertisements

Tutorial 5 Windows and Frames Section A - Working with Windows.
Working with Images and HTML
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Iframes & Images Using HTML.
Java Script Session1 INTRODUCTION.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Session 8 JavaScript/Jscript: Objects Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
The Web Warrior Guide to Web Design Technologies
1 IMAGES: A Picture Is Worth a Thousands Words, Image Formats Choosing an Image Format Image Sizes Bits Per Pixel Graphic Tips Image Tag Attributes Line.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
HTML Comprehensive Concepts and Techniques Second Edition Project 8 Integrating JavaScript with HTML.
Create slices and hotspots Create links in Web pages Create rollovers from slices Create basic animation Add tweening symbol instances to create animation.
Javascript Document Object Model. How to use JavaScript  JavaScript can be embedded into your html pages in a couple of ways  in elements in both and.
1 IMAGES: A Picture Is Worth a Thousands Words, Image Formats Image Sizes Graphic Tips Image Tag Attributes Centering Images.
CIS101 Introduction to Computing Week 10 Spring 2004.
CIS101 Introduction to Computing Week 10. Agenda Your questions Final exam and final project CIS101 Student Survey Class presentations: Your Mad Libs.
1 CS101 Introduction to Computing Lecture 44 Programming Methodology (Web Development Lecture 15)
Chapter 4 Adding Images. Inserting and Aligning Images Using CSS When you choose graphics to add to a web page, it’s important to use graphic files in.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Chapter 7: Dynamic HTML and Animation JavaScript - Introductory.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
1 CS101 Introduction to Computing Lecture 38 String Manipulations (Web Development Lecture 13)
1 CS101 Introduction to Computing Lecture 35 Mathematical Methods (Web Development Lecture 12)
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
Tutorial 14 Working with Forms and Regular Expressions.
Scripting Languages.
1 CS101 Introduction to Computing Lecture 18 Objects, Properties, Methods (Web Development Lecture 6)
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
String Object.  Conundrum: I would like people to have more time on the revisions…  … but I don't have a lot of time myself for more grading  A1 Revision.
Introduction to Applets CS 3505 Client Side Scripting with applets.
JavaScript, Fourth Edition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
1 Creating Links within a Web Page  These links are especially useful on long Web pages  Links at the top of the page point to areas further down the.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Modified from Moseley ’s sli desWeb Applications Development. Lecture 3 Slide 1 Lecture 3: Dynamic Web Pages – Introduction to JavaScript Instructor: Dr.
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
XP Tutorial 8 Adding Interactivity with ActionScript.
Internet & World Wide Web How to Program, 5/e. 2.
Introduction to JavaScript Objects, Properties, Methods.
Project Two Adding Web Pages, Links, and Images Define and set a home page Add pages to a Web site Describe Dreamweaver's image accessibility features.
Introduction to HTML. _______________________________________________________________________________________________________________ 2 Outline Key issues.
1 Start TextEdit. 2 Creating a Home Page  A home page is the main page of a Web site –Visitors usually view the home page first –Identify the purpose.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Tutorial 11 1 JavaScript Operators and Expressions.
Java Script This is a first JavaScript example. This is a first JavaScript example.
CIS 228 The Internet 11/17/11 Of Timers and Cookies.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
The Web Wizard’s Guide To JavaScript Chapter 4 Image Swapping.
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
Chapter 4 Java Script – Part2. 2 Location object Properties Properties href – whole path will be displayed. ex: window.location.href ( see example 11)
© 2007 D. J. ForemanJS-m1 String, Math & Miscellaneous Methods & Properties.
Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.
JavaScript: Functions
14 A Brief Look at JavaScript and jQuery.
String, Math & Miscellaneous Methods & Properties
PHP.
The Web Wizard’s Guide To JavaScript
Graphics Considerations
JavaScript CS 4640 Programming Languages for Web Applications
JavaScript: Objects.
Web Programming and Design
String, Math & Miscellaneous Methods & Properties
Web Programming and Design
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

1 CS101 Introduction to Computing Lecture 41 Images & Animation (Web Development Lecture 14)

2 During the last lecture we discussed String Manipulation We became familiar with methods used for manipulating strings We became able to solve simple problems involving strings

3 String Manipulation in JavaScript In addition to the concatenation operator (+) JavaScript supports several advanced string operations as well Notationaly, these functions are accessed by referring to various methods of the String object Moreover, this object also contains the ‘length’ property

4 String Methods FORMAT string.methodName( ) EXAMPLE: name = “Bhola” ; document.write( name.toUpperCase( ) ) ; document.write( name.bold( ) ) ; BHOLABhola

5 Two Types of String Methods 1.HTML Shortcuts 2.All Others

6 String Methods: HTML Shortcuts bold( ) italics( ) strike( ) sub( ) sup( ) big( ) small( ) fontsize( n ) fixed( ) fontcolor( color ) link( URL )

7 String Methods: All Others split( delimiter ) toLowerCase( ) toUpperCase( ) charAt( n ) substring( n, m ) indexOf( substring, n ) lastIndexOf( substring, n )

8 Automatic Conversion to Strings Whenever a non-string is used where JavaScript is expecting a string, it converts that non-string into a string Example: –The document.write( ) method expects a string (or several strings, separated by commas) as its argument –When a number or a Boolean is passed as an argument to this method, JavaScript automatically converts it into a string before writing it onto the document

9 The ‘+’ Operator When ‘+’ is used with numeric operands, it adds them When it is used with string operands, it concatenates them When one operand is a string, and the other is not, the non-string will first be converted to a string and then the two strings will be concatenated

10 Strings In Mathematical Expressions When a string is used in a mathematical context, if appropriate, JavaScript first converts it into a number. Otherwise, a “NaN” is the result document.write( "2" * Math.PI ) ; document.write( "Yes" ^ 43 ) ; NaN

11 The ‘toString’ Method Explicit conversion to a string EXAMPLE: Convert into a currency format a = ; b = a.toString( ) ; decimalPos = b.indexOf( ".", 0 ) ; c = b.substring( 0, decimalPos + 3 ) ; document.write( c ) ;

12 Conversion from Strings parseInt( ) and parseFloat( ) methods

13 Today’s Goal (Images & Animation) To become able to add and manipulate images and simple animations to a Web page

14 Images in HTML It is quite straight forward to include gif and jpg images in an html Web page using the tag Format: <IMG src=URL, alt=text height=pixels width=pixels align="bottom|middle|top"> Plea: Don’t use images just for the sake of it!

15

16 Image Demo Image Demo Here is an image Here is another

17 Images in JavaScript Images in JavaScript can be manipulated in many ways using the built-in object Image Properties: name, border, complete, height, width, hspace, vspace, lowsrc, src Methods: None Event handlers: onAbort, onError, onLoad, etc.

18 Image Preloading The primary use for an Image object is to download an image into the cache before it is actually needed for display This technique can be used to create smooth animations or to display one of several images based on the requirement

19 The Image Pre-Loading Process 1.An instance of the Image object is created using the new keyword 2.The src property of this instance is set equal to the filename of the image to be pre-loaded 3.That step starts the down-loading of the image into the cache without actually displaying it 4.When a pre-loaded image is required to be displayed, the src property of the displayed image is set to the src property of the pre- fetched image

20 Let us revisit an example that we first saw in lecture 35

21 * *

22

23 die1.gifdie2.gifdie3.gif die4.gifdie5.gifdie6.gif

24 Roll the Die JavaScript Code HTML Code

25 <INPUT type="button" value="Roll the Die" onClick="rollDie( )">

26 dieImg = new Array( 7 ) ; for( k = 1; k < 7; k = k + 1 ) { //Preload images dieImg[ k ] = new Image( ) ; dieImg[ k ].src = "die" + k + ".gif" ; } function rollDie( ) { dieN = Math.ceil( 6 * Math.random( ) ) ; document.die.src = dieImg[ dieN ].src ; }

27 Another Example Develop a Web page that displays six thumbnail images and a main image The main image should change to a larger version of the thumbnail as soon as the mouse moves over on a thumbnail image

28

29 Image Selector JavaScript Code HTML Code

30 dieImg = new Array( 7 ) ; for( k = 1; k < 7; k = k + 1 ) { // Preload images dieImg[ k ] = new Image( ) ; dieImg[ k ].src = "die" + k + ".gif" ; }

31 <IMG src="die1.gif" width="63" height="63" onMouseOver= "document.big.src=dieImg[ 1 ].src"> … <IMG src="die6.gif" width="63" height="63" onMouseOver= "document.big.src=dieImg[ 6 ].src">

32 Where Else Can We Use This? Automobile Web site ???

33 Animation Example 1 Take 16 images and cycle through them to create an animation effect

35

36 Animation 1 JavaScript Code HTML Code

37 setTimeout( ) executes circulate( ) once after a delay of gap milliseconds

38 gap = 100 ; imageN = 1 ; circImg = new Array( 17 ) ; for( k = 1; k < 17; k = k + 1 ) { // Preload images circImg[ k ] = new Image( ) ; circImg[ k ].src = "circle" + k + ".gif" ; }

39 function circulate( ) { document.circle.src = circImg[ imageN ].src ; imageN = imageN + 1 ; if( imageN > 16 ) imageN = 1 ; }

40

41 Animated Gifs We could have saved the 16 gif images of the previous example in a single file in the form of an animated gif, and then used it in a regular tag to display a moving image However, JavaScript provides better control over the sequencing and the gap between the individual images

42 Animation Example 2 Take 16 images and cycle through them to create an animation effect Provide buttons to slow down or speed up the animation

43

44 Animation 2 JavaScript Code HTML Code

45 <INPUT type="button" value="Slow Down" onClick="slowDown( )"> <INPUT type="button" value="Speed Up" onClick="speedUp( )">

46 gap = 100 ; imageN = 1 ; circImg = new Array( 17 ) ; for( k = 1; k < 17; k = k + 1 ) { // Preload images circImg[ k ] = new Image( ) ; circImg[ k ].src = "circle" + k + ".gif" ; } No change

47 function circulate( ) { document.circle.src = circImg[ imageN ].src ; imageN = imageN + 1 ; if( imageN > 16 ) imageN = 1 ; } No change

48 function slowDown( ) { gap = gap + 20 ; if( gap > 4000 ) gap = 4000 ; } function speedUp( ) { gap = gap - 20 ; if( gap < 0 ) gap = 0 ; } Two new functions

49

50 Flash Animation Designed for 2-D animations, but can be used for storing static vector-images as well A special program (called a plug-in) is required to view Flash files in a Web browser Can be used to design complete, animated Web sites with hardly any HTML in it Binary-file storage

51 Structured Vector Graphics New format; may become more popular than Flash Plug-in required Text-file storage; search engine friendly

52 During Today’s Lecture … We became able to add and manipulate images and simple animations to a Web page

53 Our 15 th & Final Web Dev Lecture: ( Programming Methodology) To understand effective programming practices that result in the development of correct programs with minimum effort To become familiar with simple debugging techniques