Paint sur paysage montagne

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// cols= colonne, ligne= rows
int cols, rows;
// scl pour scale
int scl = 15;
int w = 2000;
int h = 1600;
int count = 1;
float flying = 0;
// pour creer une collection d'éléments
float[][] terrain;
int wo=0;
float rotationX = 0;
float rotationZ = 0;
float rotationY =0;
int l=255;
int m=50;
void setup() {
  size(800, 800, P3D);
  cols = w / scl;
  rows = h / scl;
  terrain = new float[cols][rows];
}
 
 
void draw() {
 
wo += 20;
  flying -= 0.1;
// valeur pour faire bouger avec effet élévation selon y les points du terrain
  float yoff = flying;
  // boucle pour définir le cadrillage qui va bouger, defini selon x et y
  for (int y = 0; y < rows; y++) {
    float xoff = 0;
    for (int x = 0; x < cols; x++) {
      // on bouge selon l'axe y et x
      terrain[x][y] = map(noise(xoff, yoff), 0, 1, -150, 150);
      xoff += 0.2;
    }
    yoff += 0.2;
  }
  
 
    if (mousePressed == true) {
      
    
 
   stroke(l);
   fill(255);
   beginShape();
vertex(mouseX-30, mouseY-30, -30);
vertex( mouseX+30, mouseY-30, 0-30);
vertex(   mouseX,    mouseY,  0+30);
 
vertex( mouseX+30, mouseY-30, 0-30);
vertex( mouseX+30,  mouseY+30, 0-30);
vertex(   mouseX,    mouseY,  0+30);
 
vertex(mouseX+30,mouseY+30, 0-30);
vertex(mouseX-30,mouseY+30, 0-30);
vertex( mouseX, mouseY, 0+30);
 
vertex(mouseX-30, mouseY+30, 0-30);
vertex(mouseX-30, mouseY-30, 0-30);
vertex( mouseX, mouseY, 0+30);
endShape();
   if (keyPressed) {
   if (key == 'e' || key == 'E') {
     l -= 120;
      rotateX(rotationX);
      rotationX += PI/8;
      rotateY(PI/flying);
rotateZ(rotationZ);
rotationZ += PI/18;
 
  stroke(l-55);
   fill(120,57,75);
   beginShape();
vertex(mouseX-30, mouseY-30, -30);
vertex( mouseX+30, mouseY-30, 0-30);
vertex(   mouseX,    mouseY,  0+30);
 
vertex( mouseX+30, mouseY-30, 0-30);
vertex( mouseX+30,  mouseY+30, 0-30);
vertex(   mouseX,    mouseY,  0+30);
 
vertex(mouseX+30,mouseY+30, 0-30);
vertex(mouseX-30,mouseY+30, 0-30);
vertex( mouseX, mouseY, 0+30);
 
vertex(mouseX-30, mouseY+30, 0-30);
vertex(mouseX-30, mouseY-30, 0-30);
vertex( mouseX, mouseY, 0+30);
endShape();
   }
   }
 } else{
 
  background(0);
  stroke(noise(0, 255));
  fill(123,120,100);
// 1 ere translation pour avoir le plan, selon autre axe//mousepress avec tanslate?
  translate(width/2, height/2+m);
  // rotation de 60 degre
  rotateX(PI/3);
  // 2 eme translation pour corriger le fait qu'on a deplacer depuis en haut a gauche
  translate(-w/2, -h/2);
    
  // boucle pour former le terrain selon une triangulation
  for (int y = 0; y < rows-1; y++) {
    beginShape(TRIANGLE_STRIP);
    for (int x = 0; x < cols; x++) {
      // vertex pour les forme
      vertex(x*scl, y*scl, terrain[x][y]);
      stroke(random(0,255),random(0,255),random(0,255));
      
      vertex(x*scl, (y+1)*scl, terrain[x][y+1]);
      stroke(noise(0,255), noise(0, 255), noise(0, 255));
      //rect(x*scl, y*scl, scl, scl);
    }
    endShape();
  }
}
 
 if (keyPressed) {
     
    if (key == 's' || key == 'S') {
      save(count+"monBeauDessin.png");
      count++;
      delay(100);
    }
     if (key == 'm' || key == 'M') {
       m+=10;
      
   }
        if (key == 'n' || key == 'N') {
       m-=10;
        
     }
        
}
}