Building a Visualization Language

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    14 Favorites, 1 Group & 1 Event

    Building a Visualization Language - Presentation Transcript

    1. Building a Visualization Language John Resig http://ejohn.org/ - http://twitter.com/jeresig
    2. Topics ✦ Canvas ✦ Processing ✦ Processing.js
    3. Canvas ✦ Proposed and first implemented by Apple in WebKit ✦ A 2d drawing layer ✦ With possibilities for future expansion ✦ Embedded in web pages (looks and behaves like an img element)
    4. Shapes and Paths ✦ NOT vectors (unlike SVG) ✦ Rectangles ✦ Arcs ✦ Lines ✦ Curves ✦ Charts:
    5. Fill and Stroke ✦ All can be styled (similar to CSS) ✦ Stroke styles the path (or outline) ✦ Fill is the color of the interior ✦ Sparklines:
    6. Canvas Demo
    7. Canvas Embedding ✦ Canvases can consume: ✦ Images ✦ Other Canvases ✦ Will be able to consume (Firefox 3.1): ✦ Video ✦ In an extension: ✦ Web Pages
    8. Processing ✦ Data Visualization programming language ✦ Built on top of Java ✦ Can do 2d and 3d ✦ Many libraries (manipulate video, images, audio)
    9. The Language ✦ Strictly typed ✦ Has classes, inheritance ✦ A bunch of globally-accessible functions ✦ (Very flat API) ✦ setup() and draw() methods ✦ Very OpenGL-like ✦ draw() is called continually at a specific framerate
    10. Draw A Line w/ Mouse ✦ While you hold the mouse down, draw a line from the previous mouse point ✦ Topics > Drawing > Continuous Line ✦ void setup() { size(200, 200); background(102); } void draw() { stroke(255); if(mousePressed) { line(mouseX, mouseY, pmouseX, pmouseY); } }
    11. Initialization ✦ setup() is called initially ✦ size(...) set the width/height of the drawing area ✦ Call any other number of methods, such as: ✦ background(...) - draw and fill a background ✦ void setup() { size(200, 200); background(102); }
    12. draw() loop ✦ draw() gets called as fast as possible, unless a frameRate is specified ✦ stroke() sets color of drawing outline ✦ fill() sets inside color of drawing ✦ mousePressed is true if mouse is down ✦ mouseX, mouseY - mouse position ✦ void draw() { stroke(255); if(mousePressed) { line(mouseX, mouseY, pmouseX, pmouseY); } }
    13. Drawing ✦ Different drawing methods: ✦ line() ✦ rect() ✦ arc() ✦ ellipse() ✦ point() ✦ quad() ✦ triangle() ✦ bezier() ✦ All use stroke(), strokeWeight(), fill()
    14. The Drawing Area ✦ Just like Canvas! ✦ Mutate the canvas rendering: ✦ translate() ✦ scale() ✦ rotate() ✦ Save and Restore the state of the canvas: ✦ pushMatrix() ✦ popMatrix() ✦ Demo: Basics > Transform > Arm
    15. Shapes ✦ A series of vertices, built into a shape ✦ fill(127); beginShape(); for (int i=0; i<segments; i++){ vertex(ground[i].x1, ground[i].y1); vertex(ground[i].x2, ground[i].y2); } vertex(ground[segments-1].x2, height); vertex(ground[0].x1, height); endShape(CLOSE);
    16. Classes ✦ Hold data, do inheritance ✦ Demo: Topics > Motion > Reflection 2 ✦ class Ground { float x1, y1, x2, y2, x, y, len, rot; Ground(){ } Ground(float x1, float y1, float x2, float y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; x = (x1+x2)/2; y = (y1+y2)/2; len = dist(x1, y1, x2, y2); rot = atan2((y2-y1), (x2-x1)); } }
    17. Math functions ✦ dist(), map(), constrain(), abs(), floor(), ceil() ✦ random(), noise() ✦ atan2(), cos(), sin(), pow(), sqrt() ✦ radians()
    18. Images ✦ Load in external images ✦ Demo: Topics > Animation > Sequential ✦ int numFrames = 12; // The number of frames in the animation int frame = 0; PImage[] images = new PImage[numFrames]; void setup(){ size(200, 200); frameRate(30); for(int i=0; i<numFrames; i++) { String imageName = \"PT_anim\" + nf(i, 4) + \".gif\"; images[i] = loadImage(imageName); } } void draw() { frame = (frame+1)%numFrames; image(images[frame], 0, 0); }
    19. Processing Demos ✦ http://acg.media.mit.edu/people/fry/ zipdecode/ ✦ http://complexification.net/gallery/ machines/substrate/ ✦ http://sublimeguile.com/processing/ tree_071017b/ ✦ http://vimeo.com/311550
    20. Processing.js ✦ How do we run Processing on web pages? ✦ Applets suck ✦ Processing: Convert Processing to JavaScript and run on Canvas ✦ Two stages: ✦ Language Conversion ✦ Processing API
    21. Ported to JS ✦ Released in May: http://ejohn.org/apps/processing.js/ ✦ Port of the Processing Language + the 2d Processing API ✦ All runs in JavaScript on top of HTML 5 Canvas ✦ Works in all browsers (IE with excanvas)
    22. Porting ✦ The API ✦ Rather straight-forward ✦ 1-to-1 mapping of Processing to Canvas ✦ The Language ✦ Much more complicated ✦ Parse the full language ✦ (lots of Regular Expressions)
    23. Previous Demos ✦ http://ejohn.org/apps/processing.js/examples/topics/continuouslines.html ✦ http://ejohn.org/apps/processing.js/examples/basic/arm.html ✦ http://ejohn.org/apps/processing.js/examples/topics/reflection2.html ✦ http://ejohn.org/apps/processing.js/examples/topics/sequential.html
    24. Processing.js Demos ✦ http://ejohn.org/apps/processing.js/examples/custom/snake.html ✦ http://ejohn.org/apps/processing.js/examples/custom/molten.html ✦ http://ejohn.org/apps/processing.js/examples/basic/ ✦ Recursion ✦ Distance 2D ✦ Random ✦ http://ejohn.org/apps/processing.js/examples/topics/ ✦ Soft Body ✦ Flocking ✦ Tree ✦ http://ejohn.org/apps/hero/

    + jeresigjeresig, 2 years ago

    custom

    7185 views, 14 favs, 33 embeds more stats

    A talk I gave September 2008 at the Web 2.0 Expo in more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 7185
      • 4981 on SlideShare
      • 2204 from embeds
    • Comments 0
    • Favorites 14
    • Downloads 155
    Most viewed embeds
    • 1985 views on http://ajaxian.com
    • 84 views on http://www.schockwellenreiter.de
    • 41 views on http://www.cognitiones.de
    • 27 views on http://www.julien-verkest.fr
    • 11 views on http://schockwellenreiter.de

    more

    All embeds
    • 1985 views on http://ajaxian.com
    • 84 views on http://www.schockwellenreiter.de
    • 41 views on http://www.cognitiones.de
    • 27 views on http://www.julien-verkest.fr
    • 11 views on http://schockwellenreiter.de
    • 9 views on http://extjs.com
    • 9 views on http://www.hanrss.com
    • 6 views on http://feeds.feedburner.com
    • 4 views on http://andreas.materns.com
    • 4 views on http://bloggbotter.blogspot.com
    • 2 views on http://secondseminar.tumblr.com
    • 1 views on http://touchit.co.kr
    • 1 views on http://www.extjs.com
    • 1 views on http://arts9.com
    • 1 views on http://alt.readmix.local:8400
    • 1 views on http://webprog.yozmn.com
    • 1 views on applewebdata://2375935C-BF0E-4CCA-98CE-B7A3404614C5
    • 1 views on http://sdes1lnx:20063
    • 1 views on https://confluence.uk.jpmorgan.com
    • 1 views on http://www.zhuaxia.com
    • 1 views on http://localhost:8080
    • 1 views on http://www.kantel.de
    • 1 views on https://craftler.dyndns.org:1111
    • 1 views on http://www.ajaxian.com
    • 1 views on http://ejohn.org
    • 1 views on http://www.msdesign.de
    • 1 views on http://mjesec.ffzg.hr
    • 1 views on resource://brief-content
    • 1 views on applewebdata://00714FDC-D5B0-49B8-8CD0-AB803DCABBCE
    • 1 views on https://culearn.colorado.edu
    • 1 views on http://bigred:8888
    • 1 views on http://www.ajax-blog.com
    • 1 views on http://2105.tumblr.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories