CHAPTER 22 ADVANCED CANVAS PROGRAMMING. LEARNING OBJECTIVES How the HTML 5 canvas supports linear and radial gradients How to fill a shape with a pattern.

Slides:



Advertisements
Similar presentations
Lecture # 11 JavaScript Graphics. Scalable Vector Graphics (SVG) Scalable Vector Graphics (SVG), as the name implies, are - scalable (without pixelation):
Advertisements

Using Bitmap graphics Having looked at vector graphics in the canvas, we will now look at using bitmap graphics.
Advanced #1. 그림자 스타일 window.onload = function(){ var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.rect(188,
Neal Stublen Why Use a Canvas?  Flexibility… Use of drawing primitives (lines, arcs, text) Direct access to element display pixels.
Programming Club IIT Kanpur
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
CANVAS Fundamentals. What is Canvas? Canvas is a medium for oil painting. One of the earliest oils on canvas is a French Madonna from Canvas is.
CS4506. HTML5 The HTML5 specification was developed by the Web Hypertext Application Technology Working Group (WHATWG), which was founded in 2004 by was.
Chapter 6 Color Image Processing Chapter 6 Color Image Processing.
CHAPTER 21 INTRODUCING THE HTML 5 CANVAS. LEARNING OBJECTIVES How to create a canvas using the and tag pair How to test if a browser supports canvas operations.
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
Web Programming Language Week 13 Ken Cosh HTML 5.
CS7026 – HTML5 Canvas. What is the element 2  HTML5 defines the element as “a resolution-dependent bitmap canvas which can be used for rendering graphs,
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
Warm Up Problem of the Day Lesson Presentation Lesson Quizzes.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Excel 2007 Comprehensive.
Tutorial 6 Working with Bitmaps and Gradients, and Publishing Flash Files.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
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.
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
Canvas academy.zariba.com 1. Lecture Content 1.What is Canvas? 2.Including Canvas in your HTML 3.Commands in Canvas 4.Drawing Shapes with Canvas 5.Animations.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
Repeating Figures and Symmetries How can tessellations be made with repeating figures? What four types of symmetry do you look for in repeating figures?
Code for touch, get mouse and pen for free Pointer API captures pen motion, passing coordinates to Ink API Ink API helps render and stores motion.
Macromedia Studio 8 Step-by-Step MACROMEDIA FIREWORKS 8 Project 2: Experience Bank Logo.
Chapter 9 Fireworks: Part I The Web Warrior Guide to Web Design Technologies.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Creating Graphics for the Web Learning & Development Team Telerik Software Academy.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Intro to the Canvas Canvas is an HTML5 element If you see this, your browser doesn't support the canvas Canvas is manipulated with javascript c = document.getElementById("mycanvas");
CISC 110 Day 3 Introduction to Computer Graphics.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
Managing the Graphical Interface by Using CSS Lesson 7.
Vocabulary Similarity transformations Congruence transformations.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Nicola Gardiner © 2005 What is a pattern? Teachnet 2005.
08 – Canvas(2) Informatics Department Parahyangan Catholic University.
Can SAS Do Canvas? Creating Graphs Using HTML 5 Canvas Elements Edwin J. van Stein Astellas Pharma Global Development.
07 – HTML5 Canvas (1) Informatics Department Parahyangan Catholic University.
Desktop Publishing Lesson 5 — Enhancing Publications.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
Drawing with the HTML5 Canvas
CHAP 2. CANVAS API.  Dynamically generate and render graphics, charts, images and animations  SVG (Scalable Vector Graphics) vs. Canvas  Bitmap canvas.
Internet of the Past.
CMPE 280 Web UI Design and Development September 12 Class Meeting
Canvas Notes
Web Programming Language
ISC440: Web Programming II Ch14: HTML5 Canvas
The Canvas.
Translations Rotations Reflections Compositions 1 pt 1 pt 1 pt 1 pt
Geometric Transformations for Computer Graphics
Progress <progress value="22" max="100"></progress>
Working with Text and Gradients
Drawing Graphics in JavaScript
Simple Canvas Example Your browser doesn’t support canvases var canvas = document.getElementById("canvas1"); var context.
CSc 337 Lecture 21: Canvas.
Rotation: all points in the original figure rotate, or turn, an identical number of degrees around a fixed point.
These are flips, slides, turns, and enlargements/reductions.
Color Image Processing
Graphics Canvas.
CSc 337 Lecture 20: Canvas.
How can you tell if an object is reflected?
Warm Up Problem of the Day Lesson Presentation Lesson Quizzes.
Dr. Jim Rowan ITEC 2110 Vector Graphics II
CSc 337 Lecture 19: Canvas.
HTML5 – A few features L. Grewe.
Presentation transcript:

CHAPTER 22 ADVANCED CANVAS PROGRAMMING

LEARNING OBJECTIVES How the HTML 5 canvas supports linear and radial gradients How to fill a shape with a pattern using an image How to repeat or appear to move an image across the canvas using image translation How to rotate the canvas x and y axis coordinates using image rotation How the canvas provides functions that developers can use to directly access the pixels that comprise an image

