Advertisement
Guest User

Harmonógrafo

a guest
Nov 28th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import controlP5.*; // biblioteca da interface
  2.  
  3. float t = 0.5;
  4.  
  5.  
  6. float xp, yp; // x e y de P
  7.  
  8. ControlP5 cp5;
  9.  
  10.  
  11. boolean Limpar;
  12. float Traco = 2;
  13.  
  14.  
  15. float XP2;
  16. float YP2;
  17.  
  18. float p1=radians(0); //fase
  19. float f1=4; // frequencia
  20. float a1=150; // amplitude
  21. float d1=0; // amortecimento
  22.  
  23. float a2=150;
  24. float p2=radians(0);
  25. float f2=5;
  26. float d2=0;
  27.  
  28.  
  29. float a3=150;
  30. float p3=radians(0);
  31. float f3=5;
  32. float d3=0;
  33.  
  34. float a4=150;
  35. float p4=radians(0);
  36. float f4=3;
  37. float d4=0;
  38.  
  39.  
  40. float taxa_amort = 0.008;
  41.  
  42.  
  43. void setup() {
  44. size(900, 800);
  45. background(0);
  46. frameRate(60);
  47.  
  48. d1 = taxa_amort ; // incrementa amortecimento dos pêndulos
  49. d2 = taxa_amort ;
  50. d3 = taxa_amort ;
  51. d4 = taxa_amort ;
  52.  
  53.  
  54.  
  55. frameRate(60);
  56. cp5 = new ControlP5(this);
  57. boolean toggleValue = false;
  58.  
  59. cp5.addToggle("Limpar")
  60. .setPosition(20, 20)
  61. .setSize(50, 20)
  62. .setValue(false);
  63.  
  64. cp5.addSlider("Traco")
  65. .setPosition(10, 750)
  66. .setSize(120, 40)
  67. .setRange(1, 4);
  68. }
  69.  
  70.  
  71.  
  72. void draw() {
  73.  
  74.  
  75.  
  76. XP2=DesenhaXP ( a1, p1, f1, d1, a2, p2, f2, d2 );
  77. YP2=DesenhaYP ( a3, p3, f3, d3, a4, p4, f4, d4 );
  78.  
  79.  
  80. t += 0.02; // espaçamento
  81.  
  82.  
  83.  
  84. stroke(255);
  85. strokeWeight(Traco);
  86. strokeCap(ROUND);
  87. line(XP2, YP2, DesenhaXP( a1, p1, f1, d1, a2, p2, f2, d2), DesenhaYP( a3, p3, f3, d3, a4, p4, f4, d4 ));
  88.  
  89.  
  90.  
  91. if (Limpar==true) {
  92. background(0);
  93. Limpar=false;
  94. }
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. // DESENHA P
  102.  
  103. float DesenhaXP ( float A1, float P1, float F1, float D1, float A2, float P2, float F2, float D2 ) {
  104.  
  105.  
  106. xp=450+A1*sin(t*F1+P1)*exp(-1*D1*t)+A2*sin(t*F2+P2)*exp(-1*D2*t);
  107.  
  108.  
  109.  
  110.  
  111. return xp;
  112. }
  113.  
  114.  
  115.  
  116. float DesenhaYP ( float A3, float P3, float F3, float D3, float A4, float P4, float F4, float D4 ) {
  117.  
  118.  
  119. yp=350+A3*sin(t*F3+P3)*exp(-1*D3*t)+A4*sin(t*F4+P4)*exp(-1*D4*t);
  120.  
  121.  
  122.  
  123.  
  124. return yp;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement