diff options
Diffstat (limited to 'projects/projectile/index.js')
| -rw-r--r-- | projects/projectile/index.js | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/projects/projectile/index.js b/projects/projectile/index.js index f27f474..864384b 100644 --- a/projects/projectile/index.js +++ b/projects/projectile/index.js @@ -1,8 +1,8 @@ let t=0; let v0=50 -let x0=50 -let y0=50 +let x0=60 +let y0=60 let g=9.81 let projectile= function (node){ @@ -12,9 +12,19 @@ let projectile= function (node){ node.setup = function() { c=node.createCanvas(Math.min(window.innerWidth,width), height); - v0t=node.createElement('p', ''); + + v0t=node.createElement('span', ''); katex.render("v_0", v0t.elt); - v0t.elt.style.color="#b4b4b4" + v0t.elt.style.color="white" + + r=node.createElement('span', ''); + katex.render("\\vec{r}(t)", r.elt); + r.elt.style.color="white" + + vt=node.createElement('span', ''); + katex.render("v(t)", vt.elt); + vt.elt.style.color="white" + }; // See explanations @@ -26,6 +36,10 @@ let projectile= function (node){ return height - (-1/2 * g * t**2 + v0 * t + y0) } + function v(t) { + return (-g * t + v0) + } + node.draw = function() { node.background(70); @@ -35,23 +49,23 @@ let projectile= function (node){ node.ellipse(x(t),y(t),20,20); node.fill(255) dots.push([x(t),y(t)]) - if(t>50 || y(t)>height){ - node.noLoop() - } - t+=0.05 node.push() node.fill(22) node.stroke(180) - m=draw_arrow(node,x0,height-y0,x0+v0,height-y0-v0) - console.log(m.y) - v0t.position(c.position().x+m.x,c.position().y+m.y) - node.pop() + draw_arrow(node,x(t),y(t),x(t)+x0,y(t)-v(t),vt,c) + draw_arrow(node,x0,height-y0,x(t),y(t),r,c) + draw_arrow(node,x0,height-y0,x0+v0,height-(y0+v0),v0t,c) + if(t>50 || (height-y0)<y(t)){ + node.stop() + } + t+=0.05 }; node.windowResized = function(){ - v0t.position(c.position().x+m.x,c.position().y+m.y) node.resizeCanvas(Math.min(window.innerWidth,width), height); - + draw_arrow(node,x(t),y(t),x(t)+x0,y(t)-v(t),vt,c,true) + draw_arrow(node,x0,height-y0,x(t),y(t),r,c,true) + draw_arrow(node,x0,height-y0,x0+v0,height-(y0+v0),v0t,c,true) } }; |
