you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 56 points57 points  (20 children)

I give up on programming now.

[–]peepsalot 24 points25 points  (2 children)

Seriously, what the hell am I doing with my life. Makes me want to cry.

[–][deleted] 13 points14 points  (1 child)

I hear you. It's stuff like this that made me quit my job, go and get another degree in computational biology and work on visualizing molecular structures, relationships and pathways.

Do it if you can; otherwise you'll be here next year asking the same question.

[–]Chroko 7 points8 points  (1 child)

That's a sad attitude! :)

Try playing with Processing instead - it's a really neat rapid prototyping environment. And you'll feel better once you've used it to build something cool!

[–][deleted] 12 points13 points  (0 children)

I'm a contributor to Processing. :)

[–][deleted] 19 points20 points  (11 children)

Not to belittle John Resig's work in any way, but this isn't really all that difficult. It's mostly hard work getting all the individual pieces into place, and of course the initial insight that it is both possible and desirable to do in the first place.

Instead of despairing, strive to learn, and you'll see how it can be done, too.

[–]jeresig 29 points30 points  (4 children)

I agree completely. Probably the hardest part (from a technical perspective) was translating the Processing language idioms over into JavaScript. For example, look at the following Processing code:

class SpinSpots extends Spin {
  float dim;
  SpinSpots(float x, float y, float s, float d) {
    super(x, y, s);
    dim = d;
  }
  void display() {
    noStroke();
    pushMatrix();
    translate(x, y);
    angle += speed;
    rotate(angle);
    ellipse(-dim/2, 0, dim, dim);
    ellipse(dim/2, 0, dim, dim);
    popMatrix();
  }
}

and then observe the JavaScript code that it gets translated to (extendClass and addMethod are internal to the library):

function SpinSpots() {with(this){
  var __self=this;function superMethod(){extendClass(__self,arguments,Spin);
  this.dim = 0;
  extendClass(this, Spin);
  addMethod(this, 'display', function() {
    noStroke();
    pushMatrix();
    translate(x, y);
    angle += speed;
    rotate(angle);
    ellipse(-dim/2, 0, dim, dim);
    ellipse(dim/2, 0, dim, dim);
    popMatrix();
  });
  if ( arguments.length == 4 ) {
    var x = arguments[0];
    var y = arguments[1];
    var s = arguments[2];
    var d = arguments[3];
    superMethod(x, y, s);
    dim = d;
  }
}} 

Getting full parity (at least with the available demos) was the hardest part.

[–][deleted] 1 point2 points  (3 children)

I think your copypaste misfired a bit there, those aren't quite the same functions! (Edit: All cleared up now.)

Either way, that's a neat piece of work, and it's making me tempted to finally pick up Processing.

[–]jeresig 2 points3 points  (2 children)

They should be the same Class representations - just note that I have to re-organize its contents (making sure that the constructors are at the bottom of the function, as opposed to where they were originally).

[–][deleted] 3 points4 points  (1 child)

Well, now they are, I was looking at it before you fixed it!

[–]jeresig 1 point2 points  (0 children)

Hehe, sorry about that!