What is a Function Expression?

Slides:



Advertisements
Similar presentations
Bring Life to Your Web Pages with JavaScript and HTML5 Part 2 Ole Ildsgaard Hougaard -
Advertisements

1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
1 USING FIREWORKS Cropping an Image Obtaining Information Changing Image Size Rotating an Image Adjusting the Color of an Image Drawing Tools Using the.
Using Bitmap graphics Having looked at vector graphics in the canvas, we will now look at using bitmap graphics.
Image Maps and Graphics Internet Basics and Far Beyond! Mrs. Wilson.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Sketchify Tutorial Graphics and Animation in Sketchify sketchify.sf.net Željko Obrenović
Text, Masks, and Live Effects – Lesson 41 Text, Masks, and Live Effects Lesson 4.
DIGITAL GRAPHICS & ANIMATION
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
XP Tutorial 7 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Working with Graphics Tutorial 7.
CSCE Chapter 5 (Links, Images, & Multimedia) CSCE General Applications Programming Benito Mendoza 1 By Benito Mendoza Department.
Chapter 6 Images in Dreamweaver & Fireworks Mrs. Johnson Web Design.
Week 2 - Wednesday CS361.
HTML 5 Tutorial Chapter 5 Canvas. Canvas The tag is used to display graphics. The Canvas is a rectangular area we control each and every pixel of it.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
© 2011 Delmar, Cengage Learning Chapter 1 Getting to Know Illustrator.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Macromedia Studio 8 Step-by-Step MACROMEDIA FIREWORKS 8 Project 2: Experience Bank Logo.
CIS234A- Lecture 7 Instructor Greg D’Andrea. Tables A table can be displayed on a Web page either in a text or graphical format. A text table: – contains.
Object Oriented Programming Dr. Ennis-Cole CECS 5100.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
Adobe Photoshop CS5 – Illustrated Unit A: Getting Started with Photoshop CS5.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
© 2010 Delmar, Cengage Learning Chapter 1 Getting Started with Illustrator.
Computer Graphics Matrices
Understanding JavaScript and Coding Essentials Lesson 8.
Adobe Photoshop CS4 – Illustrated Unit A: Getting Started with Photoshop CS4.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
HTML 5 (Part 1) – Start from SCRATCH. HTML 5 – Start from SCRATCH.
Graphics Basic Concepts 1.  A graphic is an image or visual representation of an object.  A visual representation such as a photo, illustration or diagram.
Photoshop CS6 – Nelson Unit 3: Photoshop CS6. Objectives Define photo editing software Start Photoshop and view the workspace Use the Zoom tool and the.
REEM ALMOTIRI Information Technology Department Majmaah University.
Unit 2.6 Data Representation Lesson 3 ‒ Images
Introducing Macromedia Flash 8
Laying out Elements with CSS
Getting Started with Adobe Photoshop CS6
Internet of the Past.
CSS Layouts: Grouping Elements
Inserting and Working with Images
Adobe Flash Professional CS5 – Illustrated
Starburst.
Advanced CSS BIS1523 – Lecture 20.
Web Development & Design Foundations with HTML5 7th Edition
IMAGES.
Objectives Create a media query Work with the browser viewport
Chapter 5 Working with Images
Objectives Create a reset style sheet Explore page layout designs
Objectives Create a figure box Add a background image
ISC440: Web Programming II Ch14: HTML5 Canvas
The Canvas.
6th Lecture – Rectangles and Regions, and intro to Bitmap Images
Exercise 28 - Skills Vector tools enable you to create perfectly formed shapes and lines of all sorts. What’s more the vector objects keep their shape.
Chapter Lessons Use the Macromedia Flash drawing tools
Tutorial 6 Creating Dynamic Pages
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
Tutorial 3 Working with Cascading Style Sheets
Drawing Graphics in JavaScript
Programming games Share your plans for your virtual something.
PowerPoint Practice Exercise
Web Programming and Design
Web Programming and Design
Web Programming and Design
JavaScript – Let’s Draw!
Presentation transcript:

What is a Function Expression? Functions What is a Function Expression? A Function Expression defines a function as a part of a larger expression syntax (typically a variable assignment )

Example The following example defines an unnamed function and assigns it to x. The function returns the square of its argument: var x = function(y) { return y * y; };

Drawing Lines and Sprites

Info on Lines https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Applying_styles_and_colors

lineWidth example The line width is the thickness of the stroke centered on the given path. In other words, the area that's drawn extends to half the line width on either side of the path. Because canvas coordinates do not directly reference pixels, special care must be taken to obtain crisp horizontal and vertical lines.

