Advertisement
Guest User

Untitled

a guest
May 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. import peasy.*;
  2.  
  3. int numX = 10;
  4. int numY = 10;
  5. int maxH;
  6.  
  7. PGraphics canvas;
  8.  
  9. int count = 0;
  10.  
  11. PeasyCam cam;
  12.  
  13. boolean recording = false;
  14.  
  15. float[][] z;
  16. float[][] zDir;
  17. PVector[][] points;
  18.  
  19. float[] gaussian;
  20.  
  21. void setup() {
  22.   size(1000, 700, P3D);
  23.  
  24.   canvas = createGraphics(width, height, P3D);
  25.  
  26.   maxH = int(width*0.1);
  27.  
  28.   //cam = new PeasyCam(this, width/2, height/2, 0, 400);
  29.  
  30.   z = new float[numX][numY];
  31.   zDir = new float[numX][numY];
  32.   points = new PVector[numX][numY];
  33.  
  34.   gaussian = new float[maxH];
  35.   beginShape();
  36.   for (int i = 0; i < maxH; i++) {
  37.     float x = map(i, 0, maxH, -5, 5);
  38.     gaussian[i] = Gaussian(x, 0, 0.8);
  39.     gaussian[i] = map(gaussian[i], 0.0, 1.0, 0.2, 1.0);
  40.   }
  41.  
  42.  
  43.   for (int i = 0; i < numX; i++) {
  44.     for (int j = 0; j < numY; j++) {
  45.       points[i][j] = new PVector(i*(width/numX), j*(width/numY), random(0, maxH));
  46.       zDir[i][j] = random(-2, 2);
  47.       if (zDir[i][j] < 0.2 && zDir[i][j] > -0.2) {
  48.         if (zDir[i][j] <= 0.0) zDir[i][j] -= 0.2;
  49.         else if (zDir[i][j] >= 0.0) zDir[i][j] += 0.2;
  50.       }
  51.     }
  52.   }
  53.  
  54.   canvas.sphereDetail(6);
  55.  
  56.   canvas.lightSpecular(1, 1, 1);
  57.   canvas.smooth(32);
  58. }
  59.  
  60. void draw() {
  61.   noStroke();
  62.   fill(0);
  63.  
  64.   canvas.beginDraw();
  65.  
  66.   //canvas.directionalLight(255, 255, 255, 0, 0, -1);
  67.   //canvas.lights();
  68.  
  69.   //for (int i = 0; i < numX; i++) {
  70.   //  for (int j = 0; j < numY; j++) {
  71.  
  72.   //    float zee = points[i][j].z;
  73.  
  74.   //    if (zee >= maxH) zDir[i][j] *= -1;
  75.   //    else if (zee <= 0.0) zDir[i][j] *= -1;
  76.  
  77.   //    float gaus = gaussian[constrain(int(zee), 0, maxH-1)];
  78.  
  79.   //    points[i][j].z += (zDir[i][j]*3.0)*gaus;
  80.   //  }
  81.   //}
  82.  
  83.   //background(255);
  84.  
  85.   //for (int i = 0; i < numX; i++) {
  86.   //  for (int j = 0; j < numY; j++) {
  87.  
  88.   //    //canvas.pushMatrix();
  89.   //    //canvas.translate(points[i][j].x, points[i][j].y, points[i][j].z);
  90.   //    //canvas.fill(255);
  91.   //    //canvas.noStroke();
  92.   //    //canvas.sphere(5);
  93.   //    //canvas.popMatrix();
  94.   //    //canvas.stroke(100);
  95.  
  96.   //    if (i<numX-1 && j<numY-1) {
  97.  
  98.   //            canvas.fill(54, 223, 255, map(points[i][j].z, 0, maxH, 150, 0));
  99.  
  100.   //      canvas.beginShape(TRIANGLES);
  101.   //      canvas.vertex(points[i][j].x, points[i][j].y, points[i][j].z);
  102.   //      canvas.vertex(points[i][j+1].x, points[i][j+1].y, points[i][j+1].z);
  103.   //      canvas.vertex(points[i+1][j+1].x, points[i+1][j+1].y, points[i+1][j+1].z);
  104.  
  105.   //      canvas.vertex(points[i][j].x, points[i][j].y, points[i][j].z);
  106.   //      canvas.vertex(points[i+1][j].x, points[i+1][j].y, points[i+1][j].z);
  107.   //      canvas.vertex(points[i+1][j+1].x, points[i+1][j+1].y, points[i+1][j+1].z);
  108.   //      canvas.endShape();
  109.   //    }
  110.   //  }
  111.   //}
  112.  
  113.   canvas.endDraw();
  114.  
  115.   image(canvas, 0, 0);
  116.  
  117.   if (recording) {
  118.    
  119.     println(count++);
  120.   }
  121. }
  122. float Gaussian(float x, float mean, float variance) {
  123.   return (1 / sqrt(TWO_PI * variance)) * exp(-sq(x - mean) / (2 * variance));
  124. }
  125.  
  126. void keyPressed() {
  127.   if (!recording && key == 'h') {
  128.     recording = true;
  129.   } else if (key=='h') {
  130.     recording = false;
  131.   }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement