# Terrain.js sketch

**URL:** <https://discourse.processing.org/t/terrain-js-sketch/4457>\
**Category:** Coding Questions\
**Created:** [October 14, 2018, 12:40pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457 "2018-10-14T12:40:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [October 14, 2018, 12:40pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/1 "2018-10-14T12:40:26Z")

</div>

Here I attempt to create terrain as per Shiffman challenge  
[Web Editor](https://editor.p5js.org/monkstone/sketches/HkM_RUeim)  
Can’t use `CLOSE` on `endShape` like in vanilla processing or JRubyArt, adds spurious lines.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 14, 2018, 1:11pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/2 "2018-10-14T13:11:26Z")

</div>

yes, the SHAPE starts at x =0 and is a triangle strip and one ROW wide and ends at COLS

a CLOSE command would connect the right end with a triangle to x = 0  
that 2 lines to x = 0 is what you see as MESSY

the whole plane consists of ROWS times of that triangle strips

so what ends you would like to connect?

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [October 14, 2018, 1:21pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/3 "2018-10-14T13:21:45Z")

</div>

The surface looks jagged (on terrain outline), actually in vanilla processing it looks OK either with or without CLOSE.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 14, 2018, 1:23pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/4 "2018-10-14T13:23:07Z")

</div>

experiment again with that CLOSE but use  
h = 40;

++ and check out my version [https://editor.p5js.org/kll/sketches/S1myrBI5X](https://editor.p5js.org/kll/sketches/S1myrBI5X)

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [October 14, 2018, 2:12pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/5 "2018-10-14T14:12:30Z")

</div>

Here’s my [hack](https://editor.p5js.org/monkstone/sketches/rkCL0Tli7) of your sketch using hash (I get the impression it runs a bit faster?)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 14, 2018, 4:40pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/6 "2018-10-14T16:40:27Z")

</div>

good, [https://editor.p5js.org/kll/sketches/S1myrBI5X](https://editor.p5js.org/kll/sketches/S1myrBI5X)  
has mouse scroll and keyboard [s] UP DOWN  
and make the flat waterlevel with constrain

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [October 14, 2018, 5:55pm UTC](https://discourse.processing.org/t/terrain-js-sketch/4457/7 "2018-10-14T17:55:58Z")

</div>

I will have to see what I can do in [JRubyArt](https://github.com/ruby-processing/JRubyArt-examples/blob/master/processing_app/library/vecmath/vec3d/terrain.rb), where I have Vec3D class that can translate to vertex.
