Guest User

Untitled

a guest
Mar 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. //Haze07C
  2. //date
  3. int _y = year();
  4. int _mo = month();
  5. int _d = day();
  6. int _h = hour();
  7. int _mi = minute();
  8. int _s = second();
  9. PImage _img;
  10. int _NUM = 4000;
  11. PVector[] location = new PVector[_NUM];
  12. PVector[] velocity = new PVector[_NUM];
  13. PVector[] acceleration = new PVector[_NUM];
  14. PVector[] force = new PVector[_NUM];
  15. color[] colors = new color[_NUM];
  16. float _radius = 1.0;
  17. float _friction = 0.1;
  18. PVector _minloc;
  19. PVector _maxloc;
  20. float _noiseScale = 0.02;//0.01
  21. float _noiseStrength = 0.1;//0.1
  22.  
  23. void setup(){
  24. size(800, 800, P3D);
  25. smooth();
  26. _img = loadImage("source.jpg");
  27. _img.resize(width, height);
  28. _img.loadPixels();
  29. _minloc = new PVector(0, 0, height * -0.4);
  30. _maxloc = new PVector(width, height, height * 0.4);
  31. frameRate(60);
  32. for(int i = 0; i < _NUM; i++){
  33. location[i] = new PVector(random(width), random(height), random(height * -0.4, height * 0.4));
  34. velocity[i] = new PVector(0, 0, 0);
  35. acceleration[i] = new PVector(0, 0, 0);
  36. force[i] = new PVector(0, 0, 0);
  37. setColor(location[i], i);
  38. }
  39. background(255);
  40. }
  41.  
  42. void draw(){
  43. noStroke();
  44. for(int i = 0; i < _NUM; i++){
  45. fill(colors[i], 6);//a = 3
  46. force[i].x = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.5);
  47. force[i].y = sin(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 2.5);
  48. force[i].z = cos(noise(location[i].x * _noiseScale, location[i].y * _noiseScale, location[i].z * _noiseScale) * TWO_PI * 1.0);
  49. force[i].mult(_noiseStrength);
  50. acceleration[i].add(force[i]);
  51. velocity[i].add(acceleration[i]);
  52. velocity[i].mult(1.0 - _friction);
  53. location[i].add(velocity[i]);
  54. acceleration[i].set(0, 0, 0);
  55. pushMatrix();
  56. translate(location[i].x, location[i].y, location[i].z);
  57. ellipse(0, 0, _radius * 2, _radius * 2);
  58. popMatrix();
  59. if(location[i].x < _minloc.x){
  60. location[i].x = _maxloc.x;
  61. }
  62. if(location[i].y < _minloc.y){
  63. location[i].y = _maxloc.y;
  64. }
  65. if(location[i].z < _minloc.z){
  66. location[i].z = _maxloc.z;
  67. }
  68. if(location[i].x > _maxloc.x){
  69. location[i].x = _minloc.x;
  70. }
  71. if(location[i].y > _maxloc.y){
  72. location[i].y = _minloc.y;
  73. }
  74. if(location[i].z > _maxloc.z){
  75. location[i].z = _minloc.z;
  76. }
  77. }
  78. }
  79.  
  80. void mousePressed(){
  81. if (mouseButton == RIGHT){
  82. noiseSeed(round(random(1000)));
  83. for(int i = 0; i < _NUM; i++){
  84. location[i].set(random(width), random(height), random(height * -0.4, height * 0.4));
  85. velocity[i].set(0, 0, 0);
  86. force[i].set(0, 0);
  87. acceleration[i].set(0, 0, 0);
  88. }
  89. //background(255);
  90. }else if(mouseButton == LEFT){
  91. saveFrame("output/haze07C" + _y + _mo + _d + _h + _mi + _s + "#######.jpg");
  92. }else{
  93. background(0);
  94. }
  95. }
  96. void setColor(PVector loc, int i){
  97. int x = (int)loc.x;
  98. int y = (int)loc.y;
  99. int pickup = x + (y * _img.height);
  100. color c = _img.pixels[pickup];
  101. colors[i] = c;
  102. }
Add Comment
Please, Sign In to add comment