diff --git a/projects/projectile/index.html b/projects/projectile/index.html index f577c45..07e03ef 100644 --- a/projects/projectile/index.html +++ b/projects/projectile/index.html @@ -2,28 +2,28 @@
\(x_0\)
- +
\(m\)
\(y_0\)
- +
\(m\)
\(v_{0,x}\)
- +
\(m.s\)
\(v_{0,y}\)
- +
\(m.s\)
diff --git a/projects/projectile/index.js b/projects/projectile/index.js index 9409095..1c408c0 100644 --- a/projects/projectile/index.js +++ b/projects/projectile/index.js @@ -10,7 +10,7 @@ let projectile= function (p){ let width=800 let height=300 let dots=[] // Dots that show the projectile path - let end=false; + p.end=false; p.setup = function() { c=p.createCanvas(Math.min(window.innerWidth,width), height); @@ -32,7 +32,7 @@ let projectile= function (p){ }; - + // See explanations in html function xt(t) { return x0+vx0*t @@ -46,29 +46,39 @@ let projectile= function (p){ function vy(t) { return -g * t + vy0 } + + p.v0_redraw=function(vx0,vy0){ + p.draw(p.createVector(vx0,vy0)) + } - let draw_vectors=function(x,y,skiparrow=false){ + let draw_vectors=function(x,y,newV0,skiparrow=false){ p.push() + p.stroke(199, 141, 107) draw_arrow(p,x,y,x+vx(t),y-vy(t),vt,c,skiparrow) p.stroke(200) draw_arrow(p,x0,height-y0,x,y,r,c,skiparrow) - p.stroke(181, 107, 199) - draw_arrow(p,x0,height-y0,x0+vx0,height-(y0+vy0),vy0t,c,skiparrow) - p.stroke(121, 199, 107) draw_arrow(p,x0,height-y0,x0,height-y0-50,vj,c,skiparrow,true) p.stroke(199,119,107) draw_arrow(p,x0,height-y0,x0+50,height-y0,vi,c,skiparrow) + p.stroke(181, 107, 199) + if(newV0==null){ + draw_arrow(p,x0,height-y0,x0+vx0,height-(y0+vy0),vy0t,c,skiparrow) + } + else{ + draw_arrow(p,x0,height-y0,x0+newV0.x,height-(y0+newV0.y),vy0t,c,skiparrow) + } + p.pop() } - p.draw = function() { + p.draw = function(newV0=null) { p.clear() let x=xt(t) let y=yt(t) @@ -83,7 +93,7 @@ let projectile= function (p){ p.pop() // Draw vectors - draw_vectors(x,y) + draw_vectors(x,y,newV0=newV0) p.push() p.stroke(0) @@ -92,12 +102,12 @@ let projectile= function (p){ // Check simulation state and update it if(t>50 || (height-y0)