Slashdot Mirror


Processing Visualization Language Ported To Javascript

Manfre writes "On his birthday, John Resig (creator of jQuery) has given a present to developers by releasing Processing.js. This is a Javascript port of the Processing Visualization Language and a first step towards Javascript being a rival to Flash for online graphics content. His blog post contains an excellent writeup with many demos."

47 of 171 comments (clear)

  1. Heh AvP comes ot mind here by Uncle+Focker · · Score: 4, Funny

    This is a Javascript port of the Processing Visualization Language and a first step towards Javascript being a rival to Flash for online graphics content. Whoever wins, we lose.
    1. Re:Heh AvP comes ot mind here by Anonymous Coward · · Score: 4, Insightful

      You lose anyway. You and the rest of the "ASCII text forever" crowd don't speak for me.

    2. Re:Heh AvP comes ot mind here by edalytical · · Score: 5, Funny

      Score one for the "UTF-8 text forever" crowd. Thanks for the support!

      --
      Win a signed Stephen Carpenter ESP Guitar from the Deftones: http://def-tag.com/?r=0008781
    3. Re:Heh AvP comes ot mind here by Uncle+Focker · · Score: 2, Interesting

      You lose anyway. It comes with the territory.

      You and the rest of the "ASCII text forever" crowd don't speak for me. And this crowd, whose membership I've been forced into against my will, doesn't speak for me either.
    4. Re:Heh AvP comes ot mind here by rbanffy · · Score: 2, Insightful

      All we need is a decent and fast implementation of JavaScript. Apple seems to have a nice one in Safari that appears decent in Midori/Webkit.

      And, BTW, we need one badly, because the Flash (I don't trust Adobe) and Silverlight (I don't trust MS) crowds are coming and won't wait for a fast JavaScript engine.

    5. Re:Heh AvP comes ot mind here by Paradise+Pete · · Score: 4, Funny
      And this crowd, whose membership I've been forced into against my will, doesn't speak for me either.

      4F682079657320776520646F2E

    6. Re:Heh AvP comes ot mind here by Uncle+Focker · · Score: 2, Funny

      4F682079657320776520646F2E You do not!!! Damn you hex text bastards!
    7. Re:Heh AvP comes ot mind here by Chris+Burkhardt · · Score: 2, Funny

      You lose anyway. You and the rest of the "ASCII text forever" crowd don't speak for me.

      The don't speak for me either. I'm really getting into this UTF-8 stuff lately.

      --
      "And there be unix which have made themselves unix for the kingdom of heaven's sake." - Matt. 19:12
  2. 'polished turd' by teknopurge · · Score: 3, Insightful

    This is some great work....

    but this is like a polished-turd. Flash doesn't exist anymore to do animation or dynamic graphics, it exists to run fast. JS engines were not designed to process this kind of data efficiently, as seen by your CPU graph when running the demos.

    I don't want to take away from the work, because it's a slick hack, but it's not the right tool for this job.

    Regards,

    1. Re:'polished turd' by AKAImBatman · · Score: 5, Insightful

      Flash doesn't exist anymore to do animation or dynamic graphics, it exists to run fast.

      Wait, are we talking about the same Flash? Because I've done a lot of Flash and Actionscripting, and "Fast" is not even in the vocabulary. Software rendered graphics pipeline? Check. Slow VM interpreter that makes Java 1.0 look fast? Check. Lack of direct rendering APIs? Check. Focus on animation at the expense of dynamic scene creation? Check.

      Granted, Flash 9 is a major improvement, but it is arriving rather late in the game.
    2. Re:'polished turd' by Uncle+Focker · · Score: 2, Funny

      Flash doesn't exist anymore to do animation or dynamic graphics, it exists to run fast. So when is Adobe finally going to get around to meeting that goal?
    3. Re:'polished turd' by AKAImBatman · · Score: 5, Interesting

      Check out http://varriastudios.com/ for a site that illustrates what I'm talking about.

      A user interface? I think you have a very odd definition of "Fast". All you've proven is that Flash is designed to do pretty animations. Well, that's kind of the point. Not to run "Fast". "Fast" was never a part of the design. Just look up the "Actions" portion of the Flash 8 spec sometime and you'll be utterly horrified.

      That being said, Flash does do animations well. That's what it was designed for. As a result, it has even been used to create games. It never did games all that well, but Moore's law eventually made it possible to come up with some fairly decent stuff.

      Of course, if you're referring to "my Flash animations move faster than my DHTML animation", that's just plain user-error. The Flash animations work better because Flash Studio works out all the timings of the motions for you. If you Actionscripted your motions, they'd come out about the same as they would in Javascript. (And being nearly the same language, it's possible to try the same motion code in both.)

      This issue is what the Javascript PVL is intended to solve. i.e. A standard framework for providing animation/motion with minimal input from the developer.
    4. Re:'polished turd' by AKAImBatman · · Score: 4, Insightful

      JS interpreters are not optimized to do image manipulation, DOM updates, etc.

      Whiskey Tango Foxtrot. Optimized for image manipulation? You do absolutely ZERO image manipulation in Javascript. Same with Actionscript. All that is pushed down into the Canvas and Flash rendering engines, respectively. Same thing with DOM manipulations. Sure, you say "insert this item" or "delete this object", but it's the C/C++ engine under the covers that does the heavy lifting.

      People haven't done their own image manipulation since Amigas stomped the earth.

      Right now it's always faster(CPU %) to do an animation in Flash then it is to do the same animation in JS.

      You make that statement, yet you posted a benchmark that showed Javascript to be faster than Flash. I'm rather confused. You do realize that the benchmark you posted below was in millisecond and not operations per second, right? i.e. Lower is better.

      You have zero evidence for your statements. Listen to someone who actually knows something about these platforms. There's no reason why Javascript can't perform the same function as Flash using the Canvas APIs. And you know what? That's not a bad thing. :-)
    5. Re:'polished turd' by kestasjk · · Score: 3, Interesting

      JS engines aren't currently designed for it, but this is what Canvas (and a lot of HTML5) is all about..

      If you prefer think of this as Processing on Canvas, rather than Processing on JavaScript, because Canvas is the enabling technology here.

      And I don't know where you get off calling it a "polished turd". (Makes me want to poke around your homepage-vertisement, and see if you have a right to make those judgements)

      The Java requirement was always a pain to deal with before, and this "polished turd" removes that and makes visualizations much more portable and easier to play around with.

      Also the moving visualizations have always been CPU intensive, that's the nature of what they are; they're supposed to be easy to create visualizations of data, it's not a video game. It was like this on Java too.
      Note that the static practical visualizations, which take dynamic data, draw the visualization and then end, need much less CPU than dynamic ones like you might see in a flashy demo.

      This is a very good thing, and a very welcome surprise; Processing really does offer something that's pretty unique, and I look forward to seeing more of it. Kudos Resig

      --
      // MD_Update(&m,buf,j);
    6. Re:'polished turd' by AKAImBatman · · Score: 5, Insightful

      I mentioned this above, but I'll reiterate it here. In that benchmark, LOWER IS BETTER. The brand-new Flash 9 VM engine did excellent (as I expected it would), but the Flash 7 and 8 engines were generally creamed by the Javascript engines. Which I don't think is what you're trying to prove at all.

      The secret to the performance of Flash 9 is this little beauty: http://www.mozilla.org/projects/tamarin/

      A fully modern, high-performance, Just In Time compiler that gives the JVM a run for its money. It's an amazing piece of Javascript technology that Adobe has donated to the Mozilla project for inclusion in the next major revision of FireFox. Wonderful, wonderful engine that absolutely no one is using yet.

      See, if you compiled to Flash 7 or 8, you're still triggering the Flash 8 engine. The Flash 9 engine is a complete rewrite that only works with Flash 9 content. So the next chapter of performance wars has yet to be written.

      Q.E.D.

    7. Re:'polished turd' by teknopurge · · Score: 2, Informative
      Please check that link again as it appears you ahve misread it.

      Lower is better. Got it.

      Array join (array size 1000, 500 iterations)
      JS: FF2 - 375ms, Flash - 303ms

      substring (10000 iterations)
      JS: FF2 - 16ms, Flash - 3ms

      Did you look at the link I posted at all? Even the older versions of Flash were split with JS ~50/50 on the various datapoints.

      I'm not implying it's a bad thing to try, but seriously. Did you even look at the JS code that is your "framework" to this stuff? Let me grab you a piece:


          do {
                          v1 = 2 * p.random(1) - 1; // between -1.0 and 1.0
                          v2 = 2 * p.random(1) - 1; // between -1.0 and 1.0
                          s = v1 * v1 + v2 * v2;
                      } while (s >= 1 || s == 0);
                      var multiplier = Math.sqrt(-2 * Math.log(s)/s);
                      nextNextGaussian = v2 * multiplier;
                      haveNextNextGaussian = true;

                      return v1 * multiplier;


      The JS engines are not optimized to do the above. Sure they will do it, but not with any semblance of efficiency.
    8. Re:'polished turd' by frosky · · Score: 3, Insightful

      As a longtime Flash developer i can also tell you that wether u use it for animation, GUIs or for basic web apps, the primary appeal to people like me was that Macromedia created avery easy to learn authoring environment. And even as the application grew to include programming and such, its concept of timeline, tweens, movieclips, etc. was far simpler to learn than the alternatives - including MM Director. To me that is the core strength of Flash. So whoever attempts to compete should take that into consideration. Before Adobe acquired MM they failed miserably at competing because they had a very clunky authoring environment (at least as noted by most of my developer peers at the time)

    9. Re:'polished turd' by AKAImBatman · · Score: 2, Insightful

      Please check that link again as it appears you ahve misread it.

      Actually, you should check my post below as I explained in detail why Flash lost that handily. The short version is that Flash 9 is not comparable right now because the VM is not in use by many projects. By the time it's in heavy use, FireFox will be using the exact same engine.

      Did you even look at the JS code that is your "framework" to this stuff?

      Sure. And the piece you picked (like most of the code) is motion computations. The piece you picked does a handful of mulitplies and library (fast!) calls for log, random, and square root. That *could* be heavily optimized with lookup tables, but there wouldn't be much point. That's not even a blip on the processor's time. All the real work is done in the Canvas API calls where the blitting happens.

      There is no image manipulation in Javascript or Actionscript. The computations you see could be faster if Javascript had true primitive support, but at the end of the day it just doesn't matter. I know that because that was optimization 101 back when we developers had to write our own 3D engines. A routine that runs once per frame is far less of a concern than a routine that runs once a line or even once a pixel! Moore's law has continued to reinforce that truth. :-)
    10. Re:'polished turd' by AKAImBatman · · Score: 2, Informative

      I think you missed the point. If your Flash code is not compiled for Flash 9, Tamarin is not used. The old Flash 8 engine gets loaded instead. Since the vast majority of Flash content is still Flash 8, no one is using Flash 9. :-)

    11. Re:'polished turd' by kestasjk · · Score: 2, Insightful

      Conway's game of life isn't a very realistic use case, a large bit-array with lots of sequential reads/writes. It's always going to be a CPU-bound task, no matter what optimization it gets More interesting and realistic are the graphical demos, which show off Canvas. The ones which draw something in Canvas and then do nothing more are probably the most realistic real-world-like demos, and they shouldn't cripple anything.

      --
      // MD_Update(&m,buf,j);
    12. Re:'polished turd' by AKAImBatman · · Score: 2, Interesting

      With the increasing number of Flex developers and Flash developers switching over to AS3 and the Flash 9 AVM2 engine
      Who still haven't produced a critical mass of software yet. In fact, there are very few Flex sites in existence. Adobe's exit from the J2EE market hasn't helped their case one bit.

      Check out all those flash sites that use papervision3d, a 3D software renderer for Flash. That's all Flash 9 AS3.
      Papervision 3D was created for Flash 8 and ported to Flash 9. If you see a Papervision app, there's a good chance it's Flash 8.

      [Flex is] growing as an alternative to AJAX because AJAX eats a crapload of bandwidth since the Javascript code and XML aren't compressed.
      AJAX uses as much or as little bandwidth as you design it to. (That's one of the reasons why JSON is becoming a popular alternative to XML.) Flex will happily chew just as much bandwidth if you design it to do so. In fact, if you use the object remoting features, you're likely to use a lot MORE bandwidth due to the nature of distributed objects.

      Oh, and my company compresses the hell out of our Javascript and XML. Seems this little thing called GZip compression is supported by every major browser on the market. Who'da'thunk, eh?

      Moreover, your front-end code is visible in AJAX.
      You don't really know a whole lot about AS3, do you? Like, for example, it's stupidly easy to decompile the code. Worrying about someone having access to your source is so 1990's. You had better get over it, because your source is open for the world to see. That goes for Java, Javascript, Actionscript, C#, and just about any other modern language you can think of.

      you sir, are talking out of your ass.
      Classic case of pot and kettle. Please get your facts straight before being so rude in the future. It really is upsetting and therefore tempting to use rather abusive language in return.
    13. Re:'polished turd' by BungaDunga · · Score: 2, Informative

      The AS2 version of Papervision has basically been discontinued: all the shiny stuff is in the AS3 version. There's quite an incentive to run it in AS3, because it's relatively fast compared to the old AVM. Since I started messing around in PV3D I've switched entirely to AS3: it's not really much of a change in coding style.

  3. Second Step by AKAImBatman · · Score: 5, Informative

    This is a Javascript port of the Processing Visualization Language and a first step towards Javascript being a rival to Flash for online graphics content.

    Second step, actually. Apple and the WHATWG took the first step by introducing the Canvas API to the HTML 5 spec. That gave web developers the ability to do Flash-like content. This language is the second step, in that it gives programmers a standard framework from which to create impressive animations.

    Kudos to Mr. Resig on a job well done! I can't wait to play around with this project more. :-)
  4. Re:My Post by LighterShadeOfBlack · · Score: 5, Funny

    First of all... you got second post. Second of all, TFA is about Javascript, not Java.

    Other than that your post was completely relevant.

    --
    Spelling mistakes, grammatical errors, and stupid comments are intentional.
  5. Flash is just Adobe Javascript by Anonymous Coward · · Score: 4, Informative

    Flash itself uses a dialect of ECMAScript (the common parent language of Javascript and ActionScript). So your assertion that Javascript engines were not written to do this is flat out wrong.

    All this shows is just how terrible most browser's Javascript engines really are. Notice, modern browsers do considerably better on these demos than older ones, mainly because so much of the web has shifted to using Javascript and dynamic content, such that JS becomes a limiting factor in usability. Once JS engines have caught up to ActionScript in speed, what more use do we have for Flash? We already have Mozilla working to make use of the Tamarin byte-code engine, which will turn JS from being a slow, interpreted language into being a byte-code compiled language (speed on the order of modern scripting languages such as Python/Ruby and to some extent Java/C#).

    So sorry, Javascript is the right tool for the job. It's the only tool for the job as far as Open Standards are concerned.

  6. Not going to happen by stonecypher · · Score: 3, Insightful

    The primary strength of Flash is its single vendor, rigorously portable, rigorously backwards compatible runtime. Javascript is far too fragmented to be a competitor to flash.

    --
    StoneCypher is Full of BS
    1. Re:Not going to happen by ozamosi · · Score: 4, Insightful

      I know, and so does everyone else.

      You know, I recently heard about a project by John Resig (creator of jQuery) called Processing.js. It's a Javascript port of the Processing Visualization Language, which means it could be viewd as a rival to Flash for online graphics content.

      You should check out his blog post

      In case the sarcasm wasn't obvious enough: that's one of the most important things that Javascript libraries solve

    2. Re:Not going to happen by MightyYar · · Score: 2, Informative

      Javascript is far too fragmented to be a competitor to flash. The author's most famous project, jQuery, addresses this weakness, though. It is a smallish framework that does a very good job abstracting you from the browser-to-browser differences in Javascript.

      I haven't played with this new toy of his, but it stands to reason that he'll take the same care with it that he did with jQuery.

      In other words, Javascript may be too fragmented, but this Processing language is not... and you write your code in Processing, not Javascript.
      --
      W..w..W - Willy Waterloo washes Warren Wiggins who is washing Waldo Woo.
    3. Re:Not going to happen by Arslan+ibn+Da'ud · · Score: 2, Funny
      In case the sarcasm wasn't obvious enough: that's one of the most important things that Javascript libraries solve


      Wow! A library that helps people detect sarcasm...that IS a killer feature!!!

      --

      Practice Kind Randomness and Beautiful Acts of Nonsense.

  7. Re:Rival?! by AKAImBatman · · Score: 4, Informative

    The article submitter has clearly never actually used the HTML canvas object.

    Oh? I have, and I don't disagree. Of course, I've USED Flash quite a bit too, so I know how God-aweful slow that platform was up until version 9. ;-)

    There's no way in HELL canvas & javascript together could ever approach the render and execution performance of Flash.

    Why not? Flash == Software renderer. Canvas == Software renderer. Actionscript == ECMAScript engine. Javascript == ECMAScript engine. I'm not seeing the issue.

    Hell, once FireFox is on the Tamarin engine, the two platforms will be practically the same!
  8. Eric by erickhill · · Score: 5, Insightful

    Regardless if this is usable today for client work, this is insane stuff. The first iteration of Flash eons ago had plenty of nay-sayers. He made this over the course of seven months? Bow down, I say. Very impressive.

  9. Re:My Post by maxume · · Score: 2, Funny

    Well muddled.

    --
    Nerd rage is the funniest rage.
  10. Re:Creator of WHAT?! by grahamd0 · · Score: 5, Insightful

    Can someone please explain to me why anyone would regard jquery as a black mark on John Resig's work?

    I've found it very useful for anything but the most mundane js tasks. Certainly better than the piles of other libraries that all seem to be based around the fallacy that javascript needs classical inheritance. (Hint: It doesn't. It has prototypal inheritance.)

  11. Re:My Post by Anonymous Coward · · Score: 3, Informative

    I am sick and tired of people confusing Java and javascript. They are not the same language. They are not even related languages. javascript is crappy scripting language for use with HTML. It is run my the browser and aids in display time processing. Java is a full blown object oriented programming language which runs on the Java Virtual Machine. Sine the JVM handles interfacing with the operating system Java itself is mostly platform independent.

  12. Re:Creator of WHAT?! by grahamd0 · · Score: 4, Insightful

    Actually, I said it was useful for anything except the most mundane tasks (where the overhead of loading a library is not justified by the task).

  13. Re:My Post by truthsearch · · Score: 5, Funny

    Jules: Whoa, whoa, whoa, whoa... stop right there. Javascript and Java ain't even the same fsckin' thing.
    Vincent: It's not. It's the same ballpark.
    Jules: Ain't no fsckin' ballpark neither. Now look, maybe your method of programming differs from mine, but, you know, writing a web page, and coding for the JVM, ain't the same fsckin' ballpark, it ain't the same league, it ain't even the same fsckin' sport. Look, Javascript don't mean shit.

  14. Other than that, Mrs. Lincoln, how was the play? by Em+Ellel · · Score: 4, Insightful

    Thus, anything outside of the above (images, pixel processing, and text) should work "ok" everywhere. Is it just me or does graphical language that does not fully support image, pixel, or text processing seems a bit.... silly.

    Don't get me wrong, I think its a cool toy I will be playing with, but until it actually works in more than one beta browser, its is no threat to Flash at all.

    -Em
    --
    RelevantElephants: A Somatic WebComic...
  15. Re:Rival?! by Manfre · · Score: 2, Informative

    The article submitter has clearly never actually used the HTML canvas object. There's no way in HELL canvas & javascript together could ever approach the render and execution performance of Flash.

    I have used the HTML canvas object. It's not on par with Flash 9, which is why I wrote "a first step towards Javascript being a rival to Flash". I styled that to help you with reading comprehension. Processing.js is an enabler that will lower the bar for many developers and give it the attention needed to improve the weaknesses that exist.
  16. Re:My Post by fuzzy12345 · · Score: 5, Insightful

    javascript is crappy scripting language for use with HTML. [...] Java is a full blown object oriented programming language I think you meant to say "Javascript is a full blown power-users' language, basically Lisp but with syntax problems, whereas Java is a crappy low-level language; the COBOL of the millenium."
    --

    Everybody's a libertarian 'till their neighbour's becomes a crack house.
  17. Re:My Post by compro01 · · Score: 4, Interesting

    COBOL is still alive and kicking in the financial sector and it's fairly decent for what it's designed to do. i really wouldn't want to use it for general programming, but i wouldn't want to write a payroll app in C++ either.

    --
    upon the advice of my lawyer, i have no sig at this time
  18. Re:My Post by ardor · · Score: 2, Informative

    Except that Javascript is much more powerful than Java can ever hope to be. It's the environment thats crappy, not the language.

    Seriously, you should at least *understand* the languages before you talk nonsense.

    --
    This sig does not contain any SCO code.
  19. Re:My Post by Free+the+Cowards · · Score: 3, Insightful

    So you mean it's highly ubiquitous language with 100s of billions of lines of code written in it that spreads over innumerable applications? Pretty much. Both Java and COBOL blow great big donkey chunks, but they're both used all over the place. They both have this great property of making it difficult to shoot yourself in the foot, which makes it practical to unleash hordes of medium/low quality programmers on a code base and actually come up with something that kinda sorta works.
    --
    If you mod me Overrated, you are admitting that you have no penis.
  20. Re:My Post by bb5ch39t · · Score: 2, Informative

    Which was part of the design criteria for COBOL. It was so that "low level" (PFC) military "grunts" could write code that would work.

  21. Re:My Post by tkinnun0 · · Score: 2, Informative

    Java is a crappy low-level language Java's a low level language? That's news to me. Well, yeah, before Java 5 with its generics, autoboxing and the rest, that was pretty much the case. Much like C is a low-level language to produce assembler code, Java was (and mostly still is) a low-level language to produce JVM byte-code. If you take ever take a look at results of javap -c on a simple method you'll see what I mean.
  22. Re:My Post by tkinnun0 · · Score: 2, Insightful

    You nowhere near describing a stackbased cpu with the java language, it's not low level, ok? Ummm, the Java byte-code is the embodiment of a stack based language, what with its operand stack and stack frames. You would have a point, if you had insisted on a register-based cpu...

    if you ever done low lewel you know what I mean I haven't written, but I have read enough assembler to see a disturbing amount of similarities: unconditional jumps, labels, bitwise arithmetic operations, reading and writing to registers (local variables). Sure, there is more freedom when it comes to declaring the operands for any instruction. Sure, the JVM checks the bounds of your array access. But compared to a modern CPU, I'd imagine that's peanuts.
  23. Re:My Post by SanityInAnarchy · · Score: 2, Interesting

    That's funny.

    Maybe you should actually look up the very history of Javascript -- the programmer wanted an embedded LISP. Some PHB-type wanted it to look like C, so it would be more approachable. So he took his embedded LISP and gave it a C-like syntax.

    Or maybe you should've Googled about Lisp and Javascript. Here, go read.

    --
    Don't thank God, thank a doctor!
  24. VM not in use by many projects?! by nova_ostrich · · Score: 2, Informative

    The short version is that Flash 9 is not comparable right now because the VM is not in use by many projects.

    Are you serious? As a software engineer who works with Flash and Flex daily, I've worked exclusively with Flash Player 9 and ActionScript 3 for over two years. Almost anyone who calls him or herself a Flash developer will say the same. I might have let your argument slide a year ago, but with Flash Player 9 installed on well over 90% of web-connected computers, it's silly not to use AS3. Anyone still working with AS2 and Flash 8 is probably a designer building simple "experience sites" or advertisements who knows a little about coding or a developer who doesn't know any better (or is a masochist).

    --
    It's scary being a Flash and Flex developer on Slashdot. You guys are unnaturally rabid.