perlin noise with fixed top
in
Programming Questions
•
3 years ago
hi guys
i want to have an array of perlin noise points
that begin and end with zero
i've tried to get the first 5 and last 5 point and fade this range to zero, but the result is absolutly not good.. :
brutal straight line from point to zero
mayebe there is some ways to get perlin algorithm start from zero and end in zero..
any ideas?
here is my code:
- float[] points;
- float xoff = 0.0;
- float xincrement = 0.04;
- //------------------------- setup
- void setup() {
- size(500, 500);
- smooth();
- background(255);
- points = fade(getPerlin());
- }
- //------------------------- draw
- void draw() {
- background(255);
- float[] points = getPerlin();
- // original perlin points
- stroke(125);
- fill(125);
- linear(points);
- // faded points
- stroke(0, 100);
- fill(0, 100);
- linear(fade(points));
- }
- void linear(float points[]) {
- beginShape();
- for(int i=0; i<50; i++) {
- int x = (int)map(i, 0, 50, 0, width);
- int y = (int)points[i];
- vertex(x,y);
- }
- endShape();
- }
- //------------------------- GENERATE PERLIN ARRAY
- float[] getPerlin() {
- float[] a = new float[50];
- xoff = 0;
- for(int i=0; i<50; i++) {
- a[i] = noise(xoff)*width;
- xoff += xincrement;
- }
- return a;
- }
- //------------------------- FADE FIRST AND LAST 5 POINTS
- float[] fade(float[] n) {
- float beginpoint;
- float p, percentuale;
- // first 5 points from zero to n[5]
- beginpoint = n[5];
- for(int i=0; i<=5; i++) {
- percentuale = map(i, 0, 5, 0, 1);
- n[i] = (beginpoint)*percentuale;
- }
- // last 5 points from n[lenght-5] to 0
- beginpoint = n[50-1-5];
- for(int i=0; i<=5; i++) {
- percentuale = map(i, 0, 5, 1, 0);
- n[50-1 - (5-i)] = (beginpoint)*percentuale;
- }
- return n;
- }
1