SIMPLE SHAPES AND FILLS function FillShapes() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.beginPath(); context.fillStyle = '#00FF00' context.fillRect(100, 50, 100, 100); context.stroke(); context.fillStyle = '#FF0000'; context.fillRect(300, 50, 50, 100); context.stroke(); context.fillStyle = '#0000FF'; context.moveTo(550, 100); context.arc(500,100,50,0,2*Math.PI); context.fill(); context.stroke(); }

LINEAR GRADIENTS function FillShapes() { var canvas, context, gradient; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.beginPath(); gradient = context.createLinearGradient(100,50,200,50); gradient.addColorStop(0,"red"); gradient.addColorStop(1,"white"); context.fillStyle = gradient; context.fillRect(100, 50, 100, 100); context.stroke(); gradient = context.createLinearGradient(300,50,300,150); gradient.addColorStop(0,"blue"); gradient.addColorStop(1,"green"); context.fillStyle = gradient; context.fillRect(300, 50, 50, 100); context.stroke(); gradient = context.createLinearGradient(500,50,500,150); gradient.addColorStop(0,"yellow"); gradient.addColorStop(1,"orange"); context.fillStyle = gradient; context.moveTo(550, 100); context.arc(500,100,50,0,2*Math.PI); context.fill(); context.stroke(); }

RADIAL GRADIENTS function FillShapes() { var canvas, context, gradient; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.beginPath(); gradient = context.createRadialGradient(100,50,100,150,100,25); gradient.addColorStop(0,"red"); gradient.addColorStop(1,"green"); context.fillStyle = gradient; context.fillRect(100, 50, 100, 100); context.stroke(); gradient = context.createRadialGradient(300,50,50,350,150,50); gradient.addColorStop(0,"yellow"); gradient.addColorStop(1,"blue"); context.fillStyle = gradient; context.fillRect(300, 50, 50, 100); context.stroke(); gradient = context.createRadialGradient(500,50,50,500,150,25); gradient.addColorStop(0,"yellow"); gradient.addColorStop(1,"orange"); context.fillStyle = gradient; context.moveTo(550, 100); context.arc(500,100,50,0,2*Math.PI); context.fill(); context.stroke(); }

USING A FILL PATTERN function FillShapes() { var canvas, context, image, pattern; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.beginPath(); image = document.getElementById("dog"); pattern = context.createPattern(image,"repeat"); context.fillStyle = pattern; context.fillRect(100, 50, 100, 100); context.stroke(); image = document.getElementById("cat"); pattern = context.createPattern(image,"repeat"); context.fillStyle = pattern; context.fillRect(300, 50, 50, 100); context.stroke(); image = document.getElementById("wine"); pattern = context.createPattern(image,"repeat"); context.fillStyle = pattern; context.moveTo(550, 100); context.arc(500,100,50,0,2*Math.PI); context.fill(); context.stroke(); }

DROP SHADOWS function FillShapes() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.shadowColor = 'black'; context.shadowOffsetX = 10; context.shadowOffsetY = 10; context.shadowBlur = 10; context.fillStyle = '#00FF00'; context.fillRect(100, 50, 100, 100); context.fillStyle = '#FF0000'; context.fillRect(300, 50, 50, 100); context.stroke(); context.fillStyle = '#0000FF'; context.moveTo(550, 100); context.arc(500,100,50,0,2*Math.PI); context.fill(); context.stroke(); }

REPEATING AN IMAGE ON THE CANVAS function FillShapes() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.fillStyle = '#00FF00'; for (i = 0; i

MOVING AN IMAGE ACROSS THE CANVAS vari = 0; function FillShapes() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.fillStyle = '#FF0000'; if (i

ROTATING THE CANVAS function RotateSquare() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.fillStyle = '#FF0000'; context.translate(75, 50); context.rotate(Math.PI/180*45); context.fillRect(100, 0, 100, 100); }

TUMBLING AN IMAGE ACROSS THE CANVAS vari = 0; var Degree = 0; function FillShapes() { var canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.save(); context.fillStyle = '#FF0000'; if (i

MANIPULATING PIXEL DATA function GetImageData() { varImageData, canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.fillStyle='#ff0000'; context.fillRect(10,10,50,50); ImageData = context.getImageData(10, 10, 50, 50); context.putImageData(ImageData, 200, 200); }

CHANGING AN IMAGE’S COLOR VALUES function GetImageData() { var ImageData, canvas, context; canvas = document.getElementById('myCanvas'); context = canvas.getContext('2d'); context.fillStyle='#ff0000'; context.fillRect(10,10,50,50); ImageData = context.getImageData(10, 10, 50, 50); var imageData = ImageData.data; var i ; for (i = 0; i

REAL WORLD: 3D WITH WEBGL

SUMMARY This chapter examined more advanced graphics programming capabilities, such as drop shadows, gradients, image rotation and translation, and direct access of an image’s pixel data. Using the concepts this chapter presents, you can animate the display of a wide range of images.