Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. snake[] snakes = new snake[0];
  2. int r,g,b;
  3. int x, y;
  4. void setup() {
  5. background(255);
  6. frameRate(10);
  7. size(500, 500);
  8. r= int(random(255));
  9. b= int(random(255));
  10. g= int(random(255));
  11. smooth();
  12. x = int(random(width));
  13. y = int(random(height));
  14.  
  15. }
  16. void draw() {
  17.  
  18. stroke(r,g,b, 10);
  19. for (int j = 0; j < 5; j++){
  20. if(j<5){
  21. snakes = (snake[]) append(snakes, new snake(x, y, 15, random(100), 1));
  22. for(int i = 0; i < snakes.length; i++) {
  23. if(!snakes[i].done())
  24. snakes[i].go();
  25. }
  26. }
  27. }
  28. }
  29.  
  30. /*if(mousePressed) {
  31. snakes = (snake[]) append(snakes, new snake(mouseX, mouseY, 15, random(100), 1));
  32. }
  33. }
  34.  
  35. void mousePressed() {
  36. //fill(255, 255, 255, 150);
  37. //rect(0, 0, width, height);
  38. for(int i = 0; i < snakes.length; i++) {
  39. snakes[i].tm = 1;
  40. }
  41. }*/
  42. class snake {
  43. float X;
  44. float Y;
  45. float rot;
  46. float V;
  47. float tm;
  48. int fm;
  49. snake(int tX, int tY, float tfm, float trot, float tV) {
  50. X = tX;
  51. Y = tY;
  52. rot = trot;
  53. tm = tfm;
  54. V = tV;
  55. }
  56. void go() {
  57. V += random(-0.005, 0.005);
  58. tm /= 1.01;
  59. strokeWeight(tm);
  60. rot += random(-0.2, 0.2);
  61. line(X, Y, X + V*sin(rot), Y + V*cos(rot));
  62. line(X, Y, X + V*sin(rot), Y + V*cos(rot));
  63. X += V*sin(rot);
  64. Y += V*cos(rot);
  65. fm++;
  66. //if(random(400) > 398.5-(fm/20)) {
  67. //snakes = (snake[]) append(snakes, new snake(int(X), int(Y), tm, rot + random(-0.2, 0.2), V));
  68. //}
  69. }
  70. boolean done() {
  71. if(tm < 1.01) {
  72. return true;
  73. }else{
  74. return false;
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement