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");

Slides:



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

HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
CHAPTER 20 CREATING SVG GRAPHICS. LEARNING OBJECTIVES How to embed a graphic stored within a.SVG file in an HTML page How to use the and tag pair to specify.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Lecture # 11 JavaScript Graphics. Scalable Vector Graphics (SVG) Scalable Vector Graphics (SVG), as the name implies, are - scalable (without pixelation):
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.
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.
Programming games More drawing. Text. Radian measure. Faces. Homework: Do your own drawings. Create index.html file. Upload work.
Chapter 7 Creating Graphics. Chapter Objectives Use the Pen tool Reshape frames and apply stroke effects Work with polygons and compound paths Work with.
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.
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,
IT Engineering I Instructor: Rezvan Shiravi
INT222 – Internet Fundamentals Weekly Notes: AJAX and Canvas 1.
Programming games Recap. Upload work (Filezilla, index.html). Drawing lines. Drawing stars. Homework: Drawing exercises.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Patrick Chanezon (slides from Matthew Papakipos) June Google’s HTML5 Work: What’s Next?
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.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
Chapter 9 Fireworks: Part I The Web Warrior Guide to Web Design Technologies.
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.
© 2010 Delmar, Cengage Learning Chapter 7 Creating Graphics.
Attributes of drawing elements
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.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Adobe Illustrator Basics Chris Maxwell FIT 1012 September
School of Computing and Information Systems RIA Animation, part I.
Presented By Nanda Kumar(972789) P. Trinesh (982816) Sk. Salma (982824) K. Madhuri (982814) HTML5.
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.
HTML 5 (Part 1) – Start from SCRATCH. HTML 5 – Start from SCRATCH.
Martin Kruliš by Martin Kruliš (v1.1)1.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
AN ILLUSTRATION DRAWING AND COMPOSING Adobe Illustrator CS Design Professional.
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.
Game Development with JS and Canvas 2D
12 Graphics and Java 2D™.
What is a Function Expression?
CMPE 280 Web UI Design and Development September 12 Class Meeting
Canvas Notes
Web Programming Language
UNIT 5 HTML 5.
CMPE 280 Web UI Design and Development February 20 Class Meeting
ISC440: Web Programming II Ch14: HTML5 Canvas
Patrick Dengler Senior Program Manager Microsoft Corporation
Graphics in Android Fall 2012 CS2302: Programming Principles.
Drawing Graphics in JavaScript
CSc 337 Lecture 21: Canvas.
Graphics Canvas.
CSc 337 Lecture 20: Canvas.
JavaScript – Let’s Draw!
CSc 337 Lecture 19: Canvas.
Presentation transcript:

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"); c.width = screen.width - 100; c.height = screen.height - 100; Drawing is done in a 2D context ctx = c.getContext("2d");

Drawing Shapes Drawing is done by calling methods of the 2D context ctx.drawmethod(arguments); Drawing rectangles fillRect(x, y, width, height) strokeRect(x, y, width, height) clearRect(x, y, width, height) Drawing paths beginPath() closePath() // connects last point to first stroke() fill() // closes then fills the shape

Drawing Paths moveTo lifts the pen and moves it, without drawing anything moveTo(x, y) Drawing lines & polygons lineTo(x, y) Drawing arcs arc(x, y, radius, startAngle, endAngle, ccw) Drawing curves quadraticCurveTo(cp1x, cp1y, x, y) bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)

Canvas Colors Current drawing colors, gradients, and patterns are properties of the 2D context –fillStyle –strokeStyle Color strings –Named colors ("magenta") –Hexadecimal values("#ff00ff") –RGB & RGBA ("rgba(255,0,255,1)") Constant alpha can be set for all drawing globalAlpha

Lines & Shadows Current line styles are properties of the 2D context –lineWidth – value, in pixels –lineCap – "butt", "round", or "square" –lineJoin – "bevel", "round", or "miter" –miterLimit – value, in pixels Shadows involve 4 properties of the 2D context –shadowOffsetX – value, in pixels –shadowOffsetY – value, in pixels –shadowBlur – value, in pixels –shadowColor – color string

Drawing Images Place a copy at (x,y) drawImage(image, x, y) Place a copy, scaled to fit (width, height) drawImage(image, x, y, width, height) Fit part of source image into destination drawImage(image, sx, sy, swidth, sheight, dx, dy, dwidth, dheight) Put canvas image at (x, y) putImageData(image, x1, y1)

Image Types 3 types of CanvasImageSource can be drawn: HTMLImageElement – uses an image created elsewhere var img = new Image(); img.onload = function(){ /* use it */ }; img.src = imagefile; HTMLVideoElement – can be used to dynamically update the canvas HTMLCanvasElement – for image processing

Using the Canvas Element Create a new, blank ImageData object var idata = ctx.createImageData(width, height); var idata = ctx.createImageData(image); The data is an array of RGBA values idata.data[0] idata.data[3] Can put (and get) the resulting image ctx.putImageData(idata, x1, y1); var idata = ctx.getImageData(x1, y1, width, height);

Gradient & Pattern Objects Specifying the gradient createLinearGradient(x1, y1, x2, y2) createRadialGradient(x1, y1, r1, x2, y2, r2) Specifying color stops addColorStop(position, color) –position ranges from –color is any color string Specifying a pattern createPattern(image, type) –Image can be any CanvasImageSource –type is repeat, repeat-x, repeat-y or no-repeat