Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. float[] values;
  2. int i = 0, j = 1;
  3. int items = 5000;
  4. int strokeWeight;
  5. int currentIndex = 0;
  6.  
  7. void setup() {
  8. fullScreen(P2D);
  9. //frameRate(10);
  10. //size (800, 500);
  11. if (items > width) {
  12. items = width;
  13. }
  14. strokeWeight = width/items;
  15. values = new float[items];
  16. for (int x = 0; x < values.length; x++) {
  17. values[x] = noise(x) * height;
  18. }
  19. }
  20.  
  21. void swap(float[] arr, int a, int b) {
  22. float temp = arr[a];
  23. arr[a] = arr[b];
  24. arr[b] = temp;
  25. }
  26.  
  27. void draw() {
  28. background(0);
  29.  
  30. if (i < values.length - 1) {
  31. int minIndex = i;
  32. for (j = i + 1; j < values.length; j++) {
  33. if (values[j] < values[minIndex]) {
  34. println(values[j] + "<" + values[minIndex]);
  35. minIndex = j;
  36. }
  37. }
  38.  
  39. swap(values, minIndex, i);
  40. i += 1;
  41. } else {
  42. println("Finished");
  43. i++;
  44. noLoop();
  45. }
  46.  
  47. for (int n = 0; n < values.length; n++) {
  48. stroke(255);
  49. if((strokeWeight - 2) < 1){
  50. strokeWeight(strokeWeight);
  51. }else{
  52. strokeWeight(strokeWeight - 2);
  53. }
  54. if (n < i) {
  55. stroke(0, 255, 0);
  56. }
  57. line(n * strokeWeight + (strokeWeight / 2), height, n * strokeWeight + (strokeWeight / 2), height - values[n]);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement