SlideShare a Scribd company logo
1 of 27
Download to read offline
1
Nico Ludwig (@ersatzteilchen)
(2) GUI – Drawing
2
TOC
● (2) GUI – Drawing
– Vector- and Raster-based Graphics
●
Idea behind Vector- and Raster-based Graphics
● Crispness
●
Overview of Raster-based Drawing APIs
– Platform independent Graphics and GUIs in the Web Browser
●
Bare HTML Pages
● Plugins and Problems
●
From rich Content to HTML 5
– Drawing with HTML 5 Canvas
● Continuous, Event driven and free Drawing
●
Basic Drawing "How does Drawing work with JavaScript?"
●
Interaction with Controls
● Sources:
– http://channel9.msdn.com/Niners/rbarraza
– web.archive.org, Bare_HTML_Page (www.yahoo.com, 1996)
3
Vector and Raster-based Graphics
● We already discussed vector and raster displays, which bring graphics to a screen withdifferent hardware respectively.
● Apart from how graphics are brought to screen by hardware, there are alsodifferent ways to render graphics by software.
– (The term "rendering" is a more general term for "bringing graphics (incl. video) to the screen or to paper".)
● From a software perspective there exist vector-based and raster-based graphics.
4
Raster-based Graphics
● In this lecture we'll only discuss raster-based graphics in depth.
● Graphics that is rendered on a screen, wherebysoftware handles pixels individually, is called raster-based.
– (Raster-based graphics are also called pixel-based graphics.)
● For example Java's "Java 2D" software provides the function setRGB() to set one pixel to a certain value/color:
● Often, only raster-based graphics are associated with the word"drawing".
● Raster-based graphics are also used for photographs.
// Java: Set the pixel at (0; 0) to white color:
image.setRGB(0, 0, Color.WHITE.getRGB());
5
Basics on Raster-based Drawing
● Let's recapitulate, what a picture on a screen is: a big two-dimensional array of pixels, in other words it is a matrix.
– Mind that we already discussed the needed memory depending on spatial dimension and color resolution: a picture is an array!
● To have graphics on the screen we could use functions, which draw pixels of a specific color at specific coordinates, e.g.:
● But there are some problems with this pixel-oriented approach:
– It is relatively hard to use these functions to draw more complicated shapes like circles (e.g. with trigonometric functions).
– Drawing individual pixels would be very inefficient and slow, at least not very interactive.
● Therefor graphics libraries provide special functions to draw graphic primitives (rectangle, ellipse, line, bezier and text):
– This approach is very much faster than pixel-oriented drawing! Often the graphics adapter provides hardware acceleration.
●
I.e. the calculation of coordinates of individual pixels to draw a circle (with trigonometry) can be done on the graphics adapterwithout using the CPU!
●
The term graphics adapter can be reduced to the term Graphics Processing Unit (GPU).
– A set of functions and objects controlling specific aspects on a computer is called Application Programming Interface (API).
●
For operating systems (OS) providing a GUI, it is mandatory to have an API for graphics programming.
// Java: Draw an ellipse of width and height at (0; 0):
graphics.setColor(Color.WHITE);
graphics.drawOval(0, 0, width, height);
// Java: Set the pixel at (0; 0) to white color:
image.setRGB(0, 0, Color.WHITE.getRGB());
● The coordinate system of pixels is a left-handed
system (an example for a right-handed coordinate
system is the cartesian coordinate system)! This
is due to the fact that pictures are drawn row wise
on a CRT.
6
Crispness
● We should have a look at the result of drawing a circle with a raster-based API, we'll continue using Java 2D:
● Welcome the alias-effect: It looks crisp, but...
– …when we zoom the drawn image, the pixels become visible and we see how the circle is plotted by pixels mimicking an arc:
● For raster-based graphics there are two ways to get at least a bit of the crispness back:
– (1) By the application of anti-aliasing, which smoothes a raster-graphics' edges with the background with colored extra pixels.
– (2) By the application of subpixel rendering (e.g. ClearType on Windows).
Zoom ZoomZoom
Zoom ZoomZoom
Subpixel
rendering
// Java: Draw a circle with the diameter 100 at (0; 0):
graphics.setColor(Color.WHITE);
graphics.drawOval(0, 0, 100, 100);
● Aliasing is a term taken from digital signal
processing technologies. Aliasing happens if the
resolution of a raster graphic (read: frequency) is
greater than the resolution of a zoom frame (read:
scan frequency).
● Graphical anti aliasing put a considerable burden
on rendering a graphic. Some tools, e.g.
LibreOffice allow to deactivate anti aliasing.
● Bill Hill invented ClearType at IBM in 1988. The
exploitation of sub pixels lead to having more DPIs,
which lead to nicer text before WPF!
● It should be said that techniques for anti aliasing are
about to get superfluous with 4K (4096 Γ— 2304 or
3840 Γ— 2160) graphics. The pixels are so small that
they are typically no longer individually visible.
7
Excursion – Vector-based Graphics – Part I
● There are problems with raster-based graphics in general:
– When parts of the graphics are zoomed, the crispness of details gets lost. It results in pixilated graphics, not recognizable as detail.
– When the resolution increases, graphics get smaller. When the resolution decreases, graphics get larger.
● Is that a problem? Well, when we have a premium 4K display do we like smaller graphics or crisper graphics?
● These effects emerge because the rendering of raster-based graphics is dependent on the resolution.
– The shown problems are esp. visible on arcs and circles and they are very annoying on text.
increase resolution
8
Excursion – Vector-based Graphics – Part II
● To solve these problems, there needs to be a way to make the rendering of graphics independent from the resolution.
– The logical resolution was made independent from the physical resolution.
● E.g. this idea was put into effect with Microsoft's Windows Presentation Foundation (WPF):
– WPF introduced Device Independent Units (DIUs). DIUs are independent of a device's pixel raster, a DIU is defined as 1/96 of an inch.
● On a device having 96ppi (pixels per inch), 96 pixels would consume 1 inch; on a device having 120ppi, 96DIUs would be represented by 120 pixels...
●
(If logical DIUs do not exactly match to physical pixels WPF will use anti-aliasing.)
● Vector-based graphics are described as formula, which is parameterized by the physical resolution.
– It means that vector-based graphics are not described as an array of pixels!
– Raster-based graphics get smaller with higher resolution and zooming leads to pixelation:
– Vector-based graphics get crisper with higher resolution and zooming, em, just zooms! Vector-based graphics are scalable!
raster-based
zoom
raster-based
zoom
raster-based
zoom
vector-based
zoom
vector-based
zoom
vector-based
zoom
● Scalability can be defined in a very simple way:
Graphics a scalable, if it is parameterized with
physical resolutions (spacial dimension as well as
color resolution).
● Maybe in future we'll have to take more
parameters into consideration: 3D-
depth/resolution, haptic-detail-resolution, etc.
9
Excursion – Vector-based Graphics – Part III
● The application of vector-based graphics allowed the development some very important applications:
– crisp and scalable texts to allow WYSIWYG editing of documents,
– a new category of software for Computer Aided Design (CAD) to construct structures on a computer instead of pencil and paper,
– a new category of software for Desktop Publishing (DTP) to layout high quality documents for printout.
– => Graphics and print results of excellent quality on any scale.
– (Vector-based graphics are not suited for photographs.)
● Besides these applications, which more or less deal with design, also the desktop was influenced meanwhile:
– The scalability and crispness of vector-based graphics was applied to controls, windows and the desktop.
– This was required, because of:
●
(1) the availability of higher and higher physical resolutions (high definition, 4K, 8K) and
● (2) the availability of different screen sizes for the same applications (watch, mp3-player, automotive, mobile, tablet, notebook, PC screen, tv, projector).
– Examples:
● Desktop: WPF, (Graphics Device Interface+ (GDI+)), Quartz, PostScript, Cairo
●
Browser: Silverlight (WPF/E), Scalable Vector Graphics (SVG)
●
Printer: PostScript
● Using the same graphics API for graphics on the
screen as well as for the printer is the basis for
WYSIWYG.
● On OS X the graphics engine "Quartz" is based on
PDF (Portable Document Format) and uses PDF's
features to have resolution independent graphics on
the desktop.
● Virtually OS X uses PostScript and transparent
PNGs and Windows uses a mix of raster- and
vector-base graphics.
● PDF is based on PostScript, but it is structured
like a "real" programming language. There are
also some extra features in PDF like transparent
regions.
● GDI+ is the successor of GDI. It is hardware
accelerated (which was no longer the case for GDI
starting with Windows Vista) and has a couple of
features for using vector-based graphics.
10
Overview of raster-based Drawing APIs
● In this presentation we'll only discuss raster-based drawing in more depth.
● Up to now we used the Java 2D API for the examples, but there exist more APIs:
● Windows
– Graphics Device Interface (GDI)
● Linux
– GTK+ drawing (GTK for GIMP Toolkit; GIMP for GNU Image Manipulation Program; GNU for GNU is not Unix)
● OS X
– Quartz, Cocoa drawing
11
Native and platform independent Drawing APIs
● The drawing APIs we've enumerated are so called native APIs. What does that mean?
– Native APIs are only usable on/compatible with a certain platform. E.g. Windows GDI code won't run on OS X.
– I.e. code written in native APIs is not portable! β†’ Native API vs. platform independent API.
– On the other hand native APIs are fast, because they can exploit the power of the platform, e.g. directly use Windows functions.
● From a 20K miles perspective there are two ways to have platform independent (drawing) APIs:
– Create and establish a common platform.
● Establish and use a common graphics API, which is translated into native graphics API calls at run time.
●
E.g. Java 2D, QT
– Use a present common platform.
●
Find a platform, which is existent on most OS' and implement graphics on that platform.
●
E.g. web browsers
Operation System
Graphics Adapter
Native graphics API
Platform independent graphics API
Application
Operation System
Graphics Adapter
Native graphics API
Browser, interprets HTML
Website
12
Platform independent Graphics in the Web Browser
● The following discussion deals with platform independent graphics via the web browser (browser).
● Browsers are an interesting platform, because they are available on all important operating systems!
● The first approach to put "graphical content" into effect on the browser was bare HTML with forms and controls.
– ~mid 1990s
13
Bare HTML Pages
● Bare HTML pages do of course work very good in a browser, but using them didn't feel like using an application.
– HTML pages basically look like a pages of text containing some links, form elements (controls) and images.
– Using HTML pages is more or less navigation in the browser with links and the browser history.
– HTML pages seem to have no togetherness: somehow the contents of the same web address seem to belong together somehow.
●
In other words: togetherness is primarily defined by how the session with the HTML "site" is defined.
● Yes, it works, but the result is not very appealing. It is just "navigation in the browser".
– When this approach was used, network throughput was low and the performance of clients was not very good.
– On the client the browser just needed to store and render pages. The web server had to handle many requests.
– The approach of bare HTML pages is the basis for the GUI of the internet!
HTML
page 1
the "application"
HTML
page 2
HTML
page 3
HTML page 4
Form
Control 1
Control 2
Image
Link
One page in the browser
browser history
link
link
link
web
server
Client
Server
delivers HTML pages
● We'll not discuss multitiered architectures here. Let's
just assume that we have a web server as well as
clients and no other participants (e.g. database
servers).
● But it should be said that the shown architecture
does somehow resemble the "thin-client-
mainframe" architecture. The thin-client is the
application running in the browser, the mainframe
is the web-server, or whatever servers are behind
the server-border (following the figure on this
slide).
14
Rich content with Plugins
● The next incarnation of "graphical content" in the browser was the usage of additional browser plugins.
– E.g. Java Applets, Adobe Flash, Apple QuickTime etc.
● The idea is to use a special control, which has very rich interactive features:
– The functionality of these controls is provided by plugins, which are installed on the browser's OS.
● Typically the "object"- or "embed"-HTML-element is used.
– With plugins the browser is able to execute mini-applications, often called applets, in instances of plugin controls.
● The browser does indeed start an embedded runtime (e.g. the Java runtime) to execute applets.
– The web server delivers binary components (and HTML pages) that contain the code to be run in the plugin controls.
– (Adobe Flash and Apple QuickTime were the most important plugins in order to play video material in the browser at all!)
HTML page
Plugin
component
One page in the browser
● Before HTML 5 the applet element could be used for
Java applets. This element is no longer supported.
● There also exist so called hybrid Java-applets:
those implement a Java main() method, which
makes them runnable as "ordinary" Java application
on the desktop.
● Some OS' allow applets running, or even web sites,
on the desktop, these mini-applications on the
desktop are sometimes called widgets.
15
Rich content with Plugins
● Browser plugin technologies allowed "web-applications" consisting of only one site without the need for navigation.
– It should be clarified that each type of plugin provides its own event system, apart from the browser's event system.
– Because events are an intrinsic part of genuine GUIs, we can say that a web-application provides a genuine GUI.
– Pages could be designed as a mosaic of plugin controls, such web-applications are called Single Page web-Applications (SPAs).
● A new aspect of SPAs is that no navigation/reloading of sites is needed. Only parts of the sites are reloaded.
● After SPAs with plugins established, another kind of SPAs emerged: those usingAJAX.
– AJAX (Asynchronous JavaScript And XML) uses JavaScript to load content dynamically without plugin components.
● The important point: AJAX allows to load parts of a currently displayed page w/o reloading the whole page!
– The mix of those technologies is sometimes called "Web 2.0" to have a nice marketing term.
– A web-application using Web 2.0 is sometimes called Rich Internet Application (RIA).
● It can be said that the last incarnation of RIAs were sites that consisted of one huge control making up the whole content.
– E.g. JavaFX and Silverlight.
● Yes, this approach also worked and the results were appealing, but there areproblems with the application of plugins!
16
Problems with Browser Plugins
● The problem lies in the place where plugins are executed: in the browser and on the client side.
– Different browsers on different clients may behave differently. This also influences the effort for quality assurance!
– The required runtimes (and correct versions thereof) need to be installed on the client side.
– Because plugin components are loaded from a foreign source and executed on the client side, there is a certain security problem.
●
To shield the client from vicious plugin code, plugin runtimes are executed in a so called sandbox having strong security constraints.
● The problem is that there could be a leak in the sandbox, which still allows vicious plugin code to be executed!
●
=> As a result the execution of plugins is often blocked, and many users don't trust these technologies (esp. Java applets).
– Running plugin code requires a lot of resources: computing time as well as battery lifetime!
● In order to maximize battery lifetime, some browsers
(e.g. Safari) freeze the execution of plugins, so that
the uses must start them manually on the page.
17
The Solution: HTML 5
● However, in the end there are still many problems with GUIs in the browser:
– With bare HTML the interaction is not appealing, e.g. navigation among HTML pages.
– Plugins need a lot of resources: computing time and battery lifetime.
– Plugin runtimes are not necessarily installed and activated on the client-side.
– Plugins provide potential security problems.
● It took years until industry addressed these problems.In the end the answer was "HTML 5", providing important updates:
– (HTML 5 is not strictly the successor of HTML 4, instead it is a set of new features running in the browser.)
– New clever input controls: date pickers, email and web address controls, sliders and spinboxes etc.
– Support for offline web-applications, HTML 5 storage and support for data mapping and annotation with microdata.
– Support for mobile web-applications: geo location APIs.
– Support for playing video material without third party components like Apple QuickTime or Adobe Flash.
– Support for appealing/more desktop-like usage, e.g. with web workers for doing things in the background.
– But, potentially the most powerful new feature is the "canvas"-HTML-element, which we will discuss for the rest of this lecture.
● "canvas" is basically a way to bring interactive graphics into the browser with JavaScript without any plugins.
– Therefor we can now continue our discussion about of how software implements drawing in general...
● Apple's browser Safari 7 addressed the computing
time and battery life problem: the execution of
plugins are paused by default.
● Virtually all these individual HTML 5 features need
to be checked for support in the browser. A browser
may support only a subset of these features;
browser do usually not support "HTML 5"
completely.
● HTML 5 video supports video/mp4, video/webm and
video/ogg following the standard.
18
Excursion: Continuous, Event driven and free Drawing – Part I
● Basically there exist three models for drawing on the computer screen:
– Continuous drawing.
– Event driven drawing.
– Free drawing.
● Continuous drawing:
– The code, which performs the drawing, is executed automatically and continuously at a certain framerate.
● Benefit: the programming of animation and other "vivid" graphics is very simple. It's good for learning graphics basics and simple to use for "sketching".
●
Downside: it needs a lot of resources.
– Example: Processing
● Event driven drawing:
– The code, which performs the drawing is only executed, when specific events are raised (e.g. update, redraw, refresh, resize).
● Benefit: it doesn't need many resources.
● Downside: W/o interaction there is generally no drawing. (To have continuous drawing with an event driven drawing API, we have to fire draw events at a
certain framerate or call the drawing code continuously ourselves.)
– Examples: Cocoa drawing (OS X), GTK, Java 2D, Windows Forms
● There exists Processing.js, which is a continuous
drawing API based on Processing, but being
implemented used the event driven canvas API.
19
Excursion: Continuous, Event driven and free Drawing – Part II
● However, we want to discuss the third approach: free drawing.
● The idea of free drawing is that there is neither a dedicated event that initiates drawing nor any redrawing framerate.
● Free drawing means that any code, which can access the context of the graphics is able to draw!
– The code can draw independently on events as well as independently on a continuous framerate.
– It should be said that this is also possible with, e.g., Windows Forms, but the result might be overdrawn by the draw-event!
● E.g. with HTML 5 canvas each function is able to draw, because the graphical context can be accessed from everywhere.
– Benefits: it is simple to use from scratch.
– Downsides: it can be tricky to migrate code from other drawing approaches.
● Ok, now its time to see free drawing with HTML 5 canvas!
● There exists Processing.js, which is a continuous
drawing API based on Processing, but being
implemented used the event driven canvas API.
20
Let's go and draw!
● We'll begin with a general HTML scaffold to program canvas with these important parts:
– (1) Import the file containing the needed JavaScript code (Canvas.js).
– (2) Bind the HTML page's load event to the JavaScript function draw() (defined in Canvas.js).
– (3) Mark the canvas element in the page's body with the id "myCanvas".
● In the JavaScript file "Canvas.js" we implement the function draw():
– (a) Get the HTML page's canvas element by its id "myCanvas".
– (b) Get the graphical context from the canvas element by calling getContext("2d").
– (c) On the canvas' graphics context draw on the canvas programmatically with special functions (e.g. arc() and fill()).
● As can be seen, the event onload and the canvas object connect the HTML page with the JavaScript code.
<html>
<head>
<script src="Canvas.js"></script> <!--(1)-->
<title>Canvas</title>
</head>
<body onload="draw();"> <!--(2)-->
<canvas id="myCanvas" width="300" height="300"></canvas><!--(3)-->
</body>
</html>
function draw() {
var canvas = document.getElementById("myCanvas"); // (a)
var context = canvas.getContext("2d"); // (b)
// (c):
context.arc(canvas.width/2, canvas.height/2, 75, 0, 2 * Math.PI, false);
context.fill();
}
● Yes, we are using an event to initiate drawing here,
but this is not required, we could use the same
drawing code in any function elsewhere! In this
example we do so, because we want to see
something drawn as soon as the HTML page in
loaded!
● The coordinates are pixels relative to the left upper
corner of the canvas element.
● The last parameter of arc() controls whether the arc
is drawn clockwise (argument is false)or
anticlockwise (argument is true).
21
Excursion: Notification or Polling
● When the page's load event is fired, the function draw() will be called.
– This event is fired when the page is loaded into the browser. The state of the page then changes from unloaded to loaded.
● There exist two "extreme" ways to deal with state changes.
● Communication via events:
– We attach our code to the event, to which we want to react (get notified).
●
The code, which is called when the event fired, is called eventhandler or eventlistener.
– => We passively assume that the event will be fired somewhen in future. When the event is fired, we're getting notified.
– (This is what we call the "hollywood principle": Don't call us, we'll call you! It's also called "callback principle".)
● Communication via polling:
– We query a system function continuousely, until a certain state has changed.
– => We actively poll for a state to be changed (here with "slow busy waiting").
● JavaScript uses events for communication.
– Most GUI frameworks use events as well.
// Attaching an eventlistener:
// The eventlistener draw():
function draw() { /* pass */ }
// Attach the eventlistener draw() to the load event:
document.addEventListener("load", draw);
// Polling (this is no legal JavaScript code):
// The draw() function:
function draw() { /* pass */ }
// Wait until the page is loaded:
while (!document.isLoaded) {
wait(1000); // "slow busy waiting"
}
// When the document is loaded call draw():
draw();
22
Drawing on a Canvas Element
● Canvas allows to draw two kinds of primitives: solid primitives and paths (no official JavaScript API terms).
● Solid primitives are filled with a color, gradient or pattern.
– Relevant functions and properties: fillRect(), fillStyle, fill() (to fill a drafted path (see below))
● Paths are drafted with functions, which define the skeleton of a figure. Later on, these paths are stroked to be visible.
– Drafting paths is like "preliminary" drawing a figure with a very fine and hard pencil.
– Stroking is like drawing the real figure with ink.
– Relevant functions and properties: beginPath(), closePath(), moveTo(), lineTo(), rect(), arc(), strokeStyle, stroke() or fill()
– Sometimes
●
(1) a path needs to be started by calling beginPath() and sometimes
● (2) after the drafting is done a path needs to be closed (connecting the first with the last "pencil stop" with a line) by callingclosePath().
function drawPathAndStrokeCircle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.arc(/* pass */);
context.stroke();
}
function drawSolidCircle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.arc(/* pass */);
context.fill();
}
● The function moveTo() works like "pencil stop" and
then moving the pencil to another location without
drawing a line.
23
Controls
● So far we have a rough understanding of how we can draw visible contents on an HTML page.
– But it would be very time consuming to draw every piece of interaction in such a way!
– Therefor we have predefined pieces of interaction: controls.
● Controls are pieces on a GUI, arranged on a window, with which the user can interact.
– Users use mouse, keyboard and touch gestures to interact with the controls on the GUI.
24
Combine/implement Interaction with Controls and Canvas
● In this example we bind another eventlistener to theonclick event of a button.
– The onclick event is fired, when the button is clicked.
– The eventlistener drawInnerCircle() draws a smaller inner circle into the initial circle.
– The eventlistener drawInnerCircle() sets the text of the textbox to "Button clicked!".
● Via events and JavaScript code we can have real interactivity.
– Events are typically a result of user interaction, e.g. clicking a button.
●
Events are fired, when the state of HTML controls changes (page loaded, button clicked etc.).
– JavaScript code is provided by developers.
●
JavaScript code is able to access (getElementById()) and change the state of controls (e.g. setting a value).
function drawInnerCircle() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var textBox;
context.beginPath(); // Initiate a new path to decouple from 1st arc!
context.arc(canvas.width/2, canvas.height/2, 20, 0, 2 * Math.PI, false);
context.fillStyle = "white";
context.fill();
textBox = document.getElementById("myText");
textBox.value = "Button clicked!";
}
<html>
<head>
<script src="Canvas.js"></script>
<title>Canvas</title>
</head>
<body onload="draw();">
<canvas id="myCanvas" width="300" height="300"></canvas>
<button onclick="drawInnerCircle();">Click me!</button>
<input id="myText" type="text"></input>
</body>
</html>
25
Events with Parameters
● We can also attach events to a canvas element, e.g. to canvas' onmousedown event:
– The onmousedown event is fired, when the canvas is clicked.
– As can be seen, the onmousedown event is somewhat special: it accepts an argument!
●
Here we pass the global event object, just called "event".
– The event's argument is available via the parameter e in the eventlistener canvasClicked().
– The parameter allows to read the coordinates (i.e. properties x and y) of the mouse position, on which the mouse was clicked.
● A common strategy is to pass the global event object as an argument to the eventlistener.
– The passed object contains extra information about the state of the page, controls, keyboard and mouse.
– Then the eventlistener's parameter provides a lot of properties and functions, which allow almost full control of the GUI.
function canvasClicked(e) {
var textBox = document.getElementById("myText");
textBox.value = "x = "+e.x+"; y = "+e.y;
}
<html>
<head>
<script src="Canvas.js"></script>
<title>Canvas</title>
</head>
<body onload="draw();">
<canvas id="myCanvas"
onmousedown="canvasClicked(event);"
width="300" height="300"></canvas>
<input id="myText" type="text"></input>
</body>
</html>
26
Web Apps with HTML and JavaScript in Reality
● There are some important downsides of this approach:
– A browser needs to be able to render "HTML 5" in order to fully unleash the power of, e.g., canvas.
– The execution of JavaScript needs to be enabled in the browser!
– The HTML- as well as the JavaScript-code are loaded to the client side and can be read.
●
I.e. the code could be copied/reused without permission. Also leaks could be easily detected and exploited.
● (However there is a way to reduce the readability of code: with "code minimizers" (i.e. the opposite of code beautifiers).)
● General acceptance of web-applications:
– Most of them do not work offline.
– The acceptance of users is not always given, esp. the look and feel (l&f) is not like that of a desktop application.
– Web-applications can be a cheap but effective solution for business applications.
● Code minimizers do basically rename the used
identifiers (variable and function names) to very
short names and remove superfluous whitespaces. -
These modifications in the code "obfuscate" the
code and reduce the size of the code files, which
need to be transmitted from the web server to the
client.
27
Thank you!

