# 3D Mesh of Sine Waves from Coding Challenge

**URL:** <https://discourse.processing.org/t/3d-mesh-of-sine-waves-from-coding-challenge/22806>\
**Category:** Gallery\
**Created:** [July 23, 2020, 6:56pm UTC](https://discourse.processing.org/t/3d-mesh-of-sine-waves-from-coding-challenge/22806 "2020-07-23T18:56:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 23, 2020, 6:56pm UTC](https://discourse.processing.org/t/3d-mesh-of-sine-waves-from-coding-challenge/22806/1 "2020-07-23T18:56:25Z")

</div>

Hello,

I had some fun exploring 3D meshes from:  
[Coding Challenge #11: 3D Terrain Generation with Perlin Noise in Processing](https://youtu.be/IKB1hWWedMk)

> **Code \< Click here**
>
> ```auto
> // 3D Mesh Sine Waves
> // v 1.0.1
> // GLV 2020-07-22
> 
> // Inspiration:
> // Coding Challenge #11: 3D Terrain Generation with Perlin Noise in Processing
> // https://youtu.be/IKB1hWWedMk
> 
> int rows, cols;
> int sp = 10;
> int w = 600;
> int h = 600;
> int col;
> 
> float theta;
> boolean toggle = true;
> 
> void setup() 
> {
> size(600, 600, P3D);
> 
> cols = w/sp;
> rows = h/sp;
>   
> colorMode(HSB, 256*2*3, 100, 100); //all hues at full sat and brightness
> background(0);
> }
> 
> void draw() 
> {
> background(0);
> lights();
>   
> pushMatrix();
> translate(width/2, height/2);
> rotateX(TAU/8);
> translate(-w/2, -h/2 -250, -150);
>   
> theta += TAU/1000;
> col += 1;
>   
> if (col> 256*2*3-1) col = 0;
> 
> if(toggle)
> { 
> noStroke();
> fill(col, 100, 100);
> }
> else
> {
> stroke(60*256*2*3/360, 100, 100);
> println(hex(color(60*256*2*3/360, 100, 100)));
> noFill();
> }     
>     
> for(int y = 0; y< rows; y++)
> {
> beginShape(TRIANGLE_STRIP);
>     
> float angley = TAU/20;
>     
> for(int x = 0; x < cols; x++)
> {    
> float anglex = TAU/20;
>           
> float z1 = 50*sin(x*anglex + theta) + 50*sin(y*angley + theta);
> float z2 = 50*sin(x*anglex + theta) + 50*sin((y+1)*angley + theta);
>       
> vertex(x*sp, y*sp, z1);
> vertex(x*sp, (y+1)*sp, z2);
> }
> endShape();  
> }
> popMatrix();
>     
> push();  
> fill(256*3*2);
> textSize(30);
> color c = color(col, 100, 100);
>   
> text("RED: " + nfs( (c >> 16 & 0xFF), 3) + 
> " GREEN: " + nfs(( c >> 8 & 0xFF), 3) +  
> " BLUE: "+ nfs((c & 0xFF), 3), 40, height-60);    
> pop();
> }
> 
> void keyPressed()
> { 
> toggle = !toggle; 
> println(toggle); 
> }
> 
> ```

I got it to cycle through all the hues for full sat and brightness in HSB mode; that I had to think about!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/200a53b44923ace1424ce7cf0451c1fa56a58712.png)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7e38a351494a2fd155bbb1202fb3816ef722f27b.png)

That was fun!

`:)`
