# How to add image to terrain sketch

**URL:** <https://discourse.processing.org/t/how-to-add-image-to-terrain-sketch/28158>\
**Category:** Coding Questions\
**Created:** [March 1, 2021, 6:05am UTC](https://discourse.processing.org/t/how-to-add-image-to-terrain-sketch/28158 "2021-03-01T06:05:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [March 1, 2021, 6:05am UTC](https://discourse.processing.org/t/how-to-add-image-to-terrain-sketch/28158/1 "2021-03-01T06:05:52Z")

</div>

hi

how to add text and image to this sketch

```auto
int cols, rows;
int scl = 13;
int w = 1200;
int h = 1600;

float flying = 0;

//int scl = 10;
//int w = 1900;
//int h = 2600;

float[][] terrain;
 
void setup() {
  size (600, 600, P3D);
  cols = w / scl;
  rows = h / scl;
  terrain = new float[cols][rows];
}

void draw() {
  
 // flying -= 0.06;
  
  float yoff = 1;
  
  for (int y = 0; y < rows - 1; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -7, 7);
      xoff += 0.1;
    }
    yoff += 0.1;
  }
  
  
  background(0);
  stroke(255);
  noFill();
  
  translate(width / 2, height / 2 - 50);
  rotateX(PI/3);
  translate(- w / 2, - h / 2);
  
  for (int y = 0; y < rows - 1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) {
      vertex(x * scl, y * scl, terrain[x][y]);
      vertex(x * scl, (y + 1) * scl, terrain[x][y+1]);
    }
    endShape();
  }
}

```

thanks in advance

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [March 2, 2021, 7:55am UTC](https://discourse.processing.org/t/how-to-add-image-to-terrain-sketch/28158/2 "2021-03-02T07:55:31Z")

</div>

```auto
int cols, rows;
int scl = 20;
int w = 2000;
int h = 1600;
 
float flying = 0;
 
float[][] terrain;
 
PImage img;
 
void setup() {
  size(600, 600, P3D);
  cols = w / scl;
  rows = h/ scl;
  terrain = new float[cols][rows];
  //String = img;
  img = loadImage( "vv.png");

  texture(img);
}
 
 
void draw() {
 
  flying -= 0.1;
 
  float yoff = flying;
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -100, 100);
      xoff += 0.2;
    }
    yoff += 0.2;
  }
 
 
 
  background(0);
  //stroke(255);
  //noFill();
 
  translate(width/2, height/2+50);
  rotateX(PI/3);
  scale(0.5);
  translate(-w/2, -h/2);
  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    texture(img);
    for (int x = 0; x < cols; x++) {
      vertex(x*scl, y*scl, terrain[x][y], map(x,0,cols,0,img.width), map(y,0,rows,0,img.height) );
      vertex(x*scl, (y+1)*scl, terrain[x][y+1], map(x,0,cols,0,img.width), map(y+1,0,rows,0,img.height));
      //rect(x*scl, y*scl, scl, scl);
    }
    endShape();
  }
}

```

 ![Untitled 52](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/be42426cf50c74047dd3a3a2542b528dff112518.jpeg)