More Related Content

What's hot

Computer_Graphics_basic_definitions_summary
Computer_Graphics_basic_definitions_summaryComputer_Graphics_basic_definitions_summary
Computer_Graphics_basic_definitions_summaryDr. Mohamed Kazim
Β 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphicsAmol Gaikwad
Β 
Armand Rousso describes about the Computer graphic
Armand Rousso describes about the Computer graphicArmand Rousso describes about the Computer graphic
Armand Rousso describes about the Computer graphicArmand Rousso
Β 
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...Yuki Koyama
Β 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphicssonal_badhe
Β 
Stream processors texture generation model for 3d virtual worlds learning too...
Stream processors texture generation model for 3d virtual worlds learning too...Stream processors texture generation model for 3d virtual worlds learning too...
Stream processors texture generation model for 3d virtual worlds learning too...Mikhail Fominykh
Β 
Image processing for robotics
Image processing for roboticsImage processing for robotics
Image processing for roboticsSALAAMCHAUS
Β 
CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33Bilal Ahmed
Β 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
Β 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics Priyodarshini Dhar
Β 
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LIST
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LISTCOMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LIST
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LISTtarun kumar sharma
Β 
Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes  Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes ijcga
Β 
Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes  Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes ijcga
Β 
Introduction to Computer graphics
Introduction to Computer graphics Introduction to Computer graphics
Introduction to Computer graphics PrathimaBaliga
Β 
Cartoon Animation
Cartoon AnimationCartoon Animation
Cartoon AnimationTheawaster485
Β 
Raster vs vector
Raster vs vectorRaster vs vector
Raster vs vectorSUCHITRA SINGH
Β 
Higher - Storing graphics
Higher - Storing graphicsHigher - Storing graphics
Higher - Storing graphicsmissstevenson01
Β 
Visual hull construction from semitransparent coloured silhouettes
Visual hull construction from semitransparent coloured silhouettesVisual hull construction from semitransparent coloured silhouettes
Visual hull construction from semitransparent coloured silhouettesijcga
Β 

