Comutare navigație
pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
×
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
×
Lista scripturi
Script Nou
Ajutor
"Oscilator armonic liniar" - Processing
ID
Autor
Duplicat din
Ultima modificare
#3163
Ciurcau Leonardo (Goth)
-
Luni, 20 sep 2021, 19:08
var body, spring, omega, t, friction; function setup() { createCanvas(400, 400); background(255); CreateBody(); CreateSpring(); t = 0; friction = 0.01; omega = sqrt(spring.k / body.m); body.y = body.A = 20; } function draw() { translate(width / 2, height / 2); body.update(); spring.update(); background(255); body.draw(); spring.draw(); t += 10; } function CreateBody() { body = { x: 0, y: 0, w: 25, h: 20, m: 750, A: 0, v: 0, a: 0, update: function() { this.v = -this.A * cos(omega * t); this.a = -(omega * omega) * this.A * sin(omega * t); this.y += this.v; this.v += this.a; if (this.A - friction >= 0) this.A -= friction; else this.A = 0; }, draw: function() { noStroke(); fill(60); rect(this.x, this.y, this.w, this.h); } }; } function CreateSpring() { spring = { w: body.w / 4, h: body.y + width / 2, x: (body.x + body.w) / 2 - (body.w / 8), y: -width / 2, k: 0.1, update: function() { this.h = body.y + width / 2; this.w = map(this.h, 0, height, body.w / 2, body.w / 16); this.x = (body.x + body.w) / 2 - (this.w / 2); }, draw: function() { noStroke(); fill(151); rect(this.x, this.y, this.w, this.h); } } }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=3163" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!