Help to convert Processing Code into Blender compatible code

Hi there,

I watched an extremely helpful tutorial on coding perlin noise in a program called Processing.

However, whilst it explains the topic well I have no interest in using Processing and would like to translate this idea to Blender Python, which I’m a novice at. Could someone give me some assistance on translating this into Python that is compatible with Blender? The code is supposed to add in an object, which is essentially a plane which is lifted up on the z axis according to Perlin Noise.

Here’s the code:

int cols, rows;
int scl = 20;
int w = 1200;
int h = 900;

float[][] terrain;

void setup() {
size(600, 600, P3D);
cols = w / scl;
rows = h / scl;
terrain = new float[cols][rows];
float yoff = 0;
for(int x = 0; x < rows; x++) {
float xoff = 0;
for (int y = 0 ; y < cols; y++) {
terrain[x][y] = map(noise(xoff, yoff), 0, 1, -150, 150);
xoff += 0.2;
}
yoff += 0.2;
}

}

void draw() {
background(0);
stroke(255)
noFill();

translate (width/2, height/2);
rotateX(PI/3);
translate(-w/2, -h/2);
for(int y = 0; y &lt; rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0 ; x &lt; cols; x++) {
        vertex(x*scl, y*scl, terrain[x][y]);
        vertex(x*scl, (y+1)*scl,terrain[x][y+1]);
        //rect(x*scl, y*scl, scl, scl);
    }
    endShape();
}

}

Noise refers to perlin noise. The language is loosely based off of C.

Thanks for any help.

Hi! It is relatively easy to rewrite this script in python, but I’m wondering if it wouldn’t be easier to just use the built in perlin noise in blender and use the displacement modifier to move the points on the plane. Is there a reason you need this to be a custom perlin noise solution? for instance, are you planning on modifying the noise function?

if you do need it to be a python solution, here’s a script that you can run from the text editor in blender to add a “perlin plane” to the add mesh menu (Shift-A):

it’s got a bunch of parameters you can tweak. I used code from here to build it: https://blender.stackexchange.com/questions/34351/how-to-get-a-seed-and-perlin-noise-randomnumber-in-python-in-bge

ah I realize I missed the point of your post, which was to learn Python, not find a script for generating a perlin offset plane… sorry :confused: the script I wrote doesn’t implement it’s own perlin noise function since there is a perfectly servicable one built into blender, which is what that processing script is doing. you could certainly still implement the noise function from scratch and then just let the rest of that script take care of generating the vertices and triangles…