What's hot (20)

Computer_Graphics_basic_definitions_summary
Computer_Graphics_basic_definitions_summaryComputer_Graphics_basic_definitions_summary
Computer_Graphics_basic_definitions_summary
Β 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphics
Β 
fundamentals of Computer graphics(Computer graphics tutorials)
 fundamentals of Computer graphics(Computer graphics tutorials) fundamentals of Computer graphics(Computer graphics tutorials)
fundamentals of Computer graphics(Computer graphics tutorials)
Β 
Overview of Computer Graphics
Overview of Computer GraphicsOverview of Computer Graphics
Overview of Computer Graphics
Β 
Armand Rousso describes about the Computer graphic
Armand Rousso describes about the Computer graphicArmand Rousso describes about the Computer graphic
Armand Rousso describes about the Computer graphic
Β 
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...
Decomposing Images into Layers with Advanced Color Blending [Pacific Graphics...
Β 
Introduction to computer graphics
Introduction to computer graphicsIntroduction to computer graphics
Introduction to computer graphics
Β 
Stream processors texture generation model for 3d virtual worlds learning too...
Stream processors texture generation model for 3d virtual worlds learning too...Stream processors texture generation model for 3d virtual worlds learning too...
Stream processors texture generation model for 3d virtual worlds learning too...
Β 
Image processing for robotics
Image processing for roboticsImage processing for robotics
Image processing for robotics
Β 
CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33CS101- Introduction to Computing- Lecture 33
CS101- Introduction to Computing- Lecture 33
Β 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
Β 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics
Β 
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LIST
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LISTCOMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LIST
COMPUTER GRAPHICS AND MULTI MEDIA SOFTWARE LIST
Β 
Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes  Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes
Β 
Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes  Visual Hull Construction from Semitransparent Coloured Silhouettes
Visual Hull Construction from Semitransparent Coloured Silhouettes
Β 
Introduction to Computer graphics
Introduction to Computer graphics Introduction to Computer graphics
Introduction to Computer graphics
Β 
Cartoon Animation
Cartoon AnimationCartoon Animation
Cartoon Animation
Β 
Raster vs vector
Raster vs vectorRaster vs vector
Raster vs vector
Β 
Higher - Storing graphics
Higher - Storing graphicsHigher - Storing graphics
Higher - Storing graphics
Β 
Visual hull construction from semitransparent coloured silhouettes
Visual hull construction from semitransparent coloured silhouettesVisual hull construction from semitransparent coloured silhouettes
Visual hull construction from semitransparent coloured silhouettes
Β 

Viewers also liked

(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithmsNico Ludwig
Β 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithmsNico Ludwig
Β 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithmsNico Ludwig
Β 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithmsNico Ludwig
Β 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithmsNico Ludwig
Β 
(3) collections algorithms
(3) collections algorithms(3) collections algorithms
(3) collections algorithmsNico Ludwig
Β 

Viewers also liked (6)

(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
Β 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithms
Β 
(4) collections algorithms
(4) collections algorithms(4) collections algorithms
(4) collections algorithms
Β 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithms
Β 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
Β 
(3) collections algorithms
(3) collections algorithms(3) collections algorithms
(3) collections algorithms
Β 

Similar to Drawing Graphics in HTML5 Canvas

Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineAccelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineMark Kilgard
Β 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System OverviewRAJARATNAS
Β 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphicsLOKESH KUMAR
Β 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics NotesGurpreet singh
Β 
Kompüter Qrafikasına giriş
Kompüter Qrafikasına girişKompüter Qrafikasına giriş
Kompüter Qrafikasına girişHackathon Azerbaijan
Β 
Mod 2 hardware_graphics.pdf
Mod 2 hardware_graphics.pdfMod 2 hardware_graphics.pdf
Mod 2 hardware_graphics.pdfDavidsonJebaseelan1
Β 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalMasatsugu HASHIMOTO
Β 
topic_- introduction of computer graphics.
   topic_- introduction of computer graphics.   topic_- introduction of computer graphics.
topic_- introduction of computer graphics.Aniketkumar204
Β 
Computer graphics - Nitish Nagar
Computer graphics - Nitish NagarComputer graphics - Nitish Nagar
Computer graphics - Nitish NagarNitish Nagar
Β 
High performance graphics and computation - OpenGL ES and RenderScript
High performance graphics and computation - OpenGL ES and RenderScript High performance graphics and computation - OpenGL ES and RenderScript
High performance graphics and computation - OpenGL ES and RenderScript BlrDroid
Β 
GPU-accelerated Path Rendering
GPU-accelerated Path RenderingGPU-accelerated Path Rendering
GPU-accelerated Path RenderingMark Kilgard
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technologyhaverstockmedia
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technologyhaverstockmedia
Β 
Digital Graphics Technology
Digital Graphics TechnologyDigital Graphics Technology
Digital Graphics Technologyhaverstockmedia
Β 
Digital Graphics Technology
Digital Graphics TechnologyDigital Graphics Technology
Digital Graphics Technologyhaverstockmedia
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technologyhaverstockmedia
Β 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IπŸ’» Anton Gerdelan
Β 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
Β 
Desktop Softwares for Unmanned Aerial Systems(UAS))
Desktop Softwares for Unmanned Aerial Systems(UAS))Desktop Softwares for Unmanned Aerial Systems(UAS))
Desktop Softwares for Unmanned Aerial Systems(UAS))Kamal Shahi
Β 

