xxxxxxxxxx
/*// la particella che si muove di MRU deve essere caratterizzata da POSIZIONE, VELOCITà, RAGGIO
// Coordinate
let x, y;
// Velocità
let Vx, Vy;
// raggio
let r = 20*/
// e inoltre il tempo t= tempo assoluto, dt = incremento
let t, dt;
// l'approccio è vettoriale, tratto le due componenti separatamente, anche se
// in realtà posso operare facilemte con delle operazioni con i vettori
function setup() {
createCanvas(windowWidth, windowHeight)
t = 0;
dt = 3;
/*x = 100;
y = 200;
Vx = 1;
Vy = 1;*/
//creo un nuovo oggetto con new
p = new Particle (width/2, height/2, 1.2, -2.7, 20);
p1 = new Particle (width/3, 200, 5, 3, 40)
}
function draw() {
background (100);
fill (80, 10, 110);
textSize (15);
text ('tempo: ' + t, 10, 25 );
p.universe ();
p.MRU (dt);
p.DRAWparticle ();
t += dt;
p1.universe ()
p1.MRU (dt)
p.DRAWparticle ()
t += dt
// sommo una stringa a una variabile per concatenare due stringhe.
// t viene automaticamente convertita in stringa
/*// aggiornare le variabili di stato
x = x + Vx * dt;
y = y + Vy * dt;
// incremento la variabile del tempo
t += dt;
// disegnare la particella
fill (0);
ellipse (x, y, 2 * r);
// universo sferico. no graffe perchè è un'istruzione
if (x > width) x = 0
if (x < 0) x = width
if (y > height) y = 0
if (y < 0) y = height*/
/*function MRU (px, py, velx, vely, deltat, tempo) {
px = px + velx * deltat
py = py + vely * deltat
tempo += deltat
// può usare le variabili in quanto variabili globali, ma non è proprio da funzione
}
function particle () {
fill (0);
ellipse (x, y, 2 * r);
}
function universe () {
if (x > width) x = 0
if (x < 0) x = width
if (y > height) y = 0
if (y < 0) y = height*/
}