CS 490: Computer Graphics Graphics Programming and HTML Canvas.

Slides:



Advertisements
Similar presentations
The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
Advertisements

CT-376 jQuery Most popular javascript library today Latest version:
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
JQuery A Javascript Library Hard things made eas(ier) Norman White.
The Web Warrior Guide to Web Design Technologies
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Fundamentals, DOM, Events, AJAX, UI Doncho Minkov Telerik Corporation
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
JQuery CS 268. What is jQuery? From their web site:
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Chapter 4 Dreamweaver: Part II The Web Warrior Guide to Web Design Technologies.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Learning & Development Telerik Software Academy.
Yahoo! User Interface (YUI) Library Natly Mekdara.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
Chapter 19: Adding JavaScript
Bridges To Computing General Information: This document was created for use in the "Bridges to Computing" project of Brooklyn College. You are invited.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
13. jQuery See the official documentation at  See the terse API documentation at
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
Session: 17. © Aptech Ltd. 2Canvas and JavaScript / Session 17  Describe Canvas in HTML5  Explain the procedure to draw lines  Explain the procedure.
Flash & JavaScript Mariela Hristova October 19, 2004 INF 385E – Fall 2004 – School of Information.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
JavaScript Frameworks Presented by Kyle Goins Also see:
Animation & Effects Using JQuery. What is jQuery? jQuery is a lightweight, JavaScript library. The purpose of jQuery is to make it much easier to use.
JavaScript, jQuery, and Mashups Incorporating JavaScript, jQuery, and other Mashups into existing pages.
. Taught by: Muhammad Ali Baloch midahot. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between.
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
LOGO sparcs.org 1 jQuery Tutorial Presenter ㅎㅇㅎㅇ.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Web Programming Java Script & jQuery Web Programming.
1 What is JQuery. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax* interactions.
Understanding JavaScript and Coding Essentials Lesson 8.
School of Computing and Information Systems RIA Animation, part I.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model.
Lecture 9: Extra Features and Web Design Tarik Booker CS 120 California State University, Los Angeles.
CSCI 3100 Tutorial 5 JavaScript & Ajax Jichuan Zeng Department of Computer Science and Engineering The Chinese University of Hong.
Introduction to.
What is a Function Expression?
Section 17.1 Section 17.2 Add an audio file using HTML
Introduction to JavaScript
Building beautiful and interactive apps with HTML5 & CSS3
14 A Brief Look at JavaScript and jQuery.
Introduction to D3.js and Bar Chart in D3.js
JavaScript Introduction
DHTML Javascript Internet Technology.
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
DHTML Javascript Internet Technology.
..
Chengyu Sun California State University, Los Angeles
CS 352: Computer Graphics Graphics Programming and HTML Canvas.
Introduction to JavaScript
Presentation transcript:

CS 490: Computer Graphics Graphics Programming and HTML Canvas

How would you… Interactive Computer Graphics Cha pter 2 - 2

The Sierpinski Gasket pick a random point P inside a triangle for I = 1 to n select one of the three vertices (V) at random find the point P' halfway between P and V plot P' P = P' Interactive Computer Graphics Cha pter 2 - 3

The business end Interactive Computer Graphics Cha pter 2 - 4

HTML Canvas We'll use HTML's Canvas element for 2-D graphics Programming in JavaScript You can do your development with any (modern) browser Turn in programs by copying them to your public_html/352/proj2 directory Supported browsers: all relatively modern ones Interactive Computer Graphics Cha pter 2 - 5

HTML, CSS I'll assume you can copy/modify the examples as needed If you'd like a tutorial, see w3schools.com Interactive Computer Graphics Cha pter 2 - 6

JavaScript What is it? JavaScript, ECMAScript (ISO-16262), ActionScript… Cross-platform, object-oriented, light-weight scripting language for the Web Dynamic typing No disk writing, other restrictions Powers Web apps (gmail, google maps, google docs)

Object Orientation Built-in JavaScript objects String, Date, Array, Boolean, Math, RegExp DOM: document object model Document, Anchor, Button, Table, Style, … Document Your own objects: add properties or methods to any variable var sierpinski = { radius: 0.7, } sierpinski.init = function () { var returnVal = 0;...

Where to put it : scripts to be executed when they are called or when an event triggers function message() { alert("This alert box was called with the onload event"); }

Where to put it : scripts to be executed when they are loaded document.write(“This message is from JavaScript”);

JavaScript Clock setInterval("settime()", 1000); function settime() { var d = new Date(); var hour = d.getHours(); hour = (hour < 10 ? "0" : "") + hour; var min = d.getMinutes(); min = (min < 10 ? "0" : "") + min; var sec = d.getSeconds(); sec = (sec < 10 ? "0" : "") + sec; document.getElementById("clock").innerHTML = hour + ":" + min + ":" + sec; }

Canvas Interactive Computer Graphics Cha pter

Canvas Primitives Primitives: Rectangles Paths (lines, arcs, bezier curves) Text Images Interactive Computer Graphics Cha pter

Drawing Attributes Canvas is a state machine Attributes Color Fill style Line style Line join Shadow Gradient Pattern Compositing Transformation Interactive Computer Graphics Cha pter

Using Attributes Make all future shapes red with 50% opacity context.fillStyle = "rbga(128,0,0,0.5)"; Draw lines with the following end caps: context.lineJoin = "round"; (why?)why? Use this font for any upcoming text: context.font = "20pt Arial"; Interactive Computer Graphics Cha pter

Coordinate system …but what if I don't like this coordinate system? Interactive Computer Graphics Cha pter (0,0) (400,0) (0,300)

Define a new one! context.setTransform(300,0,0,-300,75,321); Interactive Computer Graphics Cha pter (0,0) (0,1) (1,0)

How would you... Interactive Computer Graphics Cha pter Make an app window with panels? Make a message box? Make the draw button draw? Make a slider? Make the slider control the number of dots drawn? Separate code from presentation?

Typical program structure HTML file defines UI elements CSS file styles everything JS file defines behavior Keeping them separate eases development, maintenance, reuse… Interactive Computer Graphics Cha pter

HTML/JS as dev environment Really the only cross-platform environment In some ways, a step back Class library is small Tools are limited Cross-platform compatibility can be an issue Easy Good development environments coming Cross-platform JavaScript libraries are sprouting like daisies on a grave! Interactive Computer Graphics Cha pter

JavaScript Libraries General purpose, open source (Stats 2011) jQuery (38%, growing fastest) jQuery UI (16%) MooTools (13%) Prototype (12%) Yahoo UI (11%)

jQuery Released in January 2006 Highly effective, concise code Extremely popular, nearly ubiquitous Focus: improving the interaction between JavaScript and HTML finding elements and performing actions smooth animated transitions cross-browser compatibility plug-ins for UI widgets

jQuery Overview Elegant transitions $(“#menu”).slideDown(“slow”); Handling events $(“div”).click(function() { alert(“div clicked”); }); DOM modification $(“#li”).append(“ An item ”); Ajax $(“#results”).load(“myresults.html”);

The jQuery Function $(CSS expression): returns a list of jQuery objects Selectors: css $(“#navbar”) $(“ul.navbar li”) $(“ul.oddevenlist li:even”)

jQuery Attributes Things you can retrieve or set for objects attr() or attr(key, value) – get or set attribute removeAttr(name) hasClass(), addClass(), removeClass(), toggleClass(), toggle() val() or val(val) – get or set contents html(), html(val) – get or set HTML contents text() or text(val) – get or set text contents

How We'll Use jQuery Sierpinski: $ (document).ready(function () { gasket.init(); }); $('#drawbutton').bind('click', gasket.draw); $('#slider1').bind('change', gasket.slider); $('#messages').prepend("Starting point: (" + p.e(1) + "," + p.e(2) + ") "); $('#pointcount').text($('#slider1').val()); Later: $('#toolBar').toggle(); $('#saveImg').attr('src',dataURL); $(this).addClass('selected'); $(this).removeClass('selected'); Interactive Computer Graphics Cha pter

Sylvester Vector and matrix math library Example: var V1 = $V([3,4,5]); var V2 = $V([9,-3,0]); var d = V1.dot(V2); // d is 15 var c = V1.cross(V2); // c is the vector (15,45,-45) Interactive Computer Graphics Cha pter

Gasket using paths? Draw a triangle of depth d: Base case? If d=0, draw a solid triangle Recursive steps? Divide the triangle into 4 smaller triangles Recursively draw a triangle in each of the three outer sub- triangles, at depth d-1 How to compute the midpoint of a line seg? Linear combination (average) of endpoints How to do this in HTML Canvas? Interactive Computer Graphics Cha pter

Chapter 2 summary We'll use HTML, Canvas, JavaScript, jQuery, Sylvester Primitives supported by Canvas: rectangles, text, paths, images Canvas is a state machine; can set attributes for future drawing Canvas event loop: event handlers. If necessary, recompute/redisplay every few milliseconds Interactive Computer Graphics Cha pter