Obtaining crisp lines requires understanding how paths are stroked Obtaining crisp lines requires understanding how paths are stroked. In the image below, the grid represents the canvas coordinate grid. The squares between gridlines are actual on-screen pixels. In the grid image below, a rectangle from (2,1) to (5,5) is filled. The entire area between them (light red) falls on pixel boundaries, so the resulting filled rectangle will have crisp edges.

If you consider a path from (3,1) to (3,5) with a line thickness of 1 If you consider a path from (3,1) to (3,5) with a line thickness of 1.0, you end up with the situation below. The actual area to be filled (dark blue) only extends halfway into the pixels on either side of the path. An approximation of this has to be rendered, which means that those pixels being only partially shaded, and results in the entire area (the light blue and dark blue) being filled in with a color only half as dark as the actual stroke color. This is what happens with the 1.0 width line for a stroke.

To fix this, you have to be very precise in your path creation To fix this, you have to be very precise in your path creation. Knowing that a 1.0 width line will extend half a unit to either side of the path, creating the path from (3.5,1) to (3.5,5) results with a 1.0 line width completely and precisely filling a single pixel vertical line.

Example URL function draw() { canvasContext.beginPath(); for (var x = 0.5; x <= canvas.width; x += 25) { canvasContext.moveTo(x, 0); canvasContext.lineTo(x, canvas.height); } for (var y = 0.5; y <= canvas.height; y += 25) { canvasContext.moveTo(0, y); canvasContext.lineTo(canvas.width, y); canvasContext.stroke();

Sprites A sprite is a bitmap graphic that is designed to be part of a larger scene.

Bitmap A bitmap (or raster graphic) is a digital image composed of a matrix of dots. When viewed at 100%, each dot corresponds to an individual pixel on a display. In a standard bitmap image, each dot can be assigned a different color. Together, these dots can be used to represent any type of rectangular picture.

Load the image var balloonSprite = new Image(); balloonSprite.src = "spr_balloon.png"; Example URL

Game.drawImage This is a special function written from the examples in the book. It will call drawImage on the context of the canvas in the HTML code.

Drawing the image canvasContext.drawImage(ballonSprite, 50, 50); This will draw the sprite at the x,y position. You cannot call the drawImage() method before the image has loaded! Animated Example We will learn about detecting the loading of data in another class.

Canvas Transition The translate() method remaps the (0,0) position on the canvas. Note: When you call a method such as fillRect() after translate(), the value is added to the x- and y-coordinate values. save() Saves the state of the current context restore() Returns previously saved path state and attributes

Canvas state isn't what's drawn on it Canvas state isn't what's drawn on it. It's a stack of properties which define the current state of the tools which are used to draw the next thing. The state you save is the state which will dictate what coordinate-orientation, dimension-scale, color, etc, you use to draw the NEXT thing (and all things thereafter, until you change those values by hand).

Translate just adds whatever numbers you put for x and y to the coordinates of your canvas. In this example shifting it to the right and down. If you want to move it left or up, just use negative numbers for x and y.

Canvas Transition – Example URL

drawImage Advanced Example context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); img Specifies the image, canvas, or video element to use   sx Optional. The x coordinate where to start clipping sy Optional. The y coordinate where to start clipping swidth Optional. The width of the clipped image sheight Optional. The height of the clipped image x The x coordinate where to place the image on the canvas y The y coordinate where to place the image on the canvas width Optional. The width of the image to use (stretch or reduce the image) height Optional. The height of the image to use (stretch or reduce the image)

Origin The origin of the image allows you to adjust were to place the image. In both cases they are placed on the Y axis at 150 pixels. However the image on the left has an origin of -34,-34 to the position drawn. The image on the right has an origin of 0,0 (upper left pixel), which is why it is not centered on the line. Examples: Still - Animated

HTML DOM Events HTML DOM events allow JavaScript to register different event handlers on elements in an HTML document. Events are normally used in combination with functions, and the function will not be executed before the event occurs (such as when a user clicks a button). Such as: document.onmousedown = handleMouseDown; More info: https://www.w3schools.com/jsref/dom_obj_event.asp https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent

Move a sprite Sprite at Center of Mouse Position

No Cursor In the CSS: .nocursor { cursor: none; } In the HTML: <div id="gameArea" class="nocursor"> Example

Example drawing a sprite

Debugging console.log F12 NetBeans Debugger

JSON – For later use. http://www.askyb.com/javascript/load-json-file-locally-by-js-without-jquery/ data = '[{"name" : "Harry", "age" : "32"}]'; function load() { var mydata = JSON.parse(data); alert(mydata[0].name); alert(mydata[0].age); }