Martin Kruliš 9. 5. 2016 by Martin Kruliš (v1.1)1.

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.
Introduction to HTML5 Programming donghao. HTML5 is the New HTML Standard New Elements, Attributes. Full CSS3 Support Video and Audio 2D/3D Graphics Local.
Graphics Pipeline.
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.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Bartosz Kowalski Software Developer CERN. Presentation outline -HTML : introduction and history -HTML5 : -History and philosophy -New features -Structure.
Macromedia Dreamweaver 4 Advanced Level Course. Add Rollovers Rollovers or mouseovers are possibly the most popular effects used in designing Web pages.
Tutorial 7 Working with Multimedia. XP Objectives Explore various multimedia applications on the Web Learn about sound file formats and properties Embed.
Canvas, SVG, Workers Doncho Minkov Telerik Corporation
© 2011 Delmar, Cengage Learning Chapter 11 Adding Media and Interactivity with Flash and Spry.
Gil Megidish And I love writing / rewriting / reverse engineering games.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
IT Engineering I Instructor: Rezvan Shiravi
Evaluation of HTML5 Graphics for Data Structure Visualization
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
IE11 Preview is here! Briefing prepared for the IE MVPs and IE userAgents communities.
SVG: The Past, Present and Future of Vector Graphics for the Web Patrick Dengler Senior Program Manager, Internet Explorer Team Member, W3C SVG Working.
Building Windows 8 Apps with HTML & JavaScript Jaime Rodriguez Principal
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
Building the User Interface by Using HTML5: Text, Graphics, and Media Lesson 2.
Tutorial 7 Working with Multimedia. XP Objectives Explore various multimedia applications on the Web Learn about sound file formats and properties Embed.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Your Metro style app, video and audio, Part 1
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Tutorial 7 Working with Multimedia. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Explore various multimedia applications.
Tutorial 7 Working with Multimedia. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Explore various multimedia applications.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Creating User Interfaces Recap HTML/HTML5 JavaScript features Homework: keep working on user observation studies. Review JavaScript.
CSS 2D Transforms CSS 3D Transforms CSS Animations CSS Backgrounds & Borders CSS Color CSS Flexbox CSS Fonts CSS Grid CSS Hyphenation CSS Image Values.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Provides a rich set of media features in easy-to-use APIs Allows you to build cutting-edge apps with advanced media functionality taking full advantage.
CS 174: Web Programming October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
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");
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Internet Explorer 10 IE9 hardware-accelerated platform CSS 2D Transforms CSS Backgrounds & Borders CSS Color CSS Fonts CSS Media Queries CSS Namespaces.
Chapter 11 Adding Media and Interactivity. Chapter 11 Lessons Introduction 1.Add and modify Flash objects 2.Add rollover images 3.Add behaviors 4.Add.
School of Computing and Information Systems RIA Animation, part I.
Web Audio API Let your WebGL program dance. Announcement Final project proposal due in one week. Choice of demo date? Plan for the 12/23 class. 2.
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.
What is HTML5? HTML5 will be the new standard for HTML. The previous version of HTML, HTML 4.01, came in The web has changed a lot since then. HTML5.
HTML5 and CSS3 Illustrated Unit F: Inserting and Working with Images.
HTML 5 (Part 1) – Start from SCRATCH. HTML 5 – Start from SCRATCH.
Part – 3 : HTML 5 SVG Tag. † SVG stands for Scalable Vector Graphics. † SVG is used to define vector-based graphics for the Web. † SVG defines the graphics.
4.3. Code animations by using JavaScript Access data access by using JavaScript. Creating Animations, Working with Graphics, and Accessing Data.
What is a Function Expression?
SVG & DOM Manipulation via Javascript
MPEG-4 Binary Information for Scenes (BIFS)
Web Applications and Multimedia
Flash Interface, Commands and Functions
Canvas Notes
Tutorial 7 Working with Multimedia
ISC440: Web Programming II Ch14: HTML5 Canvas
Patrick Dengler Senior Program Manager Microsoft Corporation
.NET and .NET Core 7. XAML Pan Wuming 2017.
Working with Multimedia
Anatomy of HTML5 sites and Metro style apps using HTML5
Drawing Graphics in JavaScript
Creating User Interfaces
JavaScript – Let’s Draw!
Presentation transcript:

Martin Kruliš by Martin Kruliš (v1.1)1

 Images and CSS3 ◦ Wise application of CCS3 can produce unexpected effects, including animations ◦ HTMLImageElement DOM API var img = new Image(); img.src = "image.png"; elem.appendChild(img); ◦ Important properties and events  complete – is image loaded and ready  naturalWidth, naturalHeight – real proportions  onload – event fired when loading completes by Martin Kruliš (v1.1)2 Example 1

 Creating Images from Blob Data var xhr = new XMLHttpRequest(); xhr.open("GET", "picture.jpg", true); xhr.responseType = "arraybuffer"; xhr.onload = function(e) { var abView = new Uint8Array(this.response); var blob = new Blob( [ abView ], { type: "image/jpeg" } ); var urlCreator = window.URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL(blob); var img = new Image(); img.src = imageUrl; parentElem.appendChild(img); }; xhr.send(); by Martin Kruliš (v1.1)3 Create temporary URL, which is valid only within the page

 Creating Animations ◦ Script can request a callback for next animation frame by window.requestAnimationFrame(anim)  Invocation returns request ID (similar to timers)  window.cancelAnimationFrame(id) aborts request ◦ The callback itself can update the page just before the window is re-painted  It gets time argument, which gets current time in miliseconds from window.performance.now()  The callback is invoked only once, but it can register new animation frame request by Martin Kruliš (v1.1)4 Example 2

 HTML Element ◦ Creates embedded screen for video playback Browser does not support HTML5 video.  The controls attribute makes controls visible  If the controls are hidden, the element may be controlled by Javascript by Martin Kruliš (v1.1)5 The same video in different formats

 HTML Element DOM API ◦ Important Methods and Properties  load(), readyState  play(), pause(), paused, ended  duration, currentTime, seekable  volume, muted ◦ Events  loadstart, loadeddata, canplay, canplaythrough  pause, play, playing, progress, stalled  seeking, seeked  volumechange by Martin Kruliš (v1.1)6

 Scalable Vector Graphics ◦ Quite complex vector graphics and animations ◦ HTML5 allows direct embedding of SVG code ◦ The SVG data are visible through DOM API document.getElementById("circle1")… by Martin Kruliš (v1.1)7 Example 3

 The canvas Element ◦ HTML5 element for JS drawing Your browser does not support HTML5 canvas.  Canvas can be sized by CSS, but width and height define the resolution of the viewport  Canvas is cleared when resized ◦ Drawing is performed through context var context = mycanvas.getContext("2d");  Various types of context (for drawing, 3D graphics, …)  Animations use timers or animation frame events by Martin Kruliš (v1.1)8

 2D Context Features ◦ Drawing rectangles  strokeRect(), fillRect(), clearRect() ◦ Drawing paths  beginPath(), closePath()  moveTo(), lineTo()  arc(), quadraticCurveTo(), bezierCurveTo()  stroke(), fill() ◦ Setting drawing styles  strokeStyle, fillStyle, globalAlpha  lineWidth, lineCap, lineJoin by Martin Kruliš (v1.1)9 Example 4

 2D Context Features ◦ Color gradients  createLinearGradient(), createRadialGradient()  gradient.addColorStop()  Can be used in strokeStyle, fillStyle ◦ Patterns var img = new Image(); img.src = "fill-pattern.png"; ctx.strokeStyle = ctx.createPattern(img,"repeat"); ◦ Text rendering  fillText(), strokeText(), font by Martin Kruliš (v1.1)10

 2D Context Features ◦ Transformations  Global transformation matrix for all drawings  translate(), rotate(), scale()  transform(), setTransform() ◦ Compositing  How is new drawing combined with existing drawings  globalCompositeOperation ◦ Clipping paths  Path terminated with clip(), instead of closePath()  All subsequent drawing is clipped accordingly by Martin Kruliš (v1.1)11

 2D Context Features ◦ Context state stack  save(), restore() ◦ Retrieving/drawing image data  ImageData object – raw RGB data in binary form  createImageData()  getImageData(), putImageData() ◦ Saving canvas as image  canvas.toDataURL() ◦ Drawing images/video on canvas  drawImage(imgElem, …) by Martin Kruliš (v1.1)12 Example 4

 KineticJS ◦ The programmer does not draw, but create objects that are automatically rendered  Similar to DOM elements  Supports geometric shapes, images, …  Modifying properties causes automatic repainting ◦ Complex object management  Layers, object groups, … ◦ Events  Extending event model to graphic objects  Drag and drop support by Martin Kruliš (v1.1)13 Example 5

 Web API for OpenGL ◦ A way to render 3D graphic in web browser  Based on OpenGL ES 3.0 specification ◦ canvas element is used as viewport  Using ‘webgl’ context, which provides bindings to OpenGL functions var canvas = document.getElementById('glcanvas'); var gl = canvas.getContext('webgl'); gl.viewport(0, 0, canvas.width, canvas.height); gl.clearColor(0.0, 0.0, 0.0, 1.0); by Martin Kruliš (v1.1)14

 WebGL Context ◦ Data buffers (vertices, colors, …) var buf = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, buf); var v = new Float32Array([ 1.0, -1.0,... ]); gl.bufferData(gl.ARRAY_BUFFER, v, gl.STATIC_DRAW); ◦ Vertex and fragment shaders  May be stored along with HTML page in elem. var shader = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(shader, shaderSourceCode); gl.compileShader(shader); by Martin Kruliš (v1.1)15 Example 6

 Three.js ◦ Lightweight 3D graphic library  Primarily uses webgl, but can fallback to SW rendering ◦ Object based approach  3D entities are JS objects  Camera, lights, scene, …  Hides complexities of 3D math ◦ Additional features  Object materials – different surface effects  Import/export 3D data  … by Martin Kruliš (v1.1)16 Example 7

 HTML Element ◦ Similar to element ◦ Controlled from user panel or from Javascript  Web Audio API ◦ Playback from media files, oscillators, and binary data buffers ◦ Adding audio filters and effects ◦ Related to WebRTC media streams  Recording from microphone  Sending audio to RTC channel by Martin Kruliš (v1.1)17

 Audio Context ◦ A context object must be created first var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); if (!audioCtx)... // no audio ◦ Within the context a pipeline of audio nodes has to be assembled by Martin Kruliš (v1.1)18 Inputs Effects Destination Example 8

 Audio Nodes ◦ Audio Sources  OscillatorNode  AudioBuffer, AudioBufferSourceNode  MediaElementAudioSourceNode – e.g.,  MediaStreamAudioSourceNode – WebRTC media stream ◦ Audio Destinations  AudioDestinationNode  audioCtx.destination – default destination (speakers)  MediaStreamAudioDestinationNode – WebRTC channel by Martin Kruliš (v1.1)19

 Audio Nodes ◦ Effects and Filters  DelayNode  GainNode  … ◦ Other Nodes  AnalysisNode – analysis and visualization  ChannelSplitterNode, ChannelMergerNode  AudioListener – position the sound in space  PannerNode – signal behavior in space by Martin Kruliš (v1.1)20

 Audio Buffer Playback Example var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); var channels = 2, sampleRate = 44100; var nextTime = 0; function enqueueAudioData(dataArrayBuffer) { var data = new Int16Array(dataArrayBuffer); var buf = audioCtx.createBuffer(channels, data.length / channels, sampleRate); //... Copy samples from data to buf... if (nextTime == 0) nextTime = audioCtx.currentTime ; var source = audioCtx.createBufferSource(); source.buffer = buf; source.connect(audioCtx.destination); source.start(nextTime); nextTime += buf.duration; } by Martin Kruliš (v1.1)21 Small constant to prevent data jittering BufferSource wraps the buffer for playback nextTime is used to mark, when the playback starts Puts data from ArrayBuffer to playback queue

by Martin Kruliš (v1.1)22