CSc 337 Lecture 19: Canvas.

Slides:



Advertisements
Similar presentations
Working with Tables for Page Design – Lesson 41 Working with Tables for Page Design Lesson 4.
Advertisements

HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
Introduction to Programming
Cascading Style Sheets. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style to HTML elements. CSS is a.
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
Neal Stublen Why Use a Canvas?  Flexibility… Use of drawing primitives (lines, arcs, text) Direct access to element display pixels.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
1 CS428 Web Engineering Lecture 10 Images, Tables, Forms, Border-Radius (CSS – V)
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.
Web Programming Language Week 13 Ken Cosh HTML 5.
 A tool that allows you to select through a free hand method › Unlike the marquee which defines the shape of your selection.
HTML, HTML5 Canvas, JavaScript PART 3 LOOKING MORE CLOSELY AT FULL BLOWN GAME DESIGN A PATTERNED BACKGROUND (CREATED WTIH LOOPS) WITH A MOVING OBJECT CHALLENGES.
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.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Log In to your User Start: Photoshop Elements. Start a new document 700x120 pixels with white background. Create a new layer by clicking Layer -> New.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
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.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Pemrograman Berbasis Web
Lab 5: More on Events and Introduction to the Canvas Tag User Interface Lab: GUI Lab Sep. 23 rd, 2013.
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.
Here is a small example of the puzzle you will be completing today. You will start in the top left corner, and end at the bottom right using 3 different.
INTRO to PIXLR.com.
What is a Function Expression?
Internet of the Past.
Controlling Backgrounds
CMPE 280 Web UI Design and Development September 12 Class Meeting
Inserting and Working with Images
Tutorial 4 Topic: CSS 3.0 Li Xu
Canvas Notes
Advanced CSS BIS1523 – Lecture 20.
Tools & Safety Three Stacked Videos (Advanced) How to use:
Web Programming Language
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Physics Careers February1st, 2017
به نام مهربانترین In the name of the most compassionate
Animated picture changes during motion path (Advanced)
ISC440: Web Programming II Ch14: HTML5 Canvas
بسم الله الرحمن الرحیم مركز بهمن استاندارد- مديريت ارزيابي و مانيتورينگ كيفي.
Order of Operations Problems
The Canvas.
Farming: An example of a system
TAB ONE TAB TWO TAB THREE TAB FOUR TAB FIVE
Order of Operations Problems
Les Verbes ER LCHS NOW SHOWING Marquee with 3-D perspective rotation
موضوع بحث: تعریف علم اصول جلسه 43.
اشاره به نتایج قیاس های فقهی گاهی، حکم شرعی است
علم اصول، «نفس قواعد» است نه «علم به قواعد»
گزارش فعالیت سه ماهه دبستان ابن سینا
Photoshop Bell Work Hand Tool: The hand tool moves an image within its window Zoom Tool: The Zoom Tool magnifies and reduces the view of an image. CTRL.
Pictures in 3-D flip book (Intermediate)
Drawing Graphics in JavaScript
CSc 337 Lecture 21: Canvas.
Start: Photoshop Elements
CSc 337 Lecture 20: Canvas.
ONE NIGHT ONLY! CJMS Talent Show Friday, December 11
spotLIGHT TEXT Ppt宝藏 提供下载 (Intermediate)
قاعده لا ضرر، تنها در شبهات حکمیه جاری است
Spell your name using word art from above
Please Do Now / Dec. 2, 15 Log into computer Go to
جلسه 34.
JavaScript – Let’s Draw!
1 ج : اشاره بعضی از اصولیون به تعریف ترکیبی آخوند با «یک لفظ»
Presentation transcript:

CSc 337 Lecture 19: Canvas

Canvas and Events You can attach an event listener to a canvas just like you can anything else Activity: Make a line of 10 circles follow your mouse when it moves over a canvas

Moving the Canvas What happens if the canvas isn't in the upper left hand corner of the page?

Incorrect clientX and clientY solution You can get the location of the canvas using the following code: let rect = canvas.getBoundingClientRect(); This contains data about the left and top. You can find the actual location of the mouse using the following: X position: event.clientX - rect.left Y position: event.clientY - rect.top

Other Canvas Context Methods Full list: https://www.w3schools.com/tags/ref_canvas.asp moveTo(x, y) Moves the path to the specified point in the canvas, without creating a line lineTo(x, y) Adds a new point and creates a line to that point from the last specified point in the canvas

Drawing a line with the mouse How can you draw a line with the mouse? Where should you begin the path? context.beginPath(); context.lineTo(x, y); context.stroke()

Activity: Drawing a line Create a web page that draws a line under the mouse as it moves across the canvas.

Gradients All called on the context. createLinearGradient() Creates a linear gradient (to use on canvas content) createPattern() Repeats a specified element in the specified direction createRadialGradient() Creates a radial/circular gradient (to use on canvas content) addColorStop() Specifies the colors and stop positions in a gradient object All called on the context.

Linear Gradient Linear gradient takes 4 parameters: start x, start y, stop x, stop y Example: let context = canvas.getContext("2d"); let gradient = context.createLinearGradient(0, 0, 100, 0);

Linear Gradient Add colors to the gradient using addColorStop. Code to create a black -> white gradient: var gradient = context.createLinearGradient(0,0,170,0); gradient.addColorStop(0, "black"); gradient.addColorStop(1, "white"); context.fillStyle = gradient; context.fillRect(20,20,150,100); Note that you must set the fillStyle to the gradient you created and actually draw the shape with it.

Activity: create a gradient Create a horizontal gradient that goes from red to green to blue. Create a vertical gradient over the top of it that goes from 0 opacity to black total opacity.

Getting a canvas pixel You can get the value of pixels on a canvas using getImageData. It takes an x location, a y location, a width and a height as parameters. let context = canvas.getContext("2d"); let data = context.getImageData(50, 50, 1, 1); console.log("red: " + data.data[0] + "green: " + data.data[1] + "blue: " + data.data[2]);

Activity Get the color of your canvas (the one that you drew a gradient on) when the user clicks on it. Turn the background of your page that color.