My code not working in javascript mode, please help.

edited February 2014 in JavaScript Mode

This is the link openprocessing.org/sketch/132755.

It works in Java mode, but not Javascript mode.

Tagged:

Answers

  • edited February 2014 Answer ✓

    JS Mode is still from the time when Java Mode was @ version 1.5.1! @-)
    So many new Processing 2+ features like constant TAU doesn't exist there! 8-X
    So if your code can run under Processing v1.5.1, it's half the way to reach JS Mode conversion success! >-)

    In your case there, just replace TAU for TWO_PI and you're done! (*)
    Anyways, I've made a clean-up version from yours as well: :bz

    // forum.processing.org/two/discussion/2936/
    // my-code-not-working-in-javascript-mode-please-help-
    
    size(500, 300);
    noLoop();
    smooth(4);
    background(-1);
    
    strokeWeight(10);
    noFill();
    
    final float SIXTH_PI = THIRD_PI/2.;
    
    // Round 1:
    stroke(0, 122, 201); //blue
    arc(100, 100, 120, 120, 0, TWO_PI);
    
    stroke(255, 161, 0); //yellow
    arc(100+64+5, 100+60, 120, 120, 0, TWO_PI);
    
    stroke(0); //black
    arc(100+128+15, 100, 120, 120, 0, TWO_PI);
    
    stroke(0, 155, 58); //green
    arc(100+192+20, 100+60, 120, 120, 0, TWO_PI);
    
    stroke(225, 14, 73); //red
    arc(100+256+30, 100, 120, 120, 0, TWO_PI);
    
    // Round 2:
    stroke(0, 122, 201); //blue
    arc(100, 100, 120, 120, -THIRD_PI, THIRD_PI);
    
    stroke(255, 161, 0); //yellow
    arc(100+64+5, 100+60, 120, 120, PI - SIXTH_PI, PI + THIRD_PI);
    arc(100+64+5, 100+60, 120, 120, PI + HALF_PI, PI + HALF_PI + THIRD_PI);
    
    stroke(0, 0, 0); //black
    arc(100+128+15, 100, 120, 120, HALF_PI, HALF_PI + THIRD_PI);
    arc(100+128+15, 100, 120, 120, -SIXTH_PI, THIRD_PI);
    
    stroke(0, 155, 58); //green
    arc(100+192+20, 100+60, 120, 120, PI - SIXTH_PI, PI + THIRD_PI);
    arc(100+192+20, 100+60, 120, 120, PI + HALF_PI, PI + HALF_PI + THIRD_PI);
    
    stroke(225, 14, 73); //red
    arc(100+256+30, 100, 120, 120, HALF_PI - SIXTH_PI, HALF_PI + THIRD_PI);
    
  • Thanks! I change all TAU to TWO_PI, and it works.

Sign In or Register to comment.