rectangular

Processing Globe Explorations

Jan 11th, 2017
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1. PShader depthOfFieldShader;
  2.  
  3. PImage texture;
  4. PImage starsTexture;
  5. PImage overlay;
  6.  
  7. PShape globe;
  8. PShape starsGlobe;
  9.  
  10. float distance = 900;
  11.  
  12. Line[] lines = new Line[1000];
  13.  
  14. void setup() {
  15.   size(1920, 1080, P3D);
  16.   smooth(4);
  17.   //pixelDensity(2);
  18.  
  19.   //depthOfFieldShader = loadShader("depthOfFieldShader.glsl");
  20.  
  21.   texture = loadImage("globe.png");
  22.   globe = createShape(SPHERE, 300);
  23.   //globe.setFill(color(255, 255, 255, 220));
  24.   globe.setTexture(texture);
  25.   //globe.setTint(color(255, 255, 255, 10));
  26.   globe.setStroke(false);
  27.  
  28.   //starsTexture = loadImage("starsTexture.png");
  29.   starsGlobe = createShape(SPHERE, 3000);
  30.   starsGlobe.setFill(false);
  31.   starsGlobe.setTexture(starsTexture);
  32.   starsGlobe.setStroke(color(210, 29, 105, 10));
  33.  
  34.   overlay = loadImage("0 Initial Globe.png");
  35.  
  36.   createSomeLines();
  37. }
  38.  
  39. void draw() {
  40.   background(255);
  41.   fill(255);
  42.  
  43.   // draw anything 3d
  44.  
  45.   //camera(frameCount, mouseY/2, (height/2) / tan(PI/6), width/2, height/2, 0, 0, 1, 0);
  46.   float x = cos(0.001 * frameCount) * distance;
  47.   float y = (-distance / 2) + mouseY / 2;
  48.   float z = sin(0.001 * frameCount) * distance;
  49.  
  50.   translate(width/2, height/2, -100);
  51.   camera(x,y,z, 0,0,0, 0,1,0);
  52.  
  53.   //lights();
  54.   //spotLight(255, 255, 255, width/2, height/2, 400, 0, 0, -1, PI/4, 2);
  55.  
  56.   //hint(DISABLE_DEPTH_TEST);
  57.   shape(globe);
  58.   shape(starsGlobe);
  59.  
  60.   //drawDebugLines();
  61.   drawLines();
  62.  
  63.   // draw anything 2d
  64.   camera();
  65.  
  66.   fill(150);
  67.   //text(round(frameRate), 10, 15);
  68.  
  69.   image(overlay, 0, 0, width, height);
  70.  
  71.   //println(frameCount);
  72.   //String pngName = String.format("_export/outer-sphere-%04d.png", frameCount);
  73.   //save(pngName);
  74. }
  75.  
  76. void mouseClicked() {
  77.   createSomeLines();
  78. }
  79.  
  80. void createSomeLines() {
  81.   for (int i = 0; i < lines.length; i++) {
  82.     Line line = new Line(random(600) - 300, random(600) - 300, random(600) - 300);
  83.     lines[i] = line;
  84.   }
  85. }
  86.  
  87. void drawLines() {
  88.   strokeWeight(1);
  89.  
  90.   for (int i = 0; i < lines.length; i++) {
  91.     stroke(lines[i].strokeColor);
  92.     line(0, 0, 0, lines[i].x, lines[i].y, lines[i].z);
  93.   }
  94. }
  95.  
  96. void drawDebugLines() {
  97.   strokeWeight(1);
  98.   stroke(255, 0, 0);
  99.   line(0, 0, 0, 600, 0, 0);
  100.  
  101.   stroke(0, 255, 0);
  102.   line(0, 0, 0, 0, 600, 0);
  103.  
  104.   stroke(0, 0, 255);
  105.   line(0, 0, 0, 0, 0, 600);
  106.   noStroke();
  107. }
  108.  
  109. class Line {
  110.  
  111.   float x;
  112.   float y;
  113.   float z;
  114.  
  115.   color strokeColor;
  116.  
  117.   Line(float _x, float _y, float _z) {
  118.     x = _x;
  119.     y = _y;
  120.     z = _z;
  121.    
  122.     int colorChoice = round(random(3));
  123.     if (colorChoice > 0) {
  124.       strokeColor = color(0, 155, 220);
  125.     } else {
  126.       strokeColor = color(210, 29, 105);
  127.     }
  128.   }
  129.  
  130. }
Add Comment
Please, Sign In to add comment