예제 #1
0
VALUE OSimplex_Generator_get_2d_chunk (const VALUE self, const VALUE x, const VALUE y, const VALUE width, const VALUE height) {
  SELF2GENERATOR();
  const int           xStart    = NUM2INT(x);
  const int           xEnd      = xStart + NUM2INT(width);
  const int           yStart    = NUM2INT(y);
  const int           yEnd      = yStart + NUM2INT(height);

  VALUE               result    = rb_ary_new();
  for (int j=yStart; j<yEnd; ++j) {
    const double        jVal      = j / gen->scale;
    for (int i=xStart; i<xEnd; ++i) {
      double            val       = normalize( open_simplex_noise2( gen->context, i / gen->scale, jVal ), gen);
      rb_ary_push(result, rb_float_new(val));
    }
  }
  return result;
}
예제 #2
0
VALUE OSimplex_Generator_get_2d (const VALUE self, const VALUE x, const VALUE y) {
  SELF2GENERATOR();
  double  ret   = open_simplex_noise2( gen->context, NUM2DBL(x) / gen->scale, NUM2DBL(y) / gen->scale );
  return  rb_float_new( normalize(ret, gen ) );
}
예제 #3
0
static int simplex(double* buffer, const scil_dims_t* dims, double mn, double mx, double arg, double arg2, int seed){
  const int frequencyCount = (int) arg2;
  double highFrequency = (double) arg;

  if( scilU_double_equal(mn, mx) || frequencyCount <= 0 ){
    return SCIL_EINVAL;
  }

  struct osn_context *ctx;
  open_simplex_noise(seed, &ctx);

  int64_t max_potenz = 1<<frequencyCount;
  const size_t* len = dims->length;

  switch(dims->dims){
    case (1):{
      size_t count = scil_dims_get_count(dims);
      for (size_t i=0; i < count; i++){
        buffer[i] = 0;
        int64_t potenz = max_potenz;
        int64_t divisor = 1;
        for(int f = 1 ; f <= frequencyCount; f++){
          buffer[i] += potenz * open_simplex_noise2(ctx, 1.0, (double) i / count * divisor * highFrequency);
          potenz /= 2;
          divisor *= 2;
        }
      }
      break;
    }case (2):{
      for (size_t y=0; y < len[1]; y++){

        for (size_t x=0; x < len[0]; x++){
          double var = 0;
          int64_t potenz = max_potenz;
          int64_t divisor = 1;
          for(int f = 1 ; f <= frequencyCount; f++){
            var += potenz * open_simplex_noise2(ctx, (double) x / len[0] * divisor*highFrequency, (double) y / len[1] * divisor*highFrequency);
            potenz /= 2;
            divisor *= 2;
          }
          buffer[x+y*len[0]] = var;
        }

      }
      break;
    }case (3):{
      for (size_t z=0; z < len[2]; z++){
        for (size_t y=0; y < len[1]; y++){
          for (size_t x=0; x < len[0]; x++){
            double var = 0;
            int64_t potenz = max_potenz;
            int64_t divisor = 1;
            for(int f = 1 ; f <= frequencyCount; f++){
              var += potenz * open_simplex_noise3(ctx, (double) x / len[0]*divisor*highFrequency, (double) y / len[1]*divisor*highFrequency, (double) z / len[2]*divisor*highFrequency);
              potenz /= 2;
              divisor *= 2;
            }
            buffer[x+y*len[0]+z*(len[0]*len[1])] = var;
          }
        }
      }
      break;
    }case (4):{
      for (size_t w=0; w < len[3]; w++){
        for (size_t z=0; z < len[2]; z++){
          for (size_t y=0; y < len[1]; y++){
            for (size_t x=0; x < len[0]; x++){
              double var = 0;
              int64_t potenz = max_potenz;
              int64_t divisor = 1;
              for(int f = 1 ; f <= frequencyCount; f++){
                var += potenz * open_simplex_noise4(ctx, (double) x / len[0]*divisor*highFrequency, (double) y / len[1]*divisor*highFrequency, (double) z / len[2]*divisor*highFrequency, (double) w / len[3]*divisor*highFrequency);
                potenz /= 2;
                divisor *= 2;
              }
              buffer[x+len[0]*(y+len[1]*(z+len[2]*w))] = var;
            }
          }
        }
      }
      break;
    }default:
      assert(0 && "Not supported");
  }

  // fix min + max, first identify min/max
  scilP_change_data_scale(buffer, dims, mn, mx);

  open_simplex_noise_free(ctx);

  return SCIL_NO_ERR;
}