Similar to Drawing Graphics in HTML5 Canvas (20)

Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware PipelineAccelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Accelerating Vector Graphics Rendering using the Graphics Hardware Pipeline
Β 
Computer graphics Applications and System Overview
Computer graphics Applications and System OverviewComputer graphics Applications and System Overview
Computer graphics Applications and System Overview
Β 
Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
Β 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics Notes
Β 
Kompüter Qrafikasına giriş
Kompüter Qrafikasına girişKompüter Qrafikasına giriş
Kompüter Qrafikasına giriş
Β 
Mod 2 hardware_graphics.pdf
Mod 2 hardware_graphics.pdfMod 2 hardware_graphics.pdf
Mod 2 hardware_graphics.pdf
Β 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
Β 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_Final
Β 
topic_- introduction of computer graphics.
   topic_- introduction of computer graphics.   topic_- introduction of computer graphics.
topic_- introduction of computer graphics.
Β 
Computer graphics - Nitish Nagar
Computer graphics - Nitish NagarComputer graphics - Nitish Nagar
Computer graphics - Nitish Nagar
Β 
High performance graphics and computation - OpenGL ES and RenderScript
High performance graphics and computation - OpenGL ES and RenderScript High performance graphics and computation - OpenGL ES and RenderScript
High performance graphics and computation - OpenGL ES and RenderScript
Β 
GPU-accelerated Path Rendering
GPU-accelerated Path RenderingGPU-accelerated Path Rendering
GPU-accelerated Path Rendering
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technology
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technology
Β 
Digital Graphics Technology
Digital Graphics TechnologyDigital Graphics Technology
Digital Graphics Technology
Β 
Digital Graphics Technology
Digital Graphics TechnologyDigital Graphics Technology
Digital Graphics Technology
Β 
Digital graphics technology
Digital graphics technologyDigital graphics technology
Digital graphics technology
Β 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
Β 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Β 
Desktop Softwares for Unmanned Aerial Systems(UAS))
Desktop Softwares for Unmanned Aerial Systems(UAS))Desktop Softwares for Unmanned Aerial Systems(UAS))
Desktop Softwares for Unmanned Aerial Systems(UAS))
Β 

More from Nico Ludwig

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_vNico Ludwig
Β 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivNico Ludwig
Β 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiNico Ludwig
Β 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiNico Ludwig
Β 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_iNico Ludwig
Β 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
Β 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
Β 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_viNico Ludwig
Β 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
Β 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
Β 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iiiNico Ludwig
Β 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_iiNico Ludwig
Β 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_iNico Ludwig
Β 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNico Ludwig
Β 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
Β 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNico Ludwig
Β 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNico Ludwig
Β 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNico Ludwig
Β 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
Β 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNico Ludwig
Β 

More from Nico Ludwig (20)

Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_vGrundkurs fuer excel_part_v
Grundkurs fuer excel_part_v
Β 
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_ivGrundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iv
Β 
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iiiGrundkurs fuer excel_part_iii
Grundkurs fuer excel_part_iii
Β 
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_iiGrundkurs fuer excel_part_ii
Grundkurs fuer excel_part_ii
Β 
Grundkurs fuer excel_part_i
Grundkurs fuer excel_part_iGrundkurs fuer excel_part_i
Grundkurs fuer excel_part_i
Β 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
Β 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
Β 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
Β 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
Β 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
Β 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iii
Β 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
Β 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
Β 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
Β 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
Β 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
Β 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
Β 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
Β 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
Β 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
Β 

Recently uploaded

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
Β 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
Β 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
Β 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
Β 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
Β 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
Β 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...soniya singh
Β 
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...gurkirankumar98700
Β 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
Β 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
Β 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
Β 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
Β 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
Β 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
Β 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
Β 

Recently uploaded (20)

KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
Β 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
Β 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
Β 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Β 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
Β 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
Β 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Β 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
Β 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
Β 
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➑️ 8264348440 πŸ’‹πŸ“ž Independent Escort S...
Β 
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
(Genuine) Escort Service Lucknow | Starting β‚Ή,5K To @25k with A/C πŸ§‘πŸ½β€β€οΈβ€πŸ§‘πŸ» 89...
Β 
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar πŸ“±  9999965857  🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar πŸ“± 9999965857 🀩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Β 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
Β 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
Β 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
Β 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
Β 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
Β 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
Β 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
Β 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
Β 

Drawing Graphics in HTML5 Canvas

  • 2. 2 TOC ● (2) GUI – Drawing – Vector- and Raster-based Graphics ● Idea behind Vector- and Raster-based Graphics ● Crispness ● Overview of Raster-based Drawing APIs – Platform independent Graphics and GUIs in the Web Browser ● Bare HTML Pages ● Plugins and Problems ● From rich Content to HTML 5 – Drawing with HTML 5 Canvas ● Continuous, Event driven and free Drawing ● Basic Drawing "How does Drawing work with JavaScript?" ● Interaction with Controls ● Sources: – http://channel9.msdn.com/Niners/rbarraza – web.archive.org, Bare_HTML_Page (www.yahoo.com, 1996)
  • 3. 3 Vector and Raster-based Graphics ● We already discussed vector and raster displays, which bring graphics to a screen withdifferent hardware respectively. ● Apart from how graphics are brought to screen by hardware, there are alsodifferent ways to render graphics by software. – (The term "rendering" is a more general term for "bringing graphics (incl. video) to the screen or to paper".) ● From a software perspective there exist vector-based and raster-based graphics.
  • 4. 4 Raster-based Graphics ● In this lecture we'll only discuss raster-based graphics in depth. ● Graphics that is rendered on a screen, wherebysoftware handles pixels individually, is called raster-based. – (Raster-based graphics are also called pixel-based graphics.) ● For example Java's "Java 2D" software provides the function setRGB() to set one pixel to a certain value/color: ● Often, only raster-based graphics are associated with the word"drawing". ● Raster-based graphics are also used for photographs. // Java: Set the pixel at (0; 0) to white color: image.setRGB(0, 0, Color.WHITE.getRGB());
  • 5. 5 Basics on Raster-based Drawing ● Let's recapitulate, what a picture on a screen is: a big two-dimensional array of pixels, in other words it is a matrix. – Mind that we already discussed the needed memory depending on spatial dimension and color resolution: a picture is an array! ● To have graphics on the screen we could use functions, which draw pixels of a specific color at specific coordinates, e.g.: ● But there are some problems with this pixel-oriented approach: – It is relatively hard to use these functions to draw more complicated shapes like circles (e.g. with trigonometric functions). – Drawing individual pixels would be very inefficient and slow, at least not very interactive. ● Therefor graphics libraries provide special functions to draw graphic primitives (rectangle, ellipse, line, bezier and text): – This approach is very much faster than pixel-oriented drawing! Often the graphics adapter provides hardware acceleration. ● I.e. the calculation of coordinates of individual pixels to draw a circle (with trigonometry) can be done on the graphics adapterwithout using the CPU! ● The term graphics adapter can be reduced to the term Graphics Processing Unit (GPU). – A set of functions and objects controlling specific aspects on a computer is called Application Programming Interface (API). ● For operating systems (OS) providing a GUI, it is mandatory to have an API for graphics programming. // Java: Draw an ellipse of width and height at (0; 0): graphics.setColor(Color.WHITE); graphics.drawOval(0, 0, width, height); // Java: Set the pixel at (0; 0) to white color: image.setRGB(0, 0, Color.WHITE.getRGB()); ● The coordinate system of pixels is a left-handed system (an example for a right-handed coordinate system is the cartesian coordinate system)! This is due to the fact that pictures are drawn row wise on a CRT.
  • 6. 6 Crispness ● We should have a look at the result of drawing a circle with a raster-based API, we'll continue using Java 2D: ● Welcome the alias-effect: It looks crisp, but... – …when we zoom the drawn image, the pixels become visible and we see how the circle is plotted by pixels mimicking an arc: ● For raster-based graphics there are two ways to get at least a bit of the crispness back: – (1) By the application of anti-aliasing, which smoothes a raster-graphics' edges with the background with colored extra pixels. – (2) By the application of subpixel rendering (e.g. ClearType on Windows). Zoom ZoomZoom Zoom ZoomZoom Subpixel rendering // Java: Draw a circle with the diameter 100 at (0; 0): graphics.setColor(Color.WHITE); graphics.drawOval(0, 0, 100, 100); ● Aliasing is a term taken from digital signal processing technologies. Aliasing happens if the resolution of a raster graphic (read: frequency) is greater than the resolution of a zoom frame (read: scan frequency). ● Graphical anti aliasing put a considerable burden on rendering a graphic. Some tools, e.g. LibreOffice allow to deactivate anti aliasing. ● Bill Hill invented ClearType at IBM in 1988. The exploitation of sub pixels lead to having more DPIs, which lead to nicer text before WPF! ● It should be said that techniques for anti aliasing are about to get superfluous with 4K (4096 Γ— 2304 or 3840 Γ— 2160) graphics. The pixels are so small that they are typically no longer individually visible.
  • 7. 7 Excursion – Vector-based Graphics – Part I ● There are problems with raster-based graphics in general: – When parts of the graphics are zoomed, the crispness of details gets lost. It results in pixilated graphics, not recognizable as detail. – When the resolution increases, graphics get smaller. When the resolution decreases, graphics get larger. ● Is that a problem? Well, when we have a premium 4K display do we like smaller graphics or crisper graphics? ● These effects emerge because the rendering of raster-based graphics is dependent on the resolution. – The shown problems are esp. visible on arcs and circles and they are very annoying on text. increase resolution
  • 8. 8 Excursion – Vector-based Graphics – Part II ● To solve these problems, there needs to be a way to make the rendering of graphics independent from the resolution. – The logical resolution was made independent from the physical resolution. ● E.g. this idea was put into effect with Microsoft's Windows Presentation Foundation (WPF): – WPF introduced Device Independent Units (DIUs). DIUs are independent of a device's pixel raster, a DIU is defined as 1/96 of an inch. ● On a device having 96ppi (pixels per inch), 96 pixels would consume 1 inch; on a device having 120ppi, 96DIUs would be represented by 120 pixels... ● (If logical DIUs do not exactly match to physical pixels WPF will use anti-aliasing.) ● Vector-based graphics are described as formula, which is parameterized by the physical resolution. – It means that vector-based graphics are not described as an array of pixels! – Raster-based graphics get smaller with higher resolution and zooming leads to pixelation: – Vector-based graphics get crisper with higher resolution and zooming, em, just zooms! Vector-based graphics are scalable! raster-based zoom raster-based zoom raster-based zoom vector-based zoom vector-based zoom vector-based zoom ● Scalability can be defined in a very simple way: Graphics a scalable, if it is parameterized with physical resolutions (spacial dimension as well as color resolution). ● Maybe in future we'll have to take more parameters into consideration: 3D- depth/resolution, haptic-detail-resolution, etc.
  • 9. 9 Excursion – Vector-based Graphics – Part III ● The application of vector-based graphics allowed the development some very important applications: – crisp and scalable texts to allow WYSIWYG editing of documents, – a new category of software for Computer Aided Design (CAD) to construct structures on a computer instead of pencil and paper, – a new category of software for Desktop Publishing (DTP) to layout high quality documents for printout. – => Graphics and print results of excellent quality on any scale. – (Vector-based graphics are not suited for photographs.) ● Besides these applications, which more or less deal with design, also the desktop was influenced meanwhile: – The scalability and crispness of vector-based graphics was applied to controls, windows and the desktop. – This was required, because of: ● (1) the availability of higher and higher physical resolutions (high definition, 4K, 8K) and ● (2) the availability of different screen sizes for the same applications (watch, mp3-player, automotive, mobile, tablet, notebook, PC screen, tv, projector). – Examples: ● Desktop: WPF, (Graphics Device Interface+ (GDI+)), Quartz, PostScript, Cairo ● Browser: Silverlight (WPF/E), Scalable Vector Graphics (SVG) ● Printer: PostScript ● Using the same graphics API for graphics on the screen as well as for the printer is the basis for WYSIWYG. ● On OS X the graphics engine "Quartz" is based on PDF (Portable Document Format) and uses PDF's features to have resolution independent graphics on the desktop. ● Virtually OS X uses PostScript and transparent PNGs and Windows uses a mix of raster- and vector-base graphics. ● PDF is based on PostScript, but it is structured like a "real" programming language. There are also some extra features in PDF like transparent regions. ● GDI+ is the successor of GDI. It is hardware accelerated (which was no longer the case for GDI starting with Windows Vista) and has a couple of features for using vector-based graphics.
  • 10. 10 Overview of raster-based Drawing APIs ● In this presentation we'll only discuss raster-based drawing in more depth. ● Up to now we used the Java 2D API for the examples, but there exist more APIs: ● Windows – Graphics Device Interface (GDI) ● Linux – GTK+ drawing (GTK for GIMP Toolkit; GIMP for GNU Image Manipulation Program; GNU for GNU is not Unix) ● OS X – Quartz, Cocoa drawing
  • 11. 11 Native and platform independent Drawing APIs ● The drawing APIs we've enumerated are so called native APIs. What does that mean? – Native APIs are only usable on/compatible with a certain platform. E.g. Windows GDI code won't run on OS X. – I.e. code written in native APIs is not portable! β†’ Native API vs. platform independent API. – On the other hand native APIs are fast, because they can exploit the power of the platform, e.g. directly use Windows functions. ● From a 20K miles perspective there are two ways to have platform independent (drawing) APIs: – Create and establish a common platform. ● Establish and use a common graphics API, which is translated into native graphics API calls at run time. ● E.g. Java 2D, QT – Use a present common platform. ● Find a platform, which is existent on most OS' and implement graphics on that platform. ● E.g. web browsers Operation System Graphics Adapter Native graphics API Platform independent graphics API Application Operation System Graphics Adapter Native graphics API Browser, interprets HTML Website
  • 12. 12 Platform independent Graphics in the Web Browser ● The following discussion deals with platform independent graphics via the web browser (browser). ● Browsers are an interesting platform, because they are available on all important operating systems! ● The first approach to put "graphical content" into effect on the browser was bare HTML with forms and controls. – ~mid 1990s
  • 13. 13 Bare HTML Pages ● Bare HTML pages do of course work very good in a browser, but using them didn't feel like using an application. – HTML pages basically look like a pages of text containing some links, form elements (controls) and images. – Using HTML pages is more or less navigation in the browser with links and the browser history. – HTML pages seem to have no togetherness: somehow the contents of the same web address seem to belong together somehow. ● In other words: togetherness is primarily defined by how the session with the HTML "site" is defined. ● Yes, it works, but the result is not very appealing. It is just "navigation in the browser". – When this approach was used, network throughput was low and the performance of clients was not very good. – On the client the browser just needed to store and render pages. The web server had to handle many requests. – The approach of bare HTML pages is the basis for the GUI of the internet! HTML page 1 the "application" HTML page 2 HTML page 3 HTML page 4 Form Control 1 Control 2 Image Link One page in the browser browser history link link link web server Client Server delivers HTML pages ● We'll not discuss multitiered architectures here. Let's just assume that we have a web server as well as clients and no other participants (e.g. database servers). ● But it should be said that the shown architecture does somehow resemble the "thin-client- mainframe" architecture. The thin-client is the application running in the browser, the mainframe is the web-server, or whatever servers are behind the server-border (following the figure on this slide).
  • 14. 14 Rich content with Plugins ● The next incarnation of "graphical content" in the browser was the usage of additional browser plugins. – E.g. Java Applets, Adobe Flash, Apple QuickTime etc. ● The idea is to use a special control, which has very rich interactive features: – The functionality of these controls is provided by plugins, which are installed on the browser's OS. ● Typically the "object"- or "embed"-HTML-element is used. – With plugins the browser is able to execute mini-applications, often called applets, in instances of plugin controls. ● The browser does indeed start an embedded runtime (e.g. the Java runtime) to execute applets. – The web server delivers binary components (and HTML pages) that contain the code to be run in the plugin controls. – (Adobe Flash and Apple QuickTime were the most important plugins in order to play video material in the browser at all!) HTML page Plugin component One page in the browser ● Before HTML 5 the applet element could be used for Java applets. This element is no longer supported. ● There also exist so called hybrid Java-applets: those implement a Java main() method, which makes them runnable as "ordinary" Java application on the desktop. ● Some OS' allow applets running, or even web sites, on the desktop, these mini-applications on the desktop are sometimes called widgets.
  • 15. 15 Rich content with Plugins ● Browser plugin technologies allowed "web-applications" consisting of only one site without the need for navigation. – It should be clarified that each type of plugin provides its own event system, apart from the browser's event system. – Because events are an intrinsic part of genuine GUIs, we can say that a web-application provides a genuine GUI. – Pages could be designed as a mosaic of plugin controls, such web-applications are called Single Page web-Applications (SPAs). ● A new aspect of SPAs is that no navigation/reloading of sites is needed. Only parts of the sites are reloaded. ● After SPAs with plugins established, another kind of SPAs emerged: those usingAJAX. – AJAX (Asynchronous JavaScript And XML) uses JavaScript to load content dynamically without plugin components. ● The important point: AJAX allows to load parts of a currently displayed page w/o reloading the whole page! – The mix of those technologies is sometimes called "Web 2.0" to have a nice marketing term. – A web-application using Web 2.0 is sometimes called Rich Internet Application (RIA). ● It can be said that the last incarnation of RIAs were sites that consisted of one huge control making up the whole content. – E.g. JavaFX and Silverlight. ● Yes, this approach also worked and the results were appealing, but there areproblems with the application of plugins!
  • 16. 16 Problems with Browser Plugins ● The problem lies in the place where plugins are executed: in the browser and on the client side. – Different browsers on different clients may behave differently. This also influences the effort for quality assurance! – The required runtimes (and correct versions thereof) need to be installed on the client side. – Because plugin components are loaded from a foreign source and executed on the client side, there is a certain security problem. ● To shield the client from vicious plugin code, plugin runtimes are executed in a so called sandbox having strong security constraints. ● The problem is that there could be a leak in the sandbox, which still allows vicious plugin code to be executed! ● => As a result the execution of plugins is often blocked, and many users don't trust these technologies (esp. Java applets). – Running plugin code requires a lot of resources: computing time as well as battery lifetime! ● In order to maximize battery lifetime, some browsers (e.g. Safari) freeze the execution of plugins, so that the uses must start them manually on the page.
  • 17. 17 The Solution: HTML 5 ● However, in the end there are still many problems with GUIs in the browser: – With bare HTML the interaction is not appealing, e.g. navigation among HTML pages. – Plugins need a lot of resources: computing time and battery lifetime. – Plugin runtimes are not necessarily installed and activated on the client-side. – Plugins provide potential security problems. ● It took years until industry addressed these problems.In the end the answer was "HTML 5", providing important updates: – (HTML 5 is not strictly the successor of HTML 4, instead it is a set of new features running in the browser.) – New clever input controls: date pickers, email and web address controls, sliders and spinboxes etc. – Support for offline web-applications, HTML 5 storage and support for data mapping and annotation with microdata. – Support for mobile web-applications: geo location APIs. – Support for playing video material without third party components like Apple QuickTime or Adobe Flash. – Support for appealing/more desktop-like usage, e.g. with web workers for doing things in the background. – But, potentially the most powerful new feature is the "canvas"-HTML-element, which we will discuss for the rest of this lecture. ● "canvas" is basically a way to bring interactive graphics into the browser with JavaScript without any plugins. – Therefor we can now continue our discussion about of how software implements drawing in general... ● Apple's browser Safari 7 addressed the computing time and battery life problem: the execution of plugins are paused by default. ● Virtually all these individual HTML 5 features need to be checked for support in the browser. A browser may support only a subset of these features; browser do usually not support "HTML 5" completely. ● HTML 5 video supports video/mp4, video/webm and video/ogg following the standard.
  • 18. 18 Excursion: Continuous, Event driven and free Drawing – Part I ● Basically there exist three models for drawing on the computer screen: – Continuous drawing. – Event driven drawing. – Free drawing. ● Continuous drawing: – The code, which performs the drawing, is executed automatically and continuously at a certain framerate. ● Benefit: the programming of animation and other "vivid" graphics is very simple. It's good for learning graphics basics and simple to use for "sketching". ● Downside: it needs a lot of resources. – Example: Processing ● Event driven drawing: – The code, which performs the drawing is only executed, when specific events are raised (e.g. update, redraw, refresh, resize). ● Benefit: it doesn't need many resources. ● Downside: W/o interaction there is generally no drawing. (To have continuous drawing with an event driven drawing API, we have to fire draw events at a certain framerate or call the drawing code continuously ourselves.) – Examples: Cocoa drawing (OS X), GTK, Java 2D, Windows Forms ● There exists Processing.js, which is a continuous drawing API based on Processing, but being implemented used the event driven canvas API.
  • 19. 19 Excursion: Continuous, Event driven and free Drawing – Part II ● However, we want to discuss the third approach: free drawing. ● The idea of free drawing is that there is neither a dedicated event that initiates drawing nor any redrawing framerate. ● Free drawing means that any code, which can access the context of the graphics is able to draw! – The code can draw independently on events as well as independently on a continuous framerate. – It should be said that this is also possible with, e.g., Windows Forms, but the result might be overdrawn by the draw-event! ● E.g. with HTML 5 canvas each function is able to draw, because the graphical context can be accessed from everywhere. – Benefits: it is simple to use from scratch. – Downsides: it can be tricky to migrate code from other drawing approaches. ● Ok, now its time to see free drawing with HTML 5 canvas! ● There exists Processing.js, which is a continuous drawing API based on Processing, but being implemented used the event driven canvas API.
  • 20. 20 Let's go and draw! ● We'll begin with a general HTML scaffold to program canvas with these important parts: – (1) Import the file containing the needed JavaScript code (Canvas.js). – (2) Bind the HTML page's load event to the JavaScript function draw() (defined in Canvas.js). – (3) Mark the canvas element in the page's body with the id "myCanvas". ● In the JavaScript file "Canvas.js" we implement the function draw(): – (a) Get the HTML page's canvas element by its id "myCanvas". – (b) Get the graphical context from the canvas element by calling getContext("2d"). – (c) On the canvas' graphics context draw on the canvas programmatically with special functions (e.g. arc() and fill()). ● As can be seen, the event onload and the canvas object connect the HTML page with the JavaScript code. <html> <head> <script src="Canvas.js"></script> <!--(1)--> <title>Canvas</title> </head> <body onload="draw();"> <!--(2)--> <canvas id="myCanvas" width="300" height="300"></canvas><!--(3)--> </body> </html> function draw() { var canvas = document.getElementById("myCanvas"); // (a) var context = canvas.getContext("2d"); // (b) // (c): context.arc(canvas.width/2, canvas.height/2, 75, 0, 2 * Math.PI, false); context.fill(); } ● Yes, we are using an event to initiate drawing here, but this is not required, we could use the same drawing code in any function elsewhere! In this example we do so, because we want to see something drawn as soon as the HTML page in loaded! ● The coordinates are pixels relative to the left upper corner of the canvas element. ● The last parameter of arc() controls whether the arc is drawn clockwise (argument is false)or anticlockwise (argument is true).
  • 21. 21 Excursion: Notification or Polling ● When the page's load event is fired, the function draw() will be called. – This event is fired when the page is loaded into the browser. The state of the page then changes from unloaded to loaded. ● There exist two "extreme" ways to deal with state changes. ● Communication via events: – We attach our code to the event, to which we want to react (get notified). ● The code, which is called when the event fired, is called eventhandler or eventlistener. – => We passively assume that the event will be fired somewhen in future. When the event is fired, we're getting notified. – (This is what we call the "hollywood principle": Don't call us, we'll call you! It's also called "callback principle".) ● Communication via polling: – We query a system function continuousely, until a certain state has changed. – => We actively poll for a state to be changed (here with "slow busy waiting"). ● JavaScript uses events for communication. – Most GUI frameworks use events as well. // Attaching an eventlistener: // The eventlistener draw(): function draw() { /* pass */ } // Attach the eventlistener draw() to the load event: document.addEventListener("load", draw); // Polling (this is no legal JavaScript code): // The draw() function: function draw() { /* pass */ } // Wait until the page is loaded: while (!document.isLoaded) { wait(1000); // "slow busy waiting" } // When the document is loaded call draw(): draw();
  • 22. 22 Drawing on a Canvas Element ● Canvas allows to draw two kinds of primitives: solid primitives and paths (no official JavaScript API terms). ● Solid primitives are filled with a color, gradient or pattern. – Relevant functions and properties: fillRect(), fillStyle, fill() (to fill a drafted path (see below)) ● Paths are drafted with functions, which define the skeleton of a figure. Later on, these paths are stroked to be visible. – Drafting paths is like "preliminary" drawing a figure with a very fine and hard pencil. – Stroking is like drawing the real figure with ink. – Relevant functions and properties: beginPath(), closePath(), moveTo(), lineTo(), rect(), arc(), strokeStyle, stroke() or fill() – Sometimes ● (1) a path needs to be started by calling beginPath() and sometimes ● (2) after the drafting is done a path needs to be closed (connecting the first with the last "pencil stop" with a line) by callingclosePath(). function drawPathAndStrokeCircle() { var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.arc(/* pass */); context.stroke(); } function drawSolidCircle() { var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.arc(/* pass */); context.fill(); } ● The function moveTo() works like "pencil stop" and then moving the pencil to another location without drawing a line.
  • 23. 23 Controls ● So far we have a rough understanding of how we can draw visible contents on an HTML page. – But it would be very time consuming to draw every piece of interaction in such a way! – Therefor we have predefined pieces of interaction: controls. ● Controls are pieces on a GUI, arranged on a window, with which the user can interact. – Users use mouse, keyboard and touch gestures to interact with the controls on the GUI.
  • 24. 24 Combine/implement Interaction with Controls and Canvas ● In this example we bind another eventlistener to theonclick event of a button. – The onclick event is fired, when the button is clicked. – The eventlistener drawInnerCircle() draws a smaller inner circle into the initial circle. – The eventlistener drawInnerCircle() sets the text of the textbox to "Button clicked!". ● Via events and JavaScript code we can have real interactivity. – Events are typically a result of user interaction, e.g. clicking a button. ● Events are fired, when the state of HTML controls changes (page loaded, button clicked etc.). – JavaScript code is provided by developers. ● JavaScript code is able to access (getElementById()) and change the state of controls (e.g. setting a value). function drawInnerCircle() { var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); var textBox; context.beginPath(); // Initiate a new path to decouple from 1st arc! context.arc(canvas.width/2, canvas.height/2, 20, 0, 2 * Math.PI, false); context.fillStyle = "white"; context.fill(); textBox = document.getElementById("myText"); textBox.value = "Button clicked!"; } <html> <head> <script src="Canvas.js"></script> <title>Canvas</title> </head> <body onload="draw();"> <canvas id="myCanvas" width="300" height="300"></canvas> <button onclick="drawInnerCircle();">Click me!</button> <input id="myText" type="text"></input> </body> </html>
  • 25. 25 Events with Parameters ● We can also attach events to a canvas element, e.g. to canvas' onmousedown event: – The onmousedown event is fired, when the canvas is clicked. – As can be seen, the onmousedown event is somewhat special: it accepts an argument! ● Here we pass the global event object, just called "event". – The event's argument is available via the parameter e in the eventlistener canvasClicked(). – The parameter allows to read the coordinates (i.e. properties x and y) of the mouse position, on which the mouse was clicked. ● A common strategy is to pass the global event object as an argument to the eventlistener. – The passed object contains extra information about the state of the page, controls, keyboard and mouse. – Then the eventlistener's parameter provides a lot of properties and functions, which allow almost full control of the GUI. function canvasClicked(e) { var textBox = document.getElementById("myText"); textBox.value = "x = "+e.x+"; y = "+e.y; } <html> <head> <script src="Canvas.js"></script> <title>Canvas</title> </head> <body onload="draw();"> <canvas id="myCanvas" onmousedown="canvasClicked(event);" width="300" height="300"></canvas> <input id="myText" type="text"></input> </body> </html>
  • 26. 26 Web Apps with HTML and JavaScript in Reality ● There are some important downsides of this approach: – A browser needs to be able to render "HTML 5" in order to fully unleash the power of, e.g., canvas. – The execution of JavaScript needs to be enabled in the browser! – The HTML- as well as the JavaScript-code are loaded to the client side and can be read. ● I.e. the code could be copied/reused without permission. Also leaks could be easily detected and exploited. ● (However there is a way to reduce the readability of code: with "code minimizers" (i.e. the opposite of code beautifiers).) ● General acceptance of web-applications: – Most of them do not work offline. – The acceptance of users is not always given, esp. the look and feel (l&f) is not like that of a desktop application. – Web-applications can be a cheap but effective solution for business applications. ● Code minimizers do basically rename the used identifiers (variable and function names) to very short names and remove superfluous whitespaces. - These modifications in the code "obfuscate" the code and reduce the size of the code files, which need to be transmitted from the web server to the client.