Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

color mapping

$
0
0

Hey everyone! I'm quite new to processing and there's something I can't quite figure out. I'm trying to make a sphere of which the radius of each point is calculated by perlin noise. This seems to be working but now I'm trying to map the color of each part of the sphere be mapped to the radius of that point. This doesn't happen however, the entire sphere is changing color. Can anyone tell me where I'm making the mistake? Any input is appreciated!

P.S. also, after a while of running the program, the radius stops being updated for some reason. If anyone knows why that is I'd love to hear it!

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

PeasyCam cam;

PVector[][] globe;
int total = 150;
float rad = 25;
float nI=0;
float nJ=0;
float hu;
boolean calculated = false;
void setup() {
  cam = new PeasyCam(this, 100);
  size(600, 600, P3D);
  globe = new PVector[total+4][total+4];
  colorMode(HSB);
}

void draw() {
  background(0);
  lights();
  // if (!calculated) {
  //float nJ=0;
  for (int i = 0; i < total+1; i++) {
    float lat = map(i, 0, total, 0, PI);
    for (int j = 0; j < total+1; j++) {
      rad = map(noise(i+nI, j+nJ), 0, 1, 90, 110);
      nI+=0.0000005;
      nJ+=0.0000005;
      hu = map(rad, 90, 110, 0, 255);
      fill(hu, 255, 255);
      float lon = map(j, 0, total, 0, TWO_PI);
      float x = rad*cos(lon)*sin(lat);
      float y = rad*sin(lon)*sin(lat);
      float z = rad*cos(lat);
      globe[i][j] = new PVector(x, y, z);
    }
  }
  calculated = true;
  //}

  for (int i =0; i < total; i++) {
    beginShape(TRIANGLE_STRIP);
    for (int j = 0; j < total + 1; j++) {
      PVector v = globe[i][j];
      PVector v2 = globe[i+1][j];
      vertex(v.x, v.y, v.z);
      vertex(v2.x, v2.y, v2.z);
    }
    endShape();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles