Problems converting to javascript for openprocessing

Hi, having problems converting this sketch from java into JavaScript.

Works fine when I run normally in java.

When I run in JavaScript, the colors are all messed up, supposed to be black and white but everything looks warped.

I think it may have something to do with the noise in my sketch but not sure..

I have EVERYTHING updated, browser, java, processing... not sure what to do? anyway to fix this?

Thank you.

Answers

  • edited July 2014

    Which sketch btW? :-/
    Anyways, it indeed seems that JS's noise() implementation doesn't match Java's! @-)

    There's this "Random Tiled Terrain Generator" based on noise():
    http://forum.processing.org/two/discussion/5985/how-can-a-roguelike-have-so-large-maps

    When run in Java Mode, a reasonable amount of brown ^ "mountain" chars show up.
    However, in JS Mode, it's almost inexistent! Check it out for yourself: :(|)
    http://studio.processingtogether.com/sp/pad/export/ro.9Ql2E8JBC54LJ/latest

  • edited July 2014

    Sorry here is the code...

    Daym. So noise() dosn't work in JavaScript.

    there is no way around this?

     float xstart, xnoise,ystart, ynoise;
         int x;
     int rand; 
     color colorRand;
     float xnoiseRand, ynoiseRand;
     float redRand, blueRand, greenRand;
    
    void setup() {
      size(640,640);
      smooth();
      background(0); 
      frameRate(24);
      xstart = random(10);
      ystart = random(10);
      rand = (int)random(10, 20);
      }
    
    void draw () { 
      background(0);
      xstart += 0.01;
      ystart += 0.01;
      xnoise = xstart;
      ynoise = ystart;
      float sine = sin(0.0);
    
     for (int y = 0; y <= height; y+=7 ) {
       ynoise += ynoiseRand;
       xnoise = xstart;
       sine +=0.01;
    
         for (int x = 0; x <= width; x+=7) {
           xnoise += 0.1;
           sine+=0.9;
           drawPoint(x, y, noise(xnoise, ynoise), sine);
         }
       }
    }
    
    void drawPoint(float x, float y, float noiseFactor, float sine) {
    
      pushMatrix();
      translate(x,y);
      rotate(noiseFactor * radians(200) );
      float edgeSize = noiseFactor * 10;
      float alph = 0 + (noiseFactor * 255);
      float red1 = 0;
      float green1 = 0;
      float blue1 = 0;
    
        colorRand = color(
         redRand + (noiseFactor * 255), 
          greenRand + (noiseFactor * 255),
          blueRand + (noiseFactor * 255),
          0 + (noiseFactor * 255)
          );
    
      noStroke();
      fill(colorRand + (noiseFactor * 255) );
      ellipse(0, 0, edgeSize, edgeSize);
      popMatrix();
    }
    
    void mouseReleased() {
      xnoiseRand = random(0.05);
      ynoiseRand = random(0.05);  
    }
    
Sign In or Register to comment.