Advertisement
MrMusAddict

Self Referential Color Cube

Feb 9th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. PImage photo; //must be at most 600x600
  2.  
  3. ArrayList<cPoint> points = new ArrayList<cPoint>();
  4.  
  5. void setup() {
  6.   size(600, 600, P3D);
  7.   ortho();
  8.   colorMode(HSB);
  9.   for (int i = 0; i < 255; i++) {
  10.     points.add(new cPoint(color(i, 255, 255)));
  11.   }
  12. }
  13.  
  14. void draw() {
  15.   background(200);
  16.   translate(width/2.0, height/2.0, 0);
  17.   rotateX(PI-PI/8.0);
  18.   rotateY(frameCount*PI/150+3.0*PI/2.0);
  19.   rotateZ(frameCount*PI/135+3.0*PI/2.0);
  20.   strokeWeight(1);
  21.   stroke(0);
  22.   noFill();
  23.   translate(-127, -127, -127);
  24.  
  25.   strokeWeight(20);
  26.   for (cPoint p : points) {
  27.     p.show();
  28.   }
  29.  
  30.   save("edit.jpg");
  31.   points.clear();
  32.   photo = loadImage("edit.jpg");
  33.   for (int i = 0; i < photo.pixels.length; i += 11) {
  34.     points.add(new cPoint(photo.pixels[i]));
  35.   }
  36. }
  37.  
  38. class cPoint {
  39.  
  40.   PVector pos;
  41.   color col;
  42.  
  43.   cPoint(color c) {
  44.     col = c;
  45.     pos = new PVector(red(c), green(c), blue(c));
  46.   }
  47.  
  48.   void show() {
  49.     stroke(col);
  50.     point(pos.x, pos.y, pos.z);
  51.   }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement