glv
March 20, 2021, 11:34am
21
Update to:
This is what I added to the terrain code:
colorMode(HSB, 100, 100, 100); // In setup()
// In body of code:
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
float z = terrain[x][y];
fill(z+20, 100, 100);
vertex(x*scl, y*scl, z);
float z1 = terrain[x][y+1];
fill(z1+20, 100, 100);
vertex(x*scl, (y+1)*scl, z1);
//rect(x*scl, y*scl, scl, scl);
}
endShape();
The z values were used to change the hue.
:)
All of the following should be able to provide you with a good understanding of how to add color to your sketch. However it feels like you may be looking for something else however i cannot tell by your comments what this is. If the post answer your question please let me know if not please decribe the problem you are looking to solve.
jafal
March 20, 2021, 2:39pm
23
@glv
hi thanks for hints
@paulgoux
see glv idea about the color
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Code for: https://youtu.be/IKB1hWWedMk
int cols, rows;
int scl = 20;
int w = 2000;
int h = 1600;
float flying = 0;
float[][] terrain;
void setup() {
size(600, 600, P3D);
cols = w / scl;
rows = h/ scl;
terrain = new float[cols][rows];
colorMode(HSB, 100, 100, 100);
}
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/2][y/2] = map(noise(xoff, yoff), 0, 1, -100, 100);
xoff += 0.2;
}
yoff += 0.2;
}
background(0);
// stroke(255);
//noFill();
//noStroke();
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);
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
float z = terrain[x][y];
fill(z+20, 100, 100);
vertex(x*scl, y*scl, z);
float z1 = terrain[x][y+1];
fill(z1+20, 100, 100);
vertex(x*scl, (y+1)*scl, z1);
//rect(x*scl, y*scl, scl, scl);
}
endShape();
}
}
the result as this
i cleared what i need on the photo
i need other way than this
if(terrain[x][y]<60)c = color(0,0,255);
if(terrain[x][y]>60)c = color(189, 189, 23);
i need to select the X Y and color it
glv
March 20, 2021, 3:01pm
24
@jafal
You are in complete control of your code. :)
// In body of code:
beginShape(TRIANGLE_STRIP);
for (int x = 0; x < cols; x++) {
float hue = 0;
float z = terrain[x][y];
if (x>cols/2 && y>rows/2)
hue = 60;
else
hue = z;
fill(hue, 100, 100);
vertex(x*scl, y*scl, z);
float z1 = terrain[x][y+1];
fill(hue, 100, 100);
vertex(x*scl, (y+1)*scl, z1);
//rect(x*scl, y*scl, scl, scl);
}
endShape();
I also added lights()
at the start of draw()
.
You can also modify the other elements of the HSB color.
2 Likes
jafal
March 20, 2021, 3:32pm
25
@glv
hi
just idea came to me now i see that its suitable for now divide the x y of grid into blocks then terrain the wanted block with selected color i am going to give it try
jafal
March 20, 2021, 5:34pm
26
@ glv
just awesome
Now, a quarter of the grid has a color independent of the rest of the grid
1 Like
jafal
March 20, 2021, 10:30pm
27
hi
i can now control the color of the grid as blocks
if ( x>44 && x<51 && y>rows/2)
hue = 60;
else
hue = z;
fill(hue, 100, 110);
if ( x>52 && x<59 && y>rows/2)
hue = 20;
fill(hue, 100, 110);
if ( x>61 && x<71 && y>rows/2)
hue = 40;
fill(hue, 100, 110);
if ( x>31 && x<41 && y>rows/2)
hue = 90;
fill(hue, 100, 110);
if ( x>71 && x<77 && y>rows/2)
hue = 10;
fill(hue, 100, 110);
if ( x>63 && x<85 && y>1&& y<38 )
hue = 25;
fill(hue, 100, 110);
if ( x>51 && x<61 && y>1&& y<38 )
hue = 75;
fill(hue, 100, 110);
jafal
March 20, 2021, 10:42pm
28
hi
my question now how to make the colored block has gradient Z color because When terrain is gained
The colors of the blocks from top to bottom remain the same
jafal
March 27, 2021, 7:25am
29
hi
yes you are true now i am in complete control
2 Likes
Try things with even more complexity. This is 2d but the im sure you should be able to convert it to 3d. Anyways play around with the commented functions.
int total = 1000;
float x,y,radius = 100;
PVector pos;
void setup(){
size(400,400);
pos = new PVector(width/2,height/2);
};
void draw(){
background(255);
//radius =
for(int i=0;i<total;i++){
float angle = ((2*PI)/total)*i;
int osc = 4;
float offset = 0;
//offset = cos(angle);
//offset = sin(angle);
//offset = tan(angle);
//offset = 1/cos(angle);
//offset = 1/sin(angle);
//offset = 1/tan(angle);
//offset = sin(angle*osc);
//offset = tan(angle*osc);
//offset = 1/cos(angle*osc);
//offset = 1/sin(angle*osc);
//offset = 1/tan(angle*osc);
float func = 0;
func = sin((angle+offset)*osc);
//func = cos((angle+offset)*osc);
//func = tan((angle+offset)*osc);
//func = sin(angle+offset*osc);
//func = cos(angle+offset*osc);
//func = tan(angle+offset*osc);
//func = sin((angle+offset)*osc)*cos((angle+offset)*osc);
//func = sin((angle+offset)*osc)*cos(angle+offset*osc);
//func = sin((angle+offset)*osc)*cos(angle+offset*osc);
//func = sin((angle+offset)*osc)*cos(angle+offset*osc);
//func = sin((angle+offset)*osc)*cos(angle+offset*osc);
//func = sin((angle+offset)*osc)*cos(angle+offset*osc);
x = pos.x+radius * cos(angle)*func;
y = pos.y+radius * sin(angle)*func;
stroke(0);
strokeWeight(1);
point(x,y);
}
};
1 Like
jafal
March 27, 2021, 7:58am
31
@paulgoux
thanks for you i am going to try you sketch
now i can have multi colors and z heights in the same grid and not random and with out noise
jafal
March 27, 2021, 8:03am
34
see how colors interference
1 Like
Now to code desmos from scratch
1 Like
jafal
March 27, 2021, 8:13am
36
yes sure but i am totally new for java and my experience close to zero but i can learn what i insist to learn with assist of good people here
1 Like
A little bit of brain food
2 Likes
jafal
March 27, 2021, 8:33am
38
nice and warm food
i do own 3d printer it could print complex shape
2 Likes