Advertisement
ahorsewithnoname

Untitled

May 4th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. float rinc = 0.5;
  2. float rmax = 17;
  3. float rmin = 2;
  4. float periodoPG = 1.5;
  5. float periodoF = 2;
  6. float r = 0;
  7. boolean runonce = true;
  8. PVector v;
  9.  
  10. float caja1x = 0;
  11. float caja1y = 450;
  12.  
  13. float caja2x = 0;
  14. float caja2y = 50;
  15.  
  16. PVector vector1[] = new PVector[144];
  17. PVector vector2[] = new PVector[144];
  18. PVector vector3[] = new PVector[144];
  19. int indexgen = 0;
  20.  
  21.  
  22. void setup(){
  23. size(600,600);
  24. frameRate(60);
  25.  
  26. }
  27.  
  28. void draw(){
  29. background(255);
  30. fill(0);
  31. circle(caja1x,caja1y,20);
  32. circle(caja2x,caja2y,20);
  33. for(int i = 20; i < 620; i += 50){
  34. for(int j = 20; j < 620; j+= 50){
  35. stroke(0);
  36. vector3[indexgen] = new PVector(0,0);
  37. if(key == '1' || key == '3' || key == '4') separado(i,j,PI, map(sqrt(pow(i-caja1x,2)+pow(j-caja1y,2)),0,300,0,1),map(sqrt(pow(i-caja1x,2)+pow(j-caja1y,2)),0,300,rmax+rmin,rmax+rmin-4),indexgen,0);
  38. stroke(0,0,255);
  39. if(key == '2' || key == '3' || key == '4') separado(i,j,PI, map(sqrt(pow(i-caja2x,2)+pow(j-caja2y,2)),0,300,0,1),map(sqrt(pow(i-caja2x,2)+pow(j-caja2y,2)),0,300,rmax+rmin,rmax+rmin-4),indexgen,1);
  40. stroke(255,0,0);
  41. if(key == '3' || key == '4') dibujavector(i,j,vector3[indexgen]);
  42. indexgen++;
  43. }
  44. }
  45. indexgen = 0;
  46. /*separado(300,300, PI, map(sqrt(pow(300-300,2)+pow(300-300,2)),0,300,0,4));
  47. separado(200,200, PI, map(sqrt(pow(200-300,2)+pow(200-300,2)),0,300,0,4));*/
  48. }
  49.  
  50. void separado(float x, float y, float aini, float tiempoini, float radiomax, int indexgen, int indexpart){
  51. if(millis() > tiempoini*1000){
  52.  
  53. float velang = (2*PI)/(60*periodoF);
  54. float t = ((millis() - tiempoini*1000)/1000)*60; //El tiempo (en frames)
  55. float ang = aini + velang * t;
  56. float rad = rmin + abs(radiomax*sin((1/periodoPG)*ang));
  57.  
  58. //println(ang);
  59. v = PVector.fromAngle(ang);
  60. v.mult(rad);
  61.  
  62. if(indexpart == 0){
  63. vector1[indexgen] = v.copy();
  64. vector3[indexgen].add(vector1[indexgen]);
  65. }
  66. if(indexpart == 1){
  67. vector2[indexgen] = v.copy();
  68. vector3[indexgen].add(vector2[indexgen]);
  69. }
  70. if(key != '4')dibujavector(x,y,v);
  71. }
  72. }
  73.  
  74.  
  75. void dibujavector(float x, float y, PVector vector){
  76. //stroke(0);
  77. noFill();
  78. circle(x,y,2*vector.mag());
  79. arrow(x, y, x+vector.x, y+vector.y);
  80. }
  81.  
  82. void arrow(float x1, float y1, float x2, float y2) {
  83. line(x1, y1, x2, y2);
  84. pushMatrix();
  85. translate(x2, y2);
  86. float a = atan2(x1-x2, y2-y1);
  87. rotate(a);
  88. line(0, 0, -3, -3);
  89. line(0, 0, 3, -3);
  90. popMatrix();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement