├── .DS_Store ├── README ├── buildIndex.sh ├── examples ├── build.sh ├── ch02 │ ├── eventdemo │ │ ├── eventdemo.dart │ │ ├── eventdemo.dart.app.js │ │ └── eventdemo.html │ ├── keyboardevents │ │ ├── keyboardevents.dart │ │ ├── keyboardevents.dart.app.js │ │ └── keyboardevents.html │ ├── keycodes │ │ ├── keycodes.dart │ │ ├── keycodes.dart.app.js │ │ └── keycodes.html │ ├── keynames │ │ ├── keynames.dart │ │ ├── keynames.dart.app.js │ │ └── keynames.html │ ├── mouseevents │ │ ├── mouseevents.dart │ │ ├── mouseevents.dart.app.js │ │ └── mouseevents.html │ ├── mouseposition │ │ ├── mouseposition.dart │ │ ├── mouseposition.dart.app.js │ │ └── mouseposition.html │ ├── skeleton │ │ ├── skeleton.dart │ │ ├── skeleton.dart.app.js │ │ └── skeleton.html │ └── touchevents │ │ ├── touchevents.dart │ │ ├── touchevents.dart.app.js │ │ └── touchevents.html ├── ch03 │ ├── bobbing │ │ ├── bobbing.dart │ │ ├── bobbing.dart.app.js │ │ └── bobbing.html │ ├── bobbing2 │ │ ├── bobbing2.dart │ │ ├── bobbing2.dart.app.js │ │ └── bobbing2.html │ ├── circle │ │ ├── circle.dart │ │ ├── circle.dart.app.js │ │ └── circle.html │ ├── classes │ │ ├── arrow.dart │ │ └── ball.dart │ ├── distance1 │ │ ├── distance1.dart │ │ ├── distance1.dart.app.js │ │ ├── distance1.html │ │ └── rectLocal.dart │ ├── mousedistance │ │ ├── mousedistance.dart │ │ ├── mousedistance.dart.app.js │ │ ├── mousedistance.html │ │ └── rectLocal.dart │ ├── oval │ │ ├── oval.dart │ │ ├── oval.dart.app.js │ │ └── oval.html │ ├── pluse │ │ ├── pluse.dart │ │ ├── pluse.dart.app.js │ │ └── pluse.html │ ├── random │ │ ├── random.dart │ │ ├── random.dart.app.js │ │ └── random.html │ ├── rotatetomouse │ │ ├── rotatetomouse.dart │ │ ├── rotatetomouse.dart.app.js │ │ └── rotatetomouse.html │ ├── wave1 │ │ ├── wave1.dart │ │ ├── wave1.dart.app.js │ │ └── wave1.html │ └── wave2 │ │ ├── wave2.dart │ │ ├── wave2.dart.app.js │ │ └── wave2.html ├── ch04 │ ├── assets │ │ ├── movieclip.mp4 │ │ ├── movieclip.ogv │ │ ├── movieclip.webm │ │ └── picture.jpg │ ├── classes │ │ └── point.dart │ ├── curvethroughpoint │ │ ├── curvethroughpoint.dart │ │ ├── curvethroughpoint.dart.app.js │ │ └── curvethroughpoint.html │ ├── drawingapp │ │ ├── drawingapp.dart │ │ ├── drawingapp.dart.app.js │ │ └── drawingapp.html │ ├── drawingcurves │ │ ├── drawingcurves.dart │ │ ├── drawingcurves.dart.app.js │ │ └── drawingcurves.html │ ├── embedimage │ │ ├── embedimage.dart │ │ ├── embedimage.dart.app.js │ │ └── embedimage.html │ ├── gradientfill1 │ │ ├── gradientfill1.dart │ │ ├── gradientfill1.dart.app.js │ │ └── gradientfill1.html │ ├── gradientfill2 │ │ ├── gradientfill2.dart │ │ ├── gradientfill2.dart.app.js │ │ └── gradientfill2.html │ ├── gradientfillradial │ │ ├── gradientfillradial.dart │ │ ├── gradientfillradial.dart.app.js │ │ └── gradientfillradial.html │ ├── grayscale │ │ ├── grayscale.dart │ │ ├── grayscale.dart.app.js │ │ └── grayscale.html │ ├── invertcolor │ │ ├── invertcolor.dart │ │ ├── invertcolor.dart.app.js │ │ └── invertcolor.html │ ├── loadimage │ │ ├── loadimage.dart │ │ ├── loadimage.dart.app.js │ │ └── loadimage.html │ ├── multicurve1 │ │ ├── multicurve1.dart │ │ ├── multicurve1.dart.app.js │ │ ├── multicurve1.html │ │ └── point.dart │ ├── multicurve2 │ │ ├── multicurve2.dart │ │ ├── multicurve2.dart.app.js │ │ ├── multicurve2.html │ │ └── point.dart │ ├── multicurve3 │ │ ├── multicurve3.dart │ │ ├── multicurve3.dart.app.js │ │ ├── multicurve3.html │ │ └── point.dart │ ├── pixelmove │ │ ├── pixelmove.dart │ │ ├── pixelmove.dart.app.js │ │ └── pixelmove.html │ ├── spraypaint │ │ ├── spraypaint.dart │ │ ├── spraypaint.dart.app.js │ │ └── spraypaint.html │ └── videoframes │ │ ├── videoframes.dart │ │ ├── videoframes.dart.app.js │ │ └── videoframes.html ├── ch05 │ ├── acceleration1 │ │ ├── acceleration1.dart │ │ ├── acceleration1.dart.app.js │ │ └── acceleration1.html │ ├── acceleration2 │ │ ├── acceleration2.dart │ │ ├── acceleration2.dart.app.js │ │ └── acceleration2.html │ ├── acceleration3 │ │ ├── acceleration3.dart │ │ ├── acceleration3.dart.app.js │ │ └── acceleration3.html │ ├── classes │ │ ├── arrow.dart │ │ ├── ball.dart │ │ └── ship.dart │ ├── followmouse1 │ │ ├── followmouse1.dart │ │ ├── followmouse1.dart.app.js │ │ └── followmouse1.html │ ├── followmouse2 │ │ ├── followmouse2.dart │ │ ├── followmouse2.dart.app.js │ │ └── followmouse2.html │ ├── gravity │ │ ├── gravity.dart │ │ ├── gravity.dart.app.js │ │ └── gravity.html │ ├── rotationalvelocity │ │ ├── rotationalvelocity.dart │ │ ├── rotationalvelocity.dart.app.js │ │ └── rotationalvelocity.html │ ├── shipsim │ │ ├── shipsim.dart │ │ ├── shipsim.dart.app.js │ │ └── shipsim.html │ ├── velocity1 │ │ ├── velocity1.dart │ │ ├── velocity1.dart.app.js │ │ └── velocity1.html │ ├── velocity2 │ │ ├── velocity2.dart │ │ ├── velocity2.dart.app.js │ │ └── velocity2.html │ └── velocityangle │ │ ├── velocityangle.dart │ │ ├── velocityangle.dart.app.js │ │ └── velocityangle.html ├── ch06 │ ├── bouncing1 │ │ ├── bouncing.dart │ │ ├── bouncing.dart.app.js │ │ └── bouncing.html │ ├── bouncing2 │ │ ├── bouncing2.dart │ │ ├── bouncing2.dart.app.js │ │ └── bouncing2.html │ ├── classes │ │ ├── ball.dart │ │ └── ship.dart │ ├── fountain │ │ ├── fountain.dart │ │ ├── fountain.dart.app.js │ │ └── fountain.html │ ├── friction1 │ │ ├── friction1.dart │ │ ├── friction1.dart.app.js │ │ └── friction1.html │ ├── friction2 │ │ ├── friction2.dart │ │ ├── friction2.dart.app.js │ │ └── friction2.html │ ├── removal │ │ ├── removal.dart │ │ ├── removal.dart.app.js │ │ └── removal.html │ ├── shipsim │ │ ├── shipsim.dart │ │ ├── shipsim.dart.app.js │ │ └── shipsim.html │ └── shipsimfriction │ │ ├── shipsimfriction.dart │ │ ├── shipsimfriction.dart.app.js │ │ └── shipsimfriction.html ├── ch07 │ ├── classes │ │ ├── ball.dart │ │ └── bound.dart │ ├── dragandmove1 │ │ ├── dragandmove1.dart │ │ ├── dragandmove1.dart.app.js │ │ └── dragandmove1.html │ ├── dragandmove2 │ │ ├── dragandmove2.dart │ │ ├── dragandmove2.dart.app.js │ │ └── dragandmove2.html │ ├── mouseevents │ │ ├── mouseevents.dart │ │ ├── mouseevents.dart.app.js │ │ └── mouseevents.html │ ├── mousemovedrag │ │ ├── mousemovedrag.dart │ │ ├── mousemovedrag.dart.app.js │ │ └── mousemovedrag.html │ ├── throwing │ │ ├── throwing.dart │ │ ├── throwing.dart.app.js │ │ └── throwing.html │ └── touchevents │ │ ├── touchevents.dart │ │ ├── touchevents.dart.app.js │ │ └── touchevents.html ├── ch08 │ ├── chain │ │ ├── chain.dart │ │ ├── chain.dart.app.js │ │ └── chain.html │ ├── chainarray │ │ ├── chainarray.dart │ │ ├── chainarray.dart.app.js │ │ └── chainarray.html │ ├── classes │ │ ├── ball.dart │ │ └── bound.dart │ ├── doublespring │ │ ├── doublespring.dart │ │ ├── doublespring.dart.app.js │ │ └── doublespring.html │ ├── easetomove │ │ ├── easetomove.dart │ │ ├── easetomove.dart.app.js │ │ └── easetomove.html │ ├── easing1 │ │ ├── easing1.dart │ │ ├── easing1.dart.app.js │ │ └── easing1.html │ ├── easing2 │ │ ├── easing2.dart │ │ ├── easing2.dart.app.js │ │ └── easing2.html │ ├── easingoff │ │ ├── easingoff.dart │ │ ├── easingoff.dart.app.js │ │ └── easingoff.html │ ├── multispring │ │ ├── multispring.dart │ │ ├── multispring.dart.app.js │ │ └── multispring.html │ ├── offsetspring │ │ ├── offsetspring.dart │ │ ├── offsetspring.dart.app.js │ │ └── offsetspring.html │ ├── spring1 │ │ ├── spring1.dart │ │ ├── spring1.dart.app.js │ │ └── spring1.html │ ├── spring2 │ │ ├── spring2.dart │ │ ├── spring2.dart.app.js │ │ └── spring2.html │ ├── spring3 │ │ ├── spring3.dart │ │ ├── spring3.dart.app.js │ │ └── spring3.html │ ├── spring4 │ │ ├── spring4.dart │ │ ├── spring4.dart.app.js │ │ └── spring4.html │ ├── spring5 │ │ ├── spring5.dart │ │ ├── spring5.dart.app.js │ │ └── spring5.html │ └── triplespring │ │ ├── triplespring.dart │ │ ├── triplespring.dart.app.js │ │ └── triplespring.html ├── ch09 │ ├── boxes │ │ ├── boxes.dart │ │ ├── boxes.dart.app.js │ │ └── boxes.html │ ├── bubbles1 │ │ ├── bubbles1.dart │ │ ├── bubbles1.dart.app.js │ │ └── bubbles1.html │ ├── bubbles2 │ │ ├── bubbles2.dart │ │ ├── bubbles2.dart.app.js │ │ └── bubbles2.html │ ├── bubbles3 │ │ ├── bubbles3.dart │ │ ├── bubbles3.dart.app.js │ │ └── bubbles3.html │ ├── classes │ │ ├── ball.dart │ │ ├── bound.dart │ │ └── box.dart │ ├── distance1 │ │ ├── distance1.dart │ │ ├── distance1.dart.app.js │ │ └── distance1.html │ ├── distance2 │ │ ├── distance2.dart │ │ ├── distance2.dart.app.js │ │ └── distance2.html │ ├── objecthittest │ │ ├── objecthittest.dart │ │ ├── objecthittest.dart.app.js │ │ └── objecthittest.html │ └── pointhittest │ │ ├── pointhittest.dart │ │ ├── pointhittest.dart.app.js │ │ └── pointhittest.html ├── ch10 │ ├── anglebounce │ │ ├── anglebounce.dart │ │ ├── anglebounce.dart.app.js │ │ └── anglebounce.html │ ├── anglebouncebounds │ │ ├── anglebouncebounds.dart │ │ ├── anglebouncebounds.dart.app.js │ │ └── anglebouncebounds.html │ ├── anglebouncefinal │ │ ├── anglebouncefinal.dart │ │ ├── anglebouncefinal.dart.app.js │ │ └── anglebouncefinal.html │ ├── anglebouncehittest │ │ ├── anglebouncehittest.dart │ │ ├── anglebouncehittest.dart.app.js │ │ └── anglebouncehittest.html │ ├── anglebounceopt │ │ ├── anglebounceopt.dart │ │ ├── anglebounceopt.dart.app.js │ │ └── anglebounceopt.html │ ├── anglebouncerotate │ │ ├── anglebouncerotate.dart │ │ ├── anglebouncerotate.dart.app.js │ │ └── anglebouncerotate.html │ ├── classes │ │ ├── ball.dart │ │ ├── bound.dart │ │ ├── box.dart │ │ └── line.dart │ ├── multianglebounce │ │ ├── multianglebounce.dart │ │ ├── multianglebounce.dart.app.js │ │ └── multianglebounce.html │ ├── rotate1 │ │ ├── rotate1.dart │ │ ├── rotate1.dart.app.js │ │ └── rotate1.html │ ├── rotate2 │ │ ├── rotate2.dart │ │ ├── rotate2.dart.app.js │ │ └── rotate2.html │ └── rotate3 │ │ ├── rotate3.dart │ │ ├── rotate3.dart.app.js │ │ └── rotate3.html ├── ch11 │ ├── billiard1 │ │ ├── billiard1.dart │ │ ├── billiard1.dart.app.js │ │ └── billiard1.html │ ├── billiard2 │ │ ├── billiard2.dart │ │ ├── billiard2.dart.app.js │ │ └── billiard2.html │ ├── billiard3 │ │ ├── billiard3.dart │ │ ├── billiard3.dart.app.js │ │ └── billiard3.html │ ├── billiard4 │ │ ├── billiard4.dart │ │ ├── billiard4.dart.app.js │ │ ├── billiard4.html │ │ └── point.dart │ ├── classes │ │ ├── ball.dart │ │ └── bound.dart │ ├── multibilliard1 │ │ ├── multibilliard1.dart │ │ ├── multibilliard1.dart.app.js │ │ ├── multibilliard1.html │ │ └── point.dart │ └── multibilliard2 │ │ ├── multibilliard2.dart │ │ ├── multibilliard2.dart.app.js │ │ ├── multibilliard2.html │ │ └── point.dart ├── ch12 │ ├── classes │ │ ├── ball.dart │ │ ├── bound.dart │ │ └── point.dart │ ├── gravity │ │ ├── gravity.dart │ │ ├── gravity.dart.app.js │ │ └── gravity.html │ ├── gravitybounce │ │ ├── gravitybounce.dart │ │ ├── gravitybounce.dart.app.js │ │ └── gravitybounce.html │ ├── gravityrandom │ │ ├── gravityrandom.dart │ │ ├── gravityrandom.dart.app.js │ │ └── gravityrandom.html │ ├── nodegarden │ │ ├── nodegarden.dart │ │ ├── nodegarden.dart.app.js │ │ └── nodegarden.html │ ├── nodegardenlines │ │ ├── nodegardenlines.dart │ │ ├── nodegardenlines.dart.app.js │ │ └── nodegardenlines.html │ ├── nodegardenmass │ │ ├── nodegardenmass.dart │ │ ├── nodegardenmass.dart.app.js │ │ └── nodegardenmass.html │ ├── orbit │ │ ├── orbit.dart │ │ ├── orbit.dart.app.js │ │ └── orbit.html │ └── orbitdraw │ │ ├── orbitdraw.dart │ │ ├── orbitdraw.dart.app.js │ │ └── orbitdraw.html ├── ch13 │ ├── classes │ │ ├── bound.dart │ │ ├── point.dart │ │ ├── segment.dart │ │ └── slider.dart │ ├── realwalk │ │ ├── realwalk.dart │ │ ├── realwalk.dart.app.js │ │ └── realwalk.html │ ├── segment │ │ ├── segment.dart │ │ ├── segment.dart.app.js │ │ └── segment.html │ ├── singlesegment │ │ ├── singlesegment.dart │ │ ├── singlesegment.dart.app.js │ │ └── singlesegment.html │ ├── twosegments1 │ │ ├── twosegments1.dart │ │ ├── twosegments1.dart.app.js │ │ └── twosegments1.html │ ├── twosegments2 │ │ ├── twosegments2.dart │ │ ├── twosegments2.dart.app.js │ │ └── twosegments2.html │ ├── walking1 │ │ ├── walking1.dart │ │ ├── walking1.dart.app.js │ │ └── walking1.html │ ├── walking2 │ │ ├── walking2.dart │ │ ├── walking2.dart.app.js │ │ └── walking2.html │ ├── walking3 │ │ ├── walking3.dart │ │ ├── walking3.dart.app.js │ │ └── walking3.html │ ├── walking4 │ │ ├── walking4.dart │ │ ├── walking4.dart.app.js │ │ └── walking4.html │ └── walking5 │ │ ├── walking5.dart │ │ ├── walking5.dart.app.js │ │ └── walking5.html ├── ch14 │ ├── classes │ │ ├── ball.dart │ │ ├── bound.dart │ │ ├── point.dart │ │ ├── segment.dart │ │ └── slider.dart │ ├── cosines1 │ │ ├── cosines1.dart │ │ ├── cosines1.dart.app.js │ │ └── cosines1.html │ ├── cosines2 │ │ ├── cosines2.dart │ │ ├── cosines2.dart.app.js │ │ └── cosines2.html │ ├── multisegmentdrag │ │ ├── multisegmentdrag.dart │ │ ├── multisegmentdrag.dart.app.js │ │ └── multisegmentdrag.html │ ├── multisegmentreach │ │ ├── multisegmentreach.dart │ │ ├── multisegmentreach.dart.app.js │ │ └── multisegmentreach.html │ ├── onesegment │ │ ├── onesegment.dart │ │ ├── onesegment.dart.app.js │ │ └── onesegment.html │ ├── onesegmentdrag │ │ ├── onesegmentdrag.dart │ │ ├── onesegmentdrag.dart.app.js │ │ └── onesegmentdrag.html │ ├── playball │ │ ├── playball.dart │ │ ├── playball.dart.app.js │ │ └── playball.html │ ├── twosegmentdrag │ │ ├── twosegmentdrag.dart │ │ ├── twosegmentdrag.dart.app.js │ │ └── twosegmentdrag.html │ └── twosegmentreach │ │ ├── twosegmentreach.dart │ │ ├── twosegmentreach.dart.app.js │ │ └── twosegmentreach.html ├── ch15 │ ├── bounce3d │ │ ├── bounce3d.dart │ │ ├── bounce3d.dart.app.js │ │ └── bounce3d.html │ ├── bouncyballs │ │ ├── bouncyballs.dart │ │ ├── bouncyballs.dart.app.js │ │ └── bouncyballs.html │ ├── classes │ │ ├── ball.dart │ │ ├── ball3d.dart │ │ ├── bound.dart │ │ └── tree.dart │ ├── collision3d │ │ ├── collision3d.dart │ │ ├── collision3d.dart.app.js │ │ └── collision3d.html │ ├── easing3d │ │ ├── easing3d.dart │ │ ├── easing3d.dart.app.js │ │ └── easing3d.html │ ├── multibounce3d │ │ ├── multibounce3d.dart │ │ ├── multibounce3d.dart.app.js │ │ └── multibounce3d.html │ ├── perspective1 │ │ ├── perspective1.dart │ │ ├── perspective1.dart.app.js │ │ └── perspective1.html │ ├── perspective2 │ │ ├── perspective2.dart │ │ ├── perspective2.dart.app.js │ │ └── perspective2.html │ ├── rotatexy │ │ ├── rotatexy.dart │ │ ├── rotatexy.dart.app.js │ │ └── rotatexy.html │ ├── rotatey │ │ ├── rotatey.dart │ │ ├── rotatey.dart.app.js │ │ └── rotatey.html │ ├── spring3d │ │ ├── spring3d.dart │ │ ├── spring3d.dart.app.js │ │ └── spring3d.html │ ├── trees │ │ ├── trees.dart │ │ ├── trees.dart.app.js │ │ └── trees.html │ ├── trees2 │ │ ├── trees2.dart │ │ ├── trees2.dart.app.js │ │ └── trees2.html │ ├── velocity3d │ │ ├── velocity3d.dart │ │ ├── velocity3d.dart.app.js │ │ └── velocity3d.html │ └── zsort │ │ ├── zsort.dart │ │ ├── zsort.dart.app.js │ │ └── zsort.html ├── ch16 │ ├── classes │ │ ├── ball3d.dart │ │ ├── point3d.dart │ │ └── triangle.dart │ ├── cube │ │ ├── cube.dart │ │ ├── cube.dart.app.js │ │ └── cube.html │ ├── cylinder │ │ ├── cylinder.dart │ │ ├── cylinder.dart.app.js │ │ └── cylinder.html │ ├── extrudeda │ │ ├── extrudeda.dart │ │ ├── extrudeda.dart.app.js │ │ └── extrudeda.html │ ├── fillede │ │ ├── fillede.dart │ │ ├── fillede.dart.app.js │ │ └── fillede.html │ ├── lines3d1 │ │ ├── lines3d1.dart │ │ ├── lines3d1.dart.app.js │ │ └── lines3d1.html │ ├── lines3d2 │ │ ├── lines3d2.dart │ │ ├── lines3d2.dart.app.js │ │ └── lines3d2.html │ ├── movecube1 │ │ ├── movecube1.dart │ │ ├── movecube1.dart.app.js │ │ └── movecube1.html │ ├── movecube2 │ │ ├── movecube2.dart │ │ ├── movecube2.dart.app.js │ │ └── movecube2.html │ ├── pyramid │ │ ├── pyramid.dart │ │ ├── pyramid.dart.app.js │ │ └── pyramid.html │ ├── spinninge │ │ ├── spinninge.dart │ │ ├── spinninge.dart.app.js │ │ └── spinninge.html │ ├── square3d │ │ ├── square3d.dart │ │ ├── square3d.dart.app.js │ │ └── square3d.html │ └── triangles1 │ │ ├── triangles1.dart │ │ ├── triangles1.dart.app.js │ │ └── triangles1.html ├── ch17 │ ├── classes │ │ ├── light.dart │ │ ├── point3d.dart │ │ ├── triangle-light.dart │ │ └── triangle.dart │ ├── extrudedacull │ │ ├── extrudedacull.dart │ │ ├── extrudedacull.dart.app.js │ │ └── extrudedacull.html │ ├── extrudedadepth │ │ ├── extrudedadepth.dart │ │ ├── extrudedadepth.dart.app.js │ │ └── extrudedadepth.html │ └── extrudedalight │ │ ├── extrudedalight.dart │ │ ├── extrudedalight.dart.app.js │ │ └── extrudedalight.html ├── ch18 │ ├── classes │ │ └── ball3d.dart │ ├── matrixrotate │ │ ├── matrixrotate.dart │ │ ├── matrixrotate.dart.app.js │ │ └── matrixrotate.html │ ├── rotatexy │ │ ├── rotatexy.dart │ │ ├── rotatexy.dart.app.js │ │ └── rotatexy.html │ ├── skewx │ │ ├── skewx.dart │ │ ├── skewx.dart.app.js │ │ └── skewx.html │ └── skewxy │ │ ├── skewxy.dart │ │ ├── skewxy.dart.app.js │ │ └── skewxy.html ├── ch19 │ ├── assets │ │ ├── boing.mp3 │ │ ├── boing.ogg │ │ └── boing.wav │ ├── brownian1 │ │ ├── brownian1.dart │ │ ├── brownian1.dart.app.js │ │ └── brownian1.html │ ├── brownian2 │ │ ├── brownian2.dart │ │ ├── brownian2.dart.app.js │ │ └── brownian2.html │ ├── classes │ │ ├── ball.dart │ │ ├── bound.dart │ │ └── point.dart │ ├── random1 │ │ ├── random1.dart │ │ ├── random1.dart.app.js │ │ └── random1.html │ ├── random2 │ │ ├── random2.dart │ │ ├── random2.dart.app.js │ │ └── random2.html │ ├── random3 │ │ ├── random3.dart │ │ ├── random3.dart.app.js │ │ └── random3.html │ ├── random4 │ │ ├── random4.dart │ │ ├── random4.dart.app.js │ │ └── random4.html │ ├── random5 │ │ ├── random5.dart │ │ ├── random5.dart.app.js │ │ └── random5.html │ ├── random6 │ │ ├── random6.dart │ │ ├── random6.dart.app.js │ │ └── random6.html │ ├── random7 │ │ ├── random7.dart │ │ ├── random7.dart.app.js │ │ └── random7.html │ ├── random8 │ │ ├── random8.dart │ │ ├── random8.dart.app.js │ │ └── random8.html │ ├── samemass │ │ ├── samemass.dart │ │ ├── samemass.dart.app.js │ │ └── samemass.html │ ├── soundevents │ │ ├── soundevents.dart │ │ ├── soundevents.dart.app.js │ │ └── soundevents.html │ ├── timebased1 │ │ ├── timebased1.dart │ │ ├── timebased1.dart.app.js │ │ └── timebased1.html │ ├── timebased2 │ │ ├── timebased2.dart │ │ ├── timebased2.dart.app.js │ │ └── timebased2.html │ ├── timebased3 │ │ ├── timebased3.dart │ │ ├── timebased3.dart.app.js │ │ └── timebased3.html │ └── timer1 │ │ ├── timer1.dart │ │ ├── timer1.dart.app.js │ │ └── timer1.html ├── clean.sh ├── gitClean.sh └── include │ ├── book-thumb.jpg │ ├── color.dart │ ├── file_icon.png │ ├── keycode.dart │ ├── mouse.dart │ ├── style.css │ ├── touch.dart │ ├── utils.dart │ └── utilslib.dart └── index.html /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/.DS_Store -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Sample code from https://github.com/lamberta/html5-animation coverted to dart. 2 | 3 | examples/ch04/videoframes sample does not work. This might be a bug that needs to get filed with dart. 4 | -------------------------------------------------------------------------------- /buildIndex.sh: -------------------------------------------------------------------------------- 1 | HEAD=" 2 | 3 | 4 | 5 | 6 | Index 7 | 8 | 9 |
10 |
11 | "; 12 | TAIL=" 13 | 14 | 15 | "; 16 | echo $HEAD 17 | EXAMPLELINKS=`find ./examples | grep .html`; 18 | for l in $EXAMPLELINKS 19 | do 20 | echo "
$l"; 21 | done 22 | echo $TAIL 23 | -------------------------------------------------------------------------------- /examples/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ~/Documents/DartEditor/dart/dart-sdk/bin/frogc --out=./eventdemo.dart.app.js ./eventdemo.dart 3 | #DART_SDK=~/Documents/DartEditor/dart/dart-sdk/ 4 | #DART_SDK=/Users/adam/Documents/DartEditor/snapshots/dart-macos-2380 5 | #FROGC=$DART_SDK/bin/frogc 6 | #~/dart_bleeding/dart/out/Debug_ia32/dartc --out ./circle.dart.js ./circle.dart 7 | # building these examples with dartc cause frogc fails on some of the canvas stuff 8 | #DARTC=~/dart_bleeding/dart/out/Debug_ia32/dartc 9 | MINFROG=~/dart_bleeding/dart/frog/minfrog 10 | for htmlFile in `find . -type f -name "*.html"` 11 | do 12 | htmlDirectory=${htmlFile%/*} 13 | htmlFileName=${htmlFile##*/} 14 | name=`echo "$htmlFileName" | cut -d'.' -f1;` 15 | #echo "RUNNING: $FROGC --out=$htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart" 16 | #$FROGC --out=$htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart 17 | #echo "RUNNING: $DARTC --out $htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart" 18 | #$DARTC --out $htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart 19 | echo "RUNNING: $MINFROG --compile-only --out=$htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart" 20 | $MINFROG --compile-only --out=$htmlDirectory/$name.dart.app.js $htmlDirectory/$name.dart 21 | rm -rf out 22 | done; 23 | -------------------------------------------------------------------------------- /examples/ch02/eventdemo/eventdemo.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class eventdemo { 4 | 5 | eventdemo() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | canvas.on.mouseDown.add((Event e) { 11 | print('mouse down'); 12 | }, false); 13 | 14 | canvas.on.mouseUp.add((Event e) { 15 | print('mouse up'); 16 | }, false); 17 | } 18 | } 19 | 20 | void main() { 21 | new eventdemo().run(); 22 | } 23 | -------------------------------------------------------------------------------- /examples/ch02/eventdemo/eventdemo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Event Demo 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch02/keyboardevents/keyboardevents.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class keyboardevents { 4 | 5 | keyboardevents() { 6 | } 7 | 8 | void run() { 9 | 10 | onKeyboardEvent(Event e) { 11 | print('${e.type}'); 12 | }; 13 | 14 | document.window.on.keyDown.add(onKeyboardEvent, false); 15 | document.window.on.keyUp.add(onKeyboardEvent, false); 16 | } 17 | } 18 | 19 | void main() { 20 | new keyboardevents().run(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/ch02/keyboardevents/keyboardevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Keyboard Events 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch02/keycodes/keycodes.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class keycodes { 4 | 5 | keycodes() { 6 | } 7 | 8 | void run() { 9 | 10 | onKeyboardEvent(KeyboardEvent e) { 11 | switch(e.keyCode) { 12 | 13 | case 38: 14 | print('up!'); 15 | break; 16 | 17 | case 40: 18 | print('down!'); 19 | break; 20 | 21 | case 37: 22 | print('left!'); 23 | break; 24 | 25 | case 39: 26 | print('right!'); 27 | break; 28 | 29 | default: 30 | print('${e.keyCode}'); 31 | break; 32 | } 33 | }; 34 | 35 | document.window.on.keyDown.add(onKeyboardEvent, false); 36 | } 37 | } 38 | 39 | void main() { 40 | new keycodes().run(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch02/keycodes/keycodes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Key Codes 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch02/keynames/keynames.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | #import('../../include/utilslib.dart', prefix:'utilslib'); 4 | 5 | class keynames { 6 | 7 | keynames() { 8 | } 9 | 10 | void run() { 11 | 12 | onKeyboardEvent(KeyboardEvent e) { 13 | switch(e.keyCode) { 14 | 15 | case utilslib.Keycode.UP: 16 | print('up!'); 17 | break; 18 | 19 | case utilslib.Keycode.DOWN: 20 | print('down!'); 21 | break; 22 | 23 | case utilslib.Keycode.LEFT: 24 | print('left!'); 25 | break; 26 | 27 | case utilslib.Keycode.RIGHT: 28 | print('right!'); 29 | break; 30 | 31 | default: 32 | print('${e.keyCode}'); 33 | break; 34 | } 35 | }; 36 | 37 | document.window.on.keyDown.add(onKeyboardEvent, false); 38 | } 39 | } 40 | 41 | void main() { 42 | new keynames().run(); 43 | } 44 | -------------------------------------------------------------------------------- /examples/ch02/keynames/keynames.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Key Names 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch02/mouseevents/mouseevents.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class mouseevents { 4 | 5 | mouseevents() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | 11 | onMouseEvent(Event e) { 12 | print(e.type); 13 | }; 14 | 15 | canvas.on.mouseDown.add(onMouseEvent, false); 16 | canvas.on.mouseUp.add(onMouseEvent, false); 17 | canvas.on.click.add(onMouseEvent, false); 18 | canvas.on.dblClick.add(onMouseEvent, false); 19 | canvas.on.mouseWheel.add(onMouseEvent, false); 20 | canvas.on.mouseMove.add(onMouseEvent, false); 21 | canvas.on.mouseOver.add(onMouseEvent, false); 22 | canvas.on.mouseOut.add(onMouseEvent, false); 23 | } 24 | } 25 | 26 | void main() { 27 | new mouseevents().run(); 28 | } 29 | -------------------------------------------------------------------------------- /examples/ch02/mouseevents/mouseevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse Event 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch02/mouseposition/mouseposition.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | #import('../../include/utilslib.dart', prefix:'utilslib'); 4 | class mouseposition { 5 | 6 | mouseposition() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var mouse = utilslib.Utils.captureMouse(canvas); 12 | 13 | canvas.on.mouseDown.add((MouseEvent e) { 14 | print('x: ${mouse.x}, y: ${mouse.y} '); 15 | }, false); 16 | } 17 | } 18 | 19 | void main() { 20 | new mouseposition().run(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/ch02/mouseposition/mouseposition.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse Position 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch02/skeleton/skeleton.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class skeleton { 4 | 5 | skeleton() { 6 | } 7 | 8 | void run() { 9 | 10 | } 11 | 12 | void write(String message) { 13 | 14 | } 15 | } 16 | 17 | void main() { 18 | new skeleton().run(); 19 | } 20 | -------------------------------------------------------------------------------- /examples/ch02/skeleton/skeleton.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/ch02/touchevents/touchevents.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class touchevents { 4 | 5 | touchevents() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | onTouchEvent(Event e) { 11 | print('${e.type}'); 12 | }; 13 | 14 | canvas.on.touchStart.add(onTouchEvent, false); 15 | canvas.on.touchEnd.add(onTouchEvent, false); 16 | canvas.on.touchMove.add(onTouchEvent, false); 17 | } 18 | } 19 | 20 | void main() { 21 | new touchevents().run(); 22 | } 23 | -------------------------------------------------------------------------------- /examples/ch02/touchevents/touchevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Touch Events 6 | 7 | 8 | 9 | 10 |
11 | Example from Foundation HTML5 Animation with JavaScript 12 |
13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch03/bobbing/bobbing.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | class bobbing { 5 | 6 | bobbing() { 7 | 8 | } 9 | 10 | void run() { 11 | 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var angle = 0; 16 | 17 | ball.x = canvas.width / 2; 18 | ball.y = canvas.height / 2; 19 | 20 | drawFrame(int t) { 21 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 22 | context.clearRect(0,0,canvas.width,canvas.height); 23 | 24 | ball.y = canvas.height / 2 + Math.sin(angle) * 50; 25 | angle += 0.1; 26 | ball.draw(context); 27 | }; 28 | 29 | drawFrame(0); 30 | 31 | } 32 | 33 | 34 | } 35 | 36 | void main() { 37 | new bobbing().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch03/bobbing/bobbing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bobbing 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/bobbing2/bobbing2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | class bobbing2 { 5 | 6 | bobbing2() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var ball = new Ball(); 13 | var angle = 0; 14 | var centerY = 200; 15 | var range = 50; 16 | var speed = 0.05; 17 | 18 | ball.x = canvas.width / 2; 19 | 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0,0,canvas.width,canvas.height); 24 | 25 | //ball.y = canvas.height / 2 + Math.sin(angle) * 50; 26 | ball.y = centerY / 2 + Math.sin(angle) * range; 27 | angle += speed; 28 | ball.draw(context); 29 | }; 30 | 31 | drawFrame(0); 32 | } 33 | 34 | 35 | } 36 | 37 | void main() { 38 | new bobbing2().run(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/ch03/bobbing2/bobbing2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bobbing 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/circle/circle.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class circle { 6 | 7 | circle() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angle = 0; 15 | var centerX = canvas.width / 2; 16 | var centerY = canvas.height / 2; 17 | var radius = 50; 18 | var speed = 0.05; 19 | 20 | drawFrame(int t) { 21 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 22 | context.clearRect(0,0,canvas.width,canvas.height); 23 | 24 | ball.x = centerX + Math.sin(angle) * radius; 25 | ball.y = centerY + Math.cos(angle) * radius; 26 | angle += speed; 27 | 28 | ball.draw(context); 29 | }; 30 | 31 | drawFrame(0); 32 | } 33 | 34 | } 35 | 36 | void main() { 37 | new circle().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch03/circle/circle.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Circle 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/classes/arrow.dart: -------------------------------------------------------------------------------- 1 | class Arrow { 2 | int x; 3 | int y; 4 | String color; 5 | double rotation; 6 | 7 | Arrow() { 8 | x=0; 9 | y=0; 10 | color="#ffff00"; 11 | rotation=0.0; 12 | } 13 | 14 | void draw(var context) { 15 | 16 | context.save(); 17 | context.translate(x, y); 18 | context.rotate(rotation); 19 | 20 | context.lineWidth = 2; 21 | context.fillStyle = color; 22 | context.beginPath(); 23 | context.moveTo(-50, -25); 24 | context.lineTo(0, -25); 25 | context.lineTo(0, -50); 26 | context.lineTo(50, 0); 27 | context.lineTo(0, 50); 28 | context.lineTo(0, 25); 29 | context.lineTo(-50, 25); 30 | context.lineTo(-50, -25); 31 | context.closePath(); 32 | context.fill(); 33 | context.stroke(); 34 | 35 | context.restore(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch03/classes/ball.dart: -------------------------------------------------------------------------------- 1 | class Ball { 2 | num x; 3 | num y; 4 | num radius; 5 | num rotation; 6 | num scaleX; 7 | num scaleY; 8 | String color; 9 | num lineWidth; 10 | 11 | Ball() { 12 | this.radius=40; 13 | this.color='#ff0000'; 14 | this.x=0; 15 | this.y=0; 16 | this.rotation=0.0; 17 | this.scaleX=1; 18 | this.scaleY=1; 19 | this.lineWidth=1; 20 | } 21 | 22 | void draw(var context) { 23 | // CanvasRenderingContext2D 24 | context.save(); 25 | context.translate(x, y); 26 | context.rotate(rotation); 27 | context.scale(scaleX,scaleY); 28 | 29 | context.lineWidth = lineWidth; 30 | context.fillStyle = color; 31 | context.beginPath(); 32 | //x, y, radius, start_angle, end_angle, anti-clockwise 33 | context.arc(0, 0, radius, 0, (Math.PI * 2), true); 34 | context.closePath(); 35 | context.fill(); 36 | if (lineWidth > 0) { 37 | context.stroke(); 38 | } 39 | context.restore(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch03/distance1/distance1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('rectLocal.dart'); 4 | 5 | 6 | class distance1 { 7 | 8 | distance1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var log = document.query('#log'); 15 | 16 | //Create a black square, assign random position. 17 | var rect1 = new rectLocal( 18 | Math.random() * canvas.width, 19 | Math.random() * canvas.height); 20 | 21 | context.fillStyle = "#000000"; 22 | context.fillRect(rect1.x - 2, rect1.y - 2, 4, 4); 23 | 24 | //Create a red square, assign random position. 25 | var rect2 = new rectLocal( 26 | Math.random() * canvas.width, 27 | Math.random() * canvas.height); 28 | 29 | context.fillStyle = "#ff0000"; 30 | context.fillRect(rect2.x - 2, rect2.y - 2, 4, 4); 31 | 32 | //Calculate the distance between the two squares. 33 | var dx = rect1.x - rect2.x; 34 | var dy = rect1.y - rect2.y; 35 | var dist = Math.sqrt(dx * dx + dy * dy); 36 | 37 | //log output of distance value to screen 38 | log.value = "distance: " + dist; 39 | 40 | } 41 | 42 | 43 | } 44 | 45 | void main() { 46 | new distance1().run(); 47 | } 48 | -------------------------------------------------------------------------------- /examples/ch03/distance1/distance1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Distance 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/ch03/distance1/rectLocal.dart: -------------------------------------------------------------------------------- 1 | class rectLocal { 2 | num x; 3 | num y; 4 | rectLocal(this.x, this.y); 5 | } 6 | -------------------------------------------------------------------------------- /examples/ch03/mousedistance/mousedistance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse Distance 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch03/mousedistance/rectLocal.dart: -------------------------------------------------------------------------------- 1 | class rectLocal { 2 | num x; 3 | num y; 4 | rectLocal(this.x, this.y); 5 | } 6 | -------------------------------------------------------------------------------- /examples/ch03/oval/oval.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class oval { 6 | 7 | oval() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angle = 0; 15 | var centerX = canvas.width / 2; 16 | var centerY = canvas.height / 2; 17 | var radiusX = 150; 18 | var radiusY = 100; 19 | var speed = 0.05; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0,0,canvas.width,canvas.height); 24 | 25 | ball.x = centerX + Math.sin(angle) * radiusX; 26 | ball.y = centerY + Math.cos(angle) * radiusY; 27 | angle += speed; 28 | 29 | ball.draw(context); 30 | }; 31 | 32 | drawFrame(0); 33 | } 34 | } 35 | 36 | void main() { 37 | new oval().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch03/oval/oval.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Oval 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/pluse/pluse.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class pluse { 6 | 7 | pluse() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angle = 0; 15 | var centerScale = 1; 16 | var range = 0.5; 17 | var speed = 0.05; 18 | 19 | ball.x = canvas.width / 2; 20 | ball.y = canvas.height / 2; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0,0,canvas.width,canvas.height); 25 | 26 | ball.scaleX = ball.scaleY = centerScale + Math.sin(angle) * range; 27 | angle += speed; 28 | 29 | ball.draw(context); 30 | }; 31 | 32 | drawFrame(0); 33 | } 34 | 35 | 36 | } 37 | 38 | void main() { 39 | new pluse().run(); 40 | } 41 | -------------------------------------------------------------------------------- /examples/ch03/pluse/pluse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pulse 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/random/random.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class random { 6 | 7 | random() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angleX = 0; 15 | var angleY = 0; 16 | var range = 50; 17 | var centerX = canvas.width / 2; 18 | var centerY = canvas.height / 2; 19 | var xspeed = 0.07; 20 | var yspeed = 0.11; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0,0,canvas.width,canvas.height); 25 | 26 | ball.x = centerX + Math.sin(angleX) * range; 27 | ball.y = centerY + Math.sin(angleY) * range; 28 | angleX += xspeed; 29 | angleY += yspeed; 30 | 31 | ball.draw(context); 32 | }; 33 | 34 | drawFrame(0); 35 | } 36 | 37 | } 38 | 39 | void main() { 40 | new random().run(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch03/random/random.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/rotatetomouse/rotatetomouse.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/arrow.dart'); 4 | class rotatetomouse { 5 | 6 | rotatetomouse() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var mouse = utilslib.Utils.captureMouse(canvas); 12 | var context = canvas.getContext('2d'); 13 | var arrow = new Arrow(); 14 | arrow.x = canvas.width / 2; 15 | arrow.y = canvas.height / 2; 16 | mouse.x = 0; 17 | mouse.y = 0; 18 | 19 | drawFrame(int t) { 20 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 21 | context.clearRect(0,0,canvas.width,canvas.height); 22 | var dx = mouse.x - arrow.x; 23 | var dy = mouse.y - arrow.y; 24 | arrow.rotation = Math.atan2(dy,dx); 25 | arrow.draw(context); 26 | }; 27 | 28 | drawFrame(0); 29 | } 30 | 31 | } 32 | 33 | void main() { 34 | new rotatetomouse().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch03/rotatetomouse/rotatetomouse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate to Mouse 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch03/wave1/wave1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class wave1 { 6 | 7 | wave1() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angle = 0; 15 | var centerY = 200; 16 | var range = 50; 17 | var xspeed = 1; 18 | var yspeed = 0.05; 19 | 20 | ball.x = 0; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0,0,canvas.width,canvas.height); 25 | 26 | ball.x += xspeed; 27 | ball.y = centerY / 2 + Math.sin(angle) * range; 28 | angle += yspeed; 29 | 30 | ball.draw(context); 31 | }; 32 | 33 | drawFrame(0); 34 | } 35 | } 36 | 37 | void main() { 38 | new wave1().run(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/ch03/wave1/wave1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Wave 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch03/wave2/wave2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | 5 | class wave2 { 6 | 7 | wave2() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | 14 | var angle = 0; 15 | var range = 50; 16 | var centerY = canvas.height / 2; 17 | var xspeed = 1; 18 | var yspeed = 0.05; 19 | var xpos = 0; 20 | var ypos = centerY; 21 | 22 | context.lineWidth = 2; 23 | 24 | drawFrame(int t) { 25 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 26 | context.beginPath(); 27 | context.moveTo(xpos, ypos); 28 | //Calculate the new position. 29 | xpos += xspeed; 30 | angle += yspeed; 31 | ypos = centerY + Math.sin(angle) * range; 32 | context.lineTo(xpos, ypos); 33 | context.stroke(); 34 | }; 35 | 36 | drawFrame(0); 37 | } 38 | 39 | 40 | } 41 | 42 | void main() { 43 | new wave2().run(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/ch03/wave2/wave2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Wave 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/assets/movieclip.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch04/assets/movieclip.mp4 -------------------------------------------------------------------------------- /examples/ch04/assets/movieclip.ogv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch04/assets/movieclip.ogv -------------------------------------------------------------------------------- /examples/ch04/assets/movieclip.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch04/assets/movieclip.webm -------------------------------------------------------------------------------- /examples/ch04/assets/picture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch04/assets/picture.jpg -------------------------------------------------------------------------------- /examples/ch04/classes/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | point.withRadius(this.x,this.y,this.radius); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch04/curvethroughpoint/curvethroughpoint.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class curvethroughpoint { 5 | 6 | curvethroughpoint() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | var x0 = 100, 14 | y0 = 200, 15 | x2 = 300, 16 | y2 = 200; 17 | 18 | canvas.on.mouseMove.add((MouseEvent e) { 19 | context.clearRect(0, 0, canvas.width, canvas.height); 20 | 21 | var x1 = mouse.x * 2 - (x0 + x2) / 2, 22 | y1 = mouse.y * 2 - (y0 + y2) / 2; 23 | 24 | //curve through mouse 25 | context.beginPath(); 26 | context.moveTo(x0, y0); 27 | context.quadraticCurveTo(x1, y1, x2, y2); 28 | context.stroke(); 29 | }, false); 30 | } 31 | } 32 | 33 | void main() { 34 | new curvethroughpoint().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch04/curvethroughpoint/curvethroughpoint.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Curve Through Point 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/drawingapp/drawingapp.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class drawingapp { 5 | 6 | drawingapp() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | 14 | onMouseMove(MouseEvent e) { 15 | context.lineTo(mouse.x, mouse.y); 16 | context.stroke(); 17 | }; 18 | 19 | canvas.on.mouseDown.add((MouseEvent e) { 20 | context.beginPath(); 21 | context.moveTo(mouse.x, mouse.y); 22 | canvas.on.mouseMove.add(onMouseMove, false); 23 | }, false); 24 | 25 | canvas.on.mouseUp.add(onMouseMove, false); 26 | } 27 | 28 | } 29 | 30 | void main() { 31 | new drawingapp().run(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/ch04/drawingapp/drawingapp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Drawing App 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/drawingcurves/drawingcurves.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class drawingcurves { 5 | 6 | drawingcurves() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | var x0 = 100, 14 | y0 = 200, 15 | x2 = 300, 16 | y2 = 200; 17 | 18 | canvas.on.mouseMove.add((MouseEvent e) { 19 | context.clearRect(0, 0, canvas.width, canvas.height); 20 | 21 | var x1 = mouse.x, 22 | y1 = mouse.y; 23 | 24 | //curve toward mouse 25 | context.beginPath(); 26 | context.moveTo(x0, y0); 27 | context.quadraticCurveTo(x1, y1, x2, y2); 28 | context.stroke(); 29 | }, false); 30 | } 31 | } 32 | 33 | void main() { 34 | new drawingcurves().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch04/drawingcurves/drawingcurves.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Drawing Curves 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/embedimage/embedimage.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class embedimage { 4 | 5 | embedimage() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var image = document.query('#picture'); 12 | context.drawImage(image, 0, 0); 13 | } 14 | } 15 | 16 | void main() { 17 | new embedimage().run(); 18 | } 19 | -------------------------------------------------------------------------------- /examples/ch04/embedimage/embedimage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Embed Image 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/ch04/gradientfill1/gradientfill1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #source('../classes/point.dart'); 3 | class gradientfill1 { 4 | 5 | gradientfill1() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | point pt1 = new point(0,0); 12 | point pt2 = new point(100,100); 13 | CanvasGradient gradient = context.createLinearGradient(pt1.x, pt1.y, pt2.x, pt2.y); 14 | 15 | //white to red 16 | gradient.addColorStop(0, "#ffffff"); 17 | gradient.addColorStop(1, "#ff0000"); 18 | 19 | context.fillStyle = gradient; 20 | context.fillRect(0, 0, 100, 100); 21 | } 22 | } 23 | 24 | void main() { 25 | new gradientfill1().run(); 26 | } 27 | -------------------------------------------------------------------------------- /examples/ch04/gradientfill1/gradientfill1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gradient Fill 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch04/gradientfill2/gradientfill2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #source('../classes/point.dart'); 3 | class gradientfill2 { 4 | 5 | gradientfill2() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | point pt1 = new point(100,100); //gradient start point 12 | point pt2 = new point(200,200); //gradient end point 13 | CanvasGradient gradient = context.createLinearGradient(pt1.x, pt1.y, pt2.x, pt2.y); 14 | 15 | //white to blue to red 16 | gradient.addColorStop(0, "#ffffff"); 17 | gradient.addColorStop(0.5, "#0000ff"); 18 | gradient.addColorStop(1, "#ff0000"); 19 | 20 | context.fillStyle = gradient; 21 | context.fillRect(100, 100, 100, 100); 22 | } 23 | } 24 | 25 | void main() { 26 | new gradientfill2().run(); 27 | } 28 | -------------------------------------------------------------------------------- /examples/ch04/gradientfill2/gradientfill2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gradient Fill 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch04/gradientfillradial/gradientfillradial.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #source('../classes/point.dart'); 3 | class gradientfillradial { 4 | 5 | gradientfillradial() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var c1 = new point.withRadius(150, 150, 0); //gradient start circle 12 | var c2 = new point.withRadius(150,150,50); //gradient end circle 13 | var gradient = context.createRadialGradient(c1.x, c1.y, c1.radius, c2.x, c2.y, c2.radius); 14 | //all black alpha blend 15 | gradient.addColorStop(0, "#000000"); 16 | gradient.addColorStop(1, "rgba(0, 0, 0, 0)"); //alpha required 17 | 18 | context.fillStyle = gradient; 19 | context.fillRect(100, 100, 100, 100); 20 | } 21 | } 22 | 23 | void main() { 24 | new gradientfillradial().run(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/ch04/gradientfillradial/gradientfillradial.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gradient Fill Radial 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch04/grayscale/grayscale.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class grayscale { 4 | 5 | grayscale() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | 12 | //draw some stripes: red, green, and blue 13 | for (var i = 0; i < canvas.width; i += 10) { 14 | for (var j = 0; j < canvas.height; j += 10) { 15 | context.fillStyle = (i % 20 === 0) ? "#f00" : ((i % 30 === 0) ? "#0f0" : "#00f"); 16 | context.fillRect(i, j, 10, 10); 17 | } 18 | } 19 | 20 | var imagedata = context.getImageData(0, 0, canvas.width, canvas.height), 21 | pixels = imagedata.data; 22 | 23 | //pixel iteration 24 | for (var offset = 0, len = pixels.length; offset < len; offset += 4) { 25 | var r = pixels[offset], 26 | g = pixels[offset + 1], 27 | b = pixels[offset + 2], 28 | y = (0.2126 * r) + (0.7152 * g) + (0.0722 * b); //relative luminance, humans perceive green more 29 | 30 | pixels[offset] = pixels[offset + 1] = pixels[offset + 2] = y; 31 | } 32 | 33 | context.putImageData(imagedata, 0, 0); 34 | } 35 | } 36 | 37 | void main() { 38 | new grayscale().run(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/ch04/grayscale/grayscale.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Grayscale 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/invertcolor/invertcolor.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class invertcolor { 4 | 5 | invertcolor() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | 12 | //draw some stripes: red, green, and blue 13 | for (var i = 0; i < canvas.width; i += 10) { 14 | for (var j = 0; j < canvas.height; j += 10) { 15 | context.fillStyle = (i % 20 === 0) ? "#f00" : ((i % 30 === 0) ? "#0f0" : "#00f"); 16 | context.fillRect(i, j, 10, 10); 17 | } 18 | } 19 | 20 | var imagedata = context.getImageData(0, 0, canvas.width, canvas.height), 21 | pixels = imagedata.data; 22 | 23 | //pixel iteration 24 | for (var offset = 0, len = pixels.length; offset < len; offset += 4) { 25 | //invert each color component of the pixel: r,g,b,a (0-255) 26 | pixels[offset] = 255 - pixels[offset]; //red to cyan 27 | pixels[offset + 1] = 255 - pixels[offset + 1]; //green to magenta 28 | pixels[offset + 2] = 255 - pixels[offset + 2]; //blue to yellow 29 | //pixels[offset + 4] is alpha (the fourth component) 30 | } 31 | 32 | context.putImageData(imagedata, 0, 0); 33 | } 34 | 35 | 36 | } 37 | 38 | void main() { 39 | new invertcolor().run(); 40 | } 41 | -------------------------------------------------------------------------------- /examples/ch04/invertcolor/invertcolor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Invert Color 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch04/loadimage/loadimage.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class loadimage { 4 | 5 | loadimage() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | ImageElement image = new Element.tag("img"); 12 | image.src = '../assets/picture.jpg'; 13 | image.on.load.add((Event e) { 14 | context.drawImage(image, 0, 0); 15 | }, false); 16 | } 17 | } 18 | 19 | void main() { 20 | new loadimage().run(); 21 | } 22 | -------------------------------------------------------------------------------- /examples/ch04/loadimage/loadimage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Load Image 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch04/multicurve1/multicurve1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #source('point.dart'); 3 | 4 | class multicurve1 { 5 | 6 | multicurve1() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | List points = new List(); 13 | var numPoints = 9; 14 | 15 | for (var i = 0; i < numPoints; i++) { 16 | point p = new point( 17 | Math.random() * canvas.width, 18 | Math.random() * canvas.height); 19 | points.add(p); 20 | } 21 | 22 | //move to the first point 23 | context.beginPath(); 24 | context.moveTo(points[0].x, points[1].y); 25 | //and loop through each successive pair 26 | for (var i = 1; i < numPoints; i += 2) { 27 | context.quadraticCurveTo(points[i].x, points[i].y, 28 | points[i+1].x, points[i+1].y); 29 | } 30 | context.stroke(); 31 | } 32 | 33 | 34 | } 35 | 36 | void main() { 37 | new multicurve1().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch04/multicurve1/multicurve1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Curve 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/multicurve1/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | point(this.x, this.y); 5 | } 6 | -------------------------------------------------------------------------------- /examples/ch04/multicurve2/multicurve2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #source('point.dart'); 3 | 4 | class multicurve2 { 5 | 6 | multicurve2() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | List points = new List(); 13 | var numPoints = 9; 14 | point ctrlPoint = new point(0,0); 15 | 16 | for (var i = 0; i < numPoints; i++) { 17 | point p = new point( 18 | Math.random() * canvas.width, 19 | Math.random() * canvas.height); 20 | points.add(p); 21 | } 22 | 23 | //move to the first point 24 | context.beginPath(); 25 | context.moveTo(points[0].x, points[1].y); 26 | //curve through the rest, stopping at each midpoint 27 | var i=1; 28 | for (; i < numPoints - 2; i++) { 29 | ctrlPoint.x = (points[i].x + points[i+1].x) / 2; 30 | ctrlPoint.y = (points[i].y + points[i+1].y) / 2; 31 | context.quadraticCurveTo(points[i].x, points[i].y, 32 | ctrlPoint.x, ctrlPoint.y); 33 | } 34 | //curve through the last two points 35 | context.quadraticCurveTo(points[i].x, points[i].y, 36 | points[i+1].x, points[i+1].y); 37 | context.stroke(); 38 | } 39 | 40 | 41 | } 42 | 43 | void main() { 44 | new multicurve2().run(); 45 | } 46 | -------------------------------------------------------------------------------- /examples/ch04/multicurve2/multicurve2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Curve 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/multicurve2/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | point(this.x, this.y); 5 | } 6 | -------------------------------------------------------------------------------- /examples/ch04/multicurve3/multicurve3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Curve 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/multicurve3/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | point(this.x, this.y); 5 | } 6 | -------------------------------------------------------------------------------- /examples/ch04/pixelmove/pixelmove.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pixel Move 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/spraypaint/spraypaint.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spray Paint 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch04/videoframes/videoframes.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class videoframes { 4 | 5 | videoframes() { 6 | } 7 | 8 | void run() { 9 | // NOTE: Sample does not fully work, file bug with dart team 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | VideoElement video = document.query('#movieclip'); 13 | 14 | drawFrame(int t) { 15 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 16 | context.drawImage(video, 0, 0); 17 | }; 18 | 19 | drawFrame(0); 20 | } 21 | } 22 | 23 | void main() { 24 | new videoframes().run(); 25 | } 26 | -------------------------------------------------------------------------------- /examples/ch04/videoframes/videoframes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Video Frames 6 | 7 | 8 | 13 | 14 | 15 | 16 |
17 | Example from Foundation HTML5 Animation with JavaScript 18 |
19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/ch05/acceleration1/acceleration1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | class acceleration1 { 5 | 6 | acceleration1() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var ball = new Ball(); 13 | var vx = 0; 14 | var ax = 0.1; 15 | 16 | ball.x = 50; 17 | ball.y = 100; 18 | 19 | drawFrame(int t) { 20 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 21 | context.clearRect(0, 0, canvas.width, canvas.height); 22 | 23 | vx += ax; 24 | ball.x += vx; 25 | ball.draw(context); 26 | }; 27 | 28 | drawFrame(0); 29 | } 30 | } 31 | 32 | void main() { 33 | new acceleration1().run(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/ch05/acceleration1/acceleration1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Acceleration 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch05/acceleration2/acceleration2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class acceleration2 { 6 | 7 | acceleration2() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var vx = 0; 15 | var ax = 0; 16 | 17 | ball.x = canvas.width / 2; 18 | ball.y = canvas.height / 2; 19 | 20 | window.on.keyDown.add((KeyboardEvent event) { 21 | if (event.keyCode === 37) { //left 22 | ax = -0.1; 23 | } else if (event.keyCode === 39) { //right 24 | ax = 0.1; 25 | } 26 | }, false); 27 | 28 | window.on.keyUp.add((KeyboardEvent event) { 29 | ax = 0; 30 | }, false); 31 | 32 | drawFrame(int t) { 33 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 34 | context.clearRect(0, 0, canvas.width, canvas.height); 35 | 36 | vx += ax; 37 | ball.x += vx; 38 | ball.draw(context); 39 | }; 40 | 41 | drawFrame(0); 42 | } 43 | } 44 | 45 | void main() { 46 | new acceleration2().run(); 47 | } 48 | -------------------------------------------------------------------------------- /examples/ch05/acceleration2/acceleration2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Acceleration 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch05/acceleration3/acceleration3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Acceleration 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch05/classes/arrow.dart: -------------------------------------------------------------------------------- 1 | class Arrow { 2 | int x; 3 | int y; 4 | String color; 5 | double rotation; 6 | 7 | Arrow() { 8 | x=0; 9 | y=0; 10 | color="#ffff00"; 11 | rotation=0.0; 12 | } 13 | 14 | void draw(var context) { 15 | 16 | context.save(); 17 | context.translate(x, y); 18 | context.rotate(rotation); 19 | 20 | context.lineWidth = 2; 21 | context.fillStyle = color; 22 | context.beginPath(); 23 | context.moveTo(-50, -25); 24 | context.lineTo(0, -25); 25 | context.lineTo(0, -50); 26 | context.lineTo(50, 0); 27 | context.lineTo(0, 50); 28 | context.lineTo(0, 25); 29 | context.lineTo(-50, 25); 30 | context.lineTo(-50, -25); 31 | context.closePath(); 32 | context.fill(); 33 | context.stroke(); 34 | 35 | context.restore(); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch05/classes/ball.dart: -------------------------------------------------------------------------------- 1 | class Ball { 2 | num x; 3 | num y; 4 | num radius; 5 | num rotation; 6 | num scaleX; 7 | num scaleY; 8 | String color; 9 | num lineWidth; 10 | 11 | Ball() { 12 | this.radius=40; 13 | this.color='#ff0000'; 14 | this.x=0; 15 | this.y=0; 16 | this.rotation=0.0; 17 | this.scaleX=1; 18 | this.scaleY=1; 19 | this.lineWidth=1; 20 | } 21 | 22 | void draw(var context) { 23 | // CanvasRenderingContext2D 24 | context.save(); 25 | context.translate(x, y); 26 | context.rotate(rotation); 27 | context.scale(scaleX,scaleY); 28 | 29 | context.lineWidth = lineWidth; 30 | context.fillStyle = color; 31 | context.beginPath(); 32 | //x, y, radius, start_angle, end_angle, anti-clockwise 33 | context.arc(0, 0, radius, 0, (Math.PI * 2), true); 34 | context.closePath(); 35 | context.fill(); 36 | if (lineWidth > 0) { 37 | context.stroke(); 38 | } 39 | context.restore(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch05/classes/ship.dart: -------------------------------------------------------------------------------- 1 | class Ship { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | num rotation; 7 | bool showFlame; 8 | 9 | Ship() { 10 | this.x = 0; 11 | this.y = 0; 12 | this.width = 25; 13 | this.height = 20; 14 | this.rotation = 0; 15 | this.showFlame = false; 16 | } 17 | 18 | void draw(var context) { 19 | context.save(); 20 | context.translate(this.x, this.y); 21 | context.rotate(this.rotation); 22 | 23 | context.lineWidth = 1; 24 | context.strokeStyle = "#ffffff"; 25 | context.beginPath(); 26 | context.moveTo(10, 0); 27 | context.lineTo(-10, 10); 28 | context.lineTo(-5, 0); 29 | context.lineTo(-10, -10); 30 | context.lineTo(10, 0); 31 | context.stroke(); 32 | 33 | if (this.showFlame) { 34 | context.beginPath(); 35 | context.moveTo(-7.5, -5); 36 | context.lineTo(-15, 0); 37 | context.lineTo(-7.5, 5); 38 | context.stroke(); 39 | } 40 | context.restore(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/ch05/followmouse1/followmouse1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/arrow.dart'); 4 | 5 | class followmouse1 { 6 | 7 | followmouse1() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var mouse = utilslib.Utils.captureMouse(canvas); 14 | var arrow = new Arrow(); 15 | var speed = 3; 16 | 17 | drawFrame(int t) { 18 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 19 | context.clearRect(0, 0, canvas.width, canvas.height); 20 | 21 | var dx = mouse.x - arrow.x, 22 | dy = mouse.y - arrow.y, 23 | angle = Math.atan2(dy, dx), 24 | vx = Math.cos(angle) * speed, 25 | vy = Math.sin(angle) * speed; 26 | 27 | arrow.rotation = angle; //radians 28 | arrow.x += vx; 29 | arrow.y += vy; 30 | arrow.draw(context); 31 | }; 32 | 33 | drawFrame(0); 34 | } 35 | 36 | 37 | } 38 | 39 | void main() { 40 | new followmouse1().run(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch05/followmouse1/followmouse1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Follow Mouse 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch05/followmouse2/followmouse2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/arrow.dart'); 4 | class followmouse2 { 5 | 6 | followmouse2() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | var arrow = new Arrow(); 14 | var vx = 0; 15 | var vy = 0; 16 | var force = 0.05; 17 | 18 | drawFrame(int t) { 19 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 20 | context.clearRect(0, 0, canvas.width, canvas.height); 21 | 22 | var dx = mouse.x - arrow.x, 23 | dy = mouse.y - arrow.y, 24 | angle = Math.atan2(dy, dx), 25 | ax = Math.cos(angle) * force, 26 | ay = Math.sin(angle) * force; 27 | 28 | arrow.rotation = angle; 29 | vx += ax; 30 | vy += ay; 31 | arrow.x += vx; 32 | arrow.y += vy; 33 | arrow.draw(context); 34 | }; 35 | 36 | drawFrame(0); 37 | } 38 | } 39 | 40 | void main() { 41 | new followmouse2().run(); 42 | } 43 | -------------------------------------------------------------------------------- /examples/ch05/followmouse2/followmouse2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Follow Mouse 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch05/gravity/gravity.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gravity 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch05/rotationalvelocity/rotationalvelocity.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/arrow.dart'); 4 | 5 | class rotationalvelocity { 6 | 7 | rotationalvelocity() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var mouse = utilslib.Utils.captureMouse(canvas); 14 | var arrow = new Arrow(); 15 | var vr = 2; //degrees 16 | 17 | arrow.x = canvas.width / 2; 18 | arrow.y = canvas.height / 2; 19 | 20 | drawFrame(int t) { 21 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 22 | context.clearRect(0, 0, canvas.width, canvas.height); 23 | 24 | arrow.rotation += vr * Math.PI / 180; //to radians 25 | arrow.draw(context); 26 | }; 27 | 28 | drawFrame(0); 29 | } 30 | 31 | 32 | } 33 | 34 | void main() { 35 | new rotationalvelocity().run(); 36 | } 37 | -------------------------------------------------------------------------------- /examples/ch05/rotationalvelocity/rotationalvelocity.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotational Velocity 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch05/shipsim/shipsim.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ship Sim 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/ch05/velocity1/velocity1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class velocity1 { 6 | 7 | velocity1() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var vx = 1; 15 | 16 | ball.x = 50; 17 | ball.y = 100; 18 | 19 | drawFrame(int t) { 20 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 21 | context.clearRect(0, 0, canvas.width, canvas.height); 22 | 23 | 24 | ball.x += vx; 25 | ball.draw(context); 26 | }; 27 | 28 | drawFrame(0); 29 | } 30 | } 31 | 32 | void main() { 33 | new velocity1().run(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/ch05/velocity1/velocity1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Velocity 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch05/velocity2/velocity2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class velocity2 { 6 | 7 | velocity2() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var vx = 1; 15 | var vy = 1; 16 | 17 | ball.x = 50; 18 | ball.y = 100; 19 | 20 | drawFrame(int t) { 21 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 22 | context.clearRect(0, 0, canvas.width, canvas.height); 23 | 24 | ball.x += vx; 25 | ball.y += vy; 26 | ball.draw(context); 27 | }; 28 | 29 | drawFrame(0); 30 | } 31 | } 32 | 33 | void main() { 34 | new velocity2().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch05/velocity2/velocity2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Velocity 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch05/velocityangle/velocityangle.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class velocityangle { 6 | 7 | velocityangle() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var angle = 45; 15 | var speed = 1; 16 | 17 | ball.x = 50; 18 | ball.y = 100; 19 | 20 | drawFrame(int t) { 21 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 22 | context.clearRect(0, 0, canvas.width, canvas.height); 23 | 24 | var radians = angle * Math.PI / 180, 25 | vx = Math.cos(radians) * speed, 26 | vy = Math.sin(radians) * speed; 27 | 28 | ball.x += vx; 29 | ball.y += vy; 30 | ball.draw(context); 31 | }; 32 | 33 | drawFrame(0); 34 | } 35 | } 36 | 37 | void main() { 38 | new velocityangle().run(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/ch05/velocityangle/velocityangle.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Velocity Angle 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/bouncing1/bouncing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bouncing 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/bouncing2/bouncing2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bouncing 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/classes/ship.dart: -------------------------------------------------------------------------------- 1 | class Ship { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | num rotation; 7 | bool showFlame; 8 | 9 | Ship() { 10 | this.x = 0; 11 | this.y = 0; 12 | this.width = 25; 13 | this.height = 20; 14 | this.rotation = 0; 15 | this.showFlame = false; 16 | } 17 | 18 | void draw(var context) { 19 | context.save(); 20 | context.translate(this.x, this.y); 21 | context.rotate(this.rotation); 22 | 23 | context.lineWidth = 1; 24 | context.strokeStyle = "#ffffff"; 25 | context.beginPath(); 26 | context.moveTo(10, 0); 27 | context.lineTo(-10, 10); 28 | context.lineTo(-5, 0); 29 | context.lineTo(-10, -10); 30 | context.lineTo(10, 0); 31 | context.stroke(); 32 | 33 | if (this.showFlame) { 34 | context.beginPath(); 35 | context.moveTo(-7.5, -5); 36 | context.lineTo(-15, 0); 37 | context.lineTo(-7.5, 5); 38 | context.stroke(); 39 | } 40 | context.restore(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/ch06/fountain/fountain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Fountain 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/friction1/friction1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class friction1 { 6 | 7 | friction1() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var vx = Math.random() * 10 - 5, 15 | vy = Math.random() * 10 - 5, 16 | friction = 0.1; 17 | 18 | ball.x = canvas.width / 2; 19 | ball.y = canvas.height / 2; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | var speed = Math.sqrt(vx * vx + vy * vy), 26 | angle = Math.atan2(vy, vx); 27 | 28 | if (speed > friction) { 29 | speed -= friction; 30 | } else { 31 | speed = 0; 32 | } 33 | vx = Math.cos(angle) * speed; 34 | vy = Math.sin(angle) * speed; 35 | ball.x += vx; 36 | ball.y += vy; 37 | ball.draw(context); 38 | }; 39 | drawFrame(0); 40 | } 41 | 42 | 43 | } 44 | 45 | void main() { 46 | new friction1().run(); 47 | } 48 | -------------------------------------------------------------------------------- /examples/ch06/friction1/friction1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Friction 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/friction2/friction2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | 5 | class friction2 { 6 | 7 | friction2() { 8 | } 9 | 10 | void run() { 11 | CanvasElement canvas = document.query('#canvas'); 12 | var context = canvas.getContext('2d'); 13 | var ball = new Ball(); 14 | var vx = Math.random() * 10 - 5, 15 | vy = Math.random() * 10 - 5, 16 | friction = 0.95; 17 | 18 | ball.x = canvas.width / 2; 19 | ball.y = canvas.height / 2; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | vx *= friction; 26 | vy *= friction; 27 | ball.x += vx; 28 | ball.y += vy; 29 | ball.draw(context); 30 | }; 31 | 32 | drawFrame(0); 33 | } 34 | } 35 | 36 | void main() { 37 | new friction2().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch06/friction2/friction2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Friction 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch06/removal/removal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Removal 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch06/shipsim/shipsim.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ship Sim 2 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/ch06/shipsimfriction/shipsimfriction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ship Sim Friction 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/ch07/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class Bound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | Bound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch07/dragandmove1/dragandmove1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Drag and Move 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch07/dragandmove2/dragandmove2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Drag and Move 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch07/mouseevents/mouseevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse Events 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch07/mousemovedrag/mousemovedrag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Mouse Move Drag 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch07/throwing/throwing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Throwing 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch07/touchevents/touchevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Touch Events 6 | 7 | 8 | 9 | 10 |
11 | Example from Foundation HTML5 Animation with JavaScript 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/ch08/chain/chain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Chain 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/chainarray/chainarray.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Chain Array 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class Bound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | Bound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch08/doublespring/doublespring.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Double Spring 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/easetomove/easetomove.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class easetomove { 7 | 8 | easetomove() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var ball = new Ball(); 16 | var easing = 0.05; 17 | 18 | drawFrame(int t) { 19 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 20 | context.clearRect(0, 0, canvas.width, canvas.height); 21 | 22 | var vx = (mouse.x - ball.x) * easing, 23 | vy = (mouse.y - ball.y) * easing; 24 | 25 | ball.x += vx; 26 | ball.y += vy; 27 | ball.draw(context); 28 | }; 29 | drawFrame(0); 30 | } 31 | } 32 | 33 | void main() { 34 | new easetomove().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch08/easetomove/easetomove.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Ease to Mouse 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/easing1/easing1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class easing1 { 7 | 8 | easing1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var easing = 0.05, 16 | targetX = canvas.width / 2, 17 | targetY = canvas.height / 2; 18 | 19 | drawFrame(int t) { 20 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 21 | context.clearRect(0, 0, canvas.width, canvas.height); 22 | 23 | var vx = (targetX - ball.x) * easing, 24 | vy = (targetY - ball.y) * easing; 25 | 26 | ball.x += vx; 27 | ball.y += vy; 28 | ball.draw(context); 29 | } 30 | drawFrame(0); 31 | } 32 | } 33 | 34 | void main() { 35 | new easing1().run(); 36 | } 37 | -------------------------------------------------------------------------------- /examples/ch08/easing1/easing1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Easing 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch08/easing2/easing2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Easing 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/easingoff/easingoff.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class easingoff { 7 | 8 | easingoff() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var log = document.query('#log'); 15 | var ball = new Ball(), 16 | easing = 0.05, 17 | targetX = canvas.width / 2; 18 | 19 | 20 | ball.y = canvas.height / 2; 21 | 22 | drawFrame(int t) { 23 | var animRequest = document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0, 0, canvas.width, canvas.height); 25 | 26 | var dx = targetX - ball.x; 27 | 28 | if (dx.abs() < 1) { 29 | ball.x = targetX; 30 | document.window.webkitCancelRequestAnimationFrame(animRequest); 31 | log.value = "Animation done!"; 32 | } else { 33 | var vx = dx * easing; 34 | ball.x += vx; 35 | } 36 | ball.draw(context); 37 | }; 38 | 39 | drawFrame(0); 40 | } 41 | } 42 | 43 | void main() { 44 | new easingoff().run(); 45 | } 46 | -------------------------------------------------------------------------------- /examples/ch08/easingoff/easingoff.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Easing Off 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch08/multispring/multispring.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Spring 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/offsetspring/offsetspring.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Offset Spring 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/spring1/spring1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class spring1 { 7 | 8 | spring1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var spring = 0.03, 16 | targetX = canvas.width / 2, 17 | vx = 0; 18 | 19 | ball.y = canvas.height / 2; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | var dx = targetX - ball.x, 26 | ax = dx * spring; 27 | 28 | vx += ax; 29 | ball.x += vx; 30 | ball.draw(context); 31 | }; 32 | drawFrame(0); 33 | } 34 | } 35 | 36 | void main() { 37 | new spring1().run(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/ch08/spring1/spring1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch08/spring2/spring2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class spring2 { 7 | 8 | spring2() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var spring = 0.03, 16 | friction = 0.95, 17 | targetX = canvas.width / 2, 18 | vx = 0; 19 | 20 | ball.y = canvas.height / 2; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0, 0, canvas.width, canvas.height); 25 | 26 | var dx = targetX - ball.x, 27 | ax = dx * spring; 28 | 29 | vx += ax; 30 | vx *= friction; 31 | ball.x += vx; 32 | ball.draw(context); 33 | }; 34 | drawFrame(0); 35 | } 36 | } 37 | 38 | void main() { 39 | new spring2().run(); 40 | } 41 | -------------------------------------------------------------------------------- /examples/ch08/spring2/spring2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch08/spring3/spring3.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class spring3 { 7 | 8 | spring3() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var spring = 0.03, 16 | friction = 0.95, 17 | targetX = canvas.width / 2, 18 | targetY = canvas.height / 2, 19 | vx = 0, 20 | vy = 0; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0, 0, canvas.width, canvas.height); 25 | 26 | var dx = targetX - ball.x, 27 | dy = targetY - ball.y, 28 | ax = dx * spring, 29 | ay = dy * spring; 30 | 31 | vx += ax; 32 | vy += ay; 33 | vx *= friction; 34 | vy *= friction; 35 | ball.x += vx; 36 | ball.y += vy; 37 | ball.draw(context); 38 | }; 39 | drawFrame(0); 40 | } 41 | } 42 | 43 | void main() { 44 | new spring3().run(); 45 | } 46 | -------------------------------------------------------------------------------- /examples/ch08/spring3/spring3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch08/spring4/spring4.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class spring4 { 7 | 8 | spring4() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var ball = new Ball(); 16 | var spring = 0.03, 17 | friction = 0.95, 18 | vx = 0, 19 | vy = 0; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | var dx = mouse.x - ball.x, 26 | dy = mouse.y - ball.y, 27 | ax = dx * spring, 28 | ay = dy * spring; 29 | 30 | vx += ax; 31 | vy += ay; 32 | vx *= friction; 33 | vy *= friction; 34 | ball.x += vx; 35 | ball.y += vy; 36 | ball.draw(context); 37 | }; 38 | drawFrame(0); 39 | } 40 | } 41 | 42 | void main() { 43 | new spring4().run(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/ch08/spring4/spring4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 4 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/spring5/spring5.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class spring5 { 7 | 8 | spring5() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var ball = new Ball(); 16 | var spring = 0.03, 17 | friction = 0.9, 18 | gravity = 2, 19 | vx = 0, 20 | vy = 0; 21 | 22 | drawFrame(int t) { 23 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 24 | context.clearRect(0, 0, canvas.width, canvas.height); 25 | 26 | var dx = mouse.x - ball.x, 27 | dy = mouse.y - ball.y, 28 | ax = dx * spring, 29 | ay = dy * spring; 30 | 31 | vx += ax; 32 | vy += ay; 33 | vy += gravity; 34 | vx *= friction; 35 | vy *= friction; 36 | ball.x += vx; 37 | ball.y += vy; 38 | context.beginPath(); 39 | context.moveTo(ball.x, ball.y); 40 | context.lineTo(mouse.x, mouse.y); 41 | context.stroke(); 42 | ball.draw(context); 43 | }; 44 | drawFrame(0); 45 | } 46 | } 47 | 48 | void main() { 49 | new spring5().run(); 50 | } 51 | -------------------------------------------------------------------------------- /examples/ch08/spring5/spring5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 5 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch08/triplespring/triplespring.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Triple Spring 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch09/boxes/boxes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Boxes 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch09/bubbles1/bubbles1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bubbles 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch09/bubbles2/bubbles2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bubbles 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch09/bubbles3/bubbles3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bubbles 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch09/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch09/distance1/distance1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class distance1 { 7 | 8 | distance1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var log = document.query('#log'); 16 | var ballA = new Ball.withRadius(30); 17 | var ballB = new Ball.withRadius(30); 18 | 19 | ballA.x = canvas.width / 2; 20 | ballA.y = canvas.height / 2; 21 | 22 | drawFrame(MouseEvent event) { 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | ballB.x = mouse.x; 26 | ballB.y = mouse.y; 27 | 28 | var dx = ballB.x - ballA.x, 29 | dy = ballB.y - ballA.y, 30 | dist = Math.sqrt(dx * dx + dy * dy); 31 | 32 | if (dist < 60) { 33 | log.value = "Hit!"; 34 | } else { 35 | log.value = ''; 36 | } 37 | ballA.draw(context); 38 | ballB.draw(context); 39 | }; 40 | 41 | canvas.on.mouseMove.add(drawFrame, false); 42 | drawFrame(null); 43 | } 44 | } 45 | 46 | void main() { 47 | new distance1().run(); 48 | } 49 | -------------------------------------------------------------------------------- /examples/ch09/distance1/distance1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Distance 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch09/distance2/distance2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Distance 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch09/objecthittest/objecthittest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Object Hit Test 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch09/pointhittest/pointhittest.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class pointhittest { 7 | 8 | pointhittest() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var log = document.query('#log'); 16 | var ball = new Ball(); 17 | 18 | ball.x = canvas.width / 2; 19 | ball.y = canvas.height / 2; 20 | ball.draw(context); 21 | 22 | canvas.on.mouseMove.add((MouseEvent event) { 23 | if (utilslib.Utils.containsPoint(ball.getBounds(), mouse.x, mouse.y)) { 24 | log.value = "Hit!"; 25 | } else { 26 | log.value = ''; 27 | } 28 | }, false); 29 | } 30 | } 31 | 32 | void main() { 33 | new pointhittest().run(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/ch09/pointhittest/pointhittest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Point Hit Test 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch10/anglebounce/anglebounce.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch10/anglebouncebounds/anglebouncebounds.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce Bounds 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch10/anglebouncefinal/anglebouncefinal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce Final 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch10/anglebouncehittest/anglebouncehittest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce Hit Test 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch10/anglebounceopt/anglebounceopt.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce Optimized 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch10/anglebouncerotate/anglebouncerotate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Angle Bounce Rotate 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch10/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch10/multianglebounce/multianglebounce.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Angle Bounce 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch10/rotate1/rotate1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class rotate1 { 7 | 8 | rotate1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var vr = 0.05, 16 | angle = 0, 17 | radius = 150, 18 | centerX = canvas.width / 2, 19 | centerY = canvas.height / 2; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | ball.x = centerX + Math.cos(angle) * radius; 26 | ball.y = centerY + Math.sin(angle) * radius; 27 | angle += vr; 28 | 29 | ball.draw(context); 30 | }; 31 | drawFrame(0); 32 | } 33 | } 34 | 35 | void main() { 36 | new rotate1().run(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/ch10/rotate1/rotate1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch10/rotate2/rotate2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class rotate2 { 7 | 8 | rotate2() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(); 15 | var vr = 0.05, 16 | cos = Math.cos(vr), 17 | sin = Math.sin(vr), 18 | centerX = canvas.width / 2, 19 | centerY = canvas.height / 2; 20 | 21 | ball.x = Math.random() * canvas.width; 22 | ball.y = Math.random() * canvas.height; 23 | 24 | drawFrame(int t) { 25 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 26 | context.clearRect(0, 0, canvas.width, canvas.height); 27 | 28 | var x1 = ball.x - centerX, 29 | y1 = ball.y - centerY, 30 | x2 = cos * x1 - sin * y1, 31 | y2 = cos * y1 + sin * x1; 32 | 33 | ball.x = centerX + x2; 34 | ball.y = centerY + y2; 35 | 36 | ball.draw(context); 37 | }; 38 | drawFrame(0); 39 | } 40 | } 41 | 42 | void main() { 43 | new rotate2().run(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/ch10/rotate2/rotate2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch10/rotate3/rotate3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch11/billiard1/billiard1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Billiard 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch11/billiard2/billiard2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Billiard 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch11/billiard3/billiard3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Billiard 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch11/billiard4/billiard4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Billiard 4 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch11/billiard4/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } 7 | -------------------------------------------------------------------------------- /examples/ch11/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch11/multibilliard1/multibilliard1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Billiard 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch11/multibilliard1/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } 7 | -------------------------------------------------------------------------------- /examples/ch11/multibilliard2/multibilliard2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Billiard 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch11/multibilliard2/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } 7 | -------------------------------------------------------------------------------- /examples/ch12/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch12/classes/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } 7 | -------------------------------------------------------------------------------- /examples/ch12/gravity/gravity.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gravity 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch12/gravitybounce/gravitybounce.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gravity Bounce 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch12/gravityrandom/gravityrandom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Gravity Random 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch12/nodegarden/nodegarden.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Node Garden 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/ch12/nodegardenlines/nodegardenlines.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Node Garden Lines 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/ch12/nodegardenmass/nodegardenmass.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Node Garden Mass 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/ch12/orbit/orbit.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Orbit 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch12/orbitdraw/orbitdraw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Orbit Draw 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch13/classes/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } -------------------------------------------------------------------------------- /examples/ch13/realwalk/realwalk.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Real Walk 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch13/segment/segment.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/slider.dart'); 5 | #source('../classes/point.dart'); 6 | #source('../classes/bound.dart'); 7 | 8 | class segment { 9 | 10 | segment() { 11 | } 12 | 13 | void run() { 14 | CanvasElement canvas = document.query('#canvas'); 15 | var context = canvas.getContext('2d'); 16 | var segment0 = new Segment(100, 20), 17 | segment1 = new Segment(200, 10), 18 | segment2 = new Segment(80, 40); 19 | 20 | 21 | segment0.x = 100; 22 | segment0.y = 50; 23 | segment0.draw(context); 24 | 25 | segment1.x = 100; 26 | segment1.y = 80; 27 | segment1.draw(context); 28 | 29 | segment2.x = 100; 30 | segment2.y = 120; 31 | segment2.draw(context); 32 | } 33 | } 34 | 35 | void main() { 36 | new segment().run(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/ch13/segment/segment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Segment 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/singlesegment/singlesegment.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/slider.dart'); 5 | #source('../classes/point.dart'); 6 | #source('../classes/bound.dart'); 7 | 8 | class singlesegment { 9 | 10 | singlesegment() { 11 | } 12 | 13 | void run() { 14 | CanvasElement canvas = document.query('#canvas'); 15 | var context = canvas.getContext('2d'); 16 | var segment = new Segment(100, 20); 17 | var slider = new Slider(-90, 90, 0); 18 | 19 | segment.x = 100; 20 | segment.y = 100; 21 | 22 | slider.x = 300; 23 | slider.y = 20; 24 | slider.captureMouse(canvas); 25 | 26 | drawFrame () { 27 | context.clearRect(0, 0, canvas.width, canvas.height); 28 | 29 | segment.rotation = slider.value * Math.PI / 180; 30 | segment.draw(context); 31 | slider.draw(context); 32 | } 33 | 34 | slider.onchange = drawFrame; 35 | drawFrame(); 36 | } 37 | } 38 | 39 | void main() { 40 | new singlesegment().run(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/ch13/singlesegment/singlesegment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Single Segment 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch13/twosegments1/twosegments1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Two Segments 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch13/twosegments2/twosegments2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Two Segments 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch13/walking1/walking1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/point.dart'); 5 | #source('../classes/bound.dart'); 6 | 7 | class walking1 { 8 | 9 | walking1() { 10 | } 11 | 12 | void run() { 13 | CanvasElement canvas = document.query('#canvas'); 14 | var context = canvas.getContext('2d'); 15 | var segment0 = new Segment(100, 20), 16 | segment1 = new Segment(100, 20), 17 | cycle = 0; 18 | 19 | segment0.x = 200; 20 | segment0.y = 200; 21 | 22 | segment1.x = segment0.getPin().x; 23 | segment1.y = segment0.getPin().y; 24 | 25 | drawFrame(int t) { 26 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 27 | context.clearRect(0, 0, canvas.width, canvas.height); 28 | 29 | cycle += 0.02; 30 | var angle = (Math.sin(cycle) * 90) * Math.PI / 180; 31 | segment0.rotation = angle; 32 | segment1.rotation = segment0.rotation + angle; 33 | segment1.x = segment0.getPin().x; 34 | segment1.y = segment0.getPin().y; 35 | segment0.draw(context); 36 | segment1.draw(context); 37 | 38 | }; 39 | 40 | drawFrame(0); 41 | } 42 | } 43 | 44 | void main() { 45 | new walking1().run(); 46 | } 47 | -------------------------------------------------------------------------------- /examples/ch13/walking1/walking1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Walking 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/walking2/walking2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Walking 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/walking3/walking3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Walking 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/walking4/walking4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Walking 4 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch13/walking5/walking5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Walking 5 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch14/classes/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } -------------------------------------------------------------------------------- /examples/ch14/cosines1/cosines1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cosines 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/cosines2/cosines2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cosines 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/multisegmentdrag/multisegmentdrag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Segment Drag 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/multisegmentreach/multisegmentreach.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Segment Reach 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/onesegment/onesegment.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/point.dart'); 5 | 6 | 7 | class onesegment { 8 | 9 | onesegment() { 10 | } 11 | 12 | void run() { 13 | CanvasElement canvas = document.query('#canvas'); 14 | var context = canvas.getContext('2d'); 15 | var mouse = utilslib.Utils.captureMouse(canvas); 16 | var segment0 = new Segment(100, 20); 17 | 18 | segment0.x = canvas.width / 2; 19 | segment0.y = canvas.height / 2; 20 | 21 | drawFrame(int t) { 22 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 23 | context.clearRect(0, 0, canvas.width, canvas.height); 24 | 25 | var dx = mouse.x - segment0.x, 26 | dy = mouse.y - segment0.y; 27 | segment0.rotation = Math.atan2(dy, dx); 28 | 29 | segment0.draw(context); 30 | }; 31 | drawFrame(0); 32 | } 33 | } 34 | 35 | void main() { 36 | new onesegment().run(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/ch14/onesegment/onesegment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | One Segment 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/onesegmentdrag/onesegmentdrag.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/point.dart'); 5 | 6 | class onesegmentdrag { 7 | 8 | onesegmentdrag() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var segment0 = new Segment(100, 20); 16 | 17 | drawFrame(int t) { 18 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 19 | context.clearRect(0, 0, canvas.width, canvas.height); 20 | 21 | var dx = mouse.x - segment0.x, 22 | dy = mouse.y - segment0.y; 23 | segment0.rotation = Math.atan2(dy, dx); 24 | var w = segment0.getPin().x - segment0.x, 25 | h = segment0.getPin().y - segment0.y; 26 | segment0.x = mouse.x - w; 27 | segment0.y = mouse.y - h; 28 | 29 | segment0.draw(context); 30 | }; 31 | drawFrame(0); 32 | } 33 | } 34 | 35 | void main() { 36 | new onesegmentdrag().run(); 37 | } 38 | -------------------------------------------------------------------------------- /examples/ch14/onesegmentdrag/onesegmentdrag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | One Segment Drag 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/playball/playball.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Play Ball 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch14/twosegmentdrag/twosegmentdrag.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/segment.dart'); 4 | #source('../classes/point.dart'); 5 | 6 | class twosegmentdrag { 7 | 8 | twosegmentdrag() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var mouse = utilslib.Utils.captureMouse(canvas); 15 | var segment0 = new Segment(100, 20); 16 | var segment1 = new Segment(100, 20); 17 | 18 | drag (segment, xpos, ypos) { 19 | var dx = xpos - segment.x, 20 | dy = ypos - segment.y; 21 | segment.rotation = Math.atan2(dy, dx); 22 | var w = segment.getPin().x - segment.x, 23 | h = segment.getPin().y - segment.y; 24 | segment.x = xpos - w; 25 | segment.y = ypos - h; 26 | } 27 | 28 | drawFrame(int t) { 29 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 30 | context.clearRect(0, 0, canvas.width, canvas.height); 31 | 32 | drag(segment0, mouse.x, mouse.y); 33 | drag(segment1, segment0.x, segment0.y); 34 | 35 | segment0.draw(context); 36 | segment1.draw(context); 37 | }; 38 | drawFrame(0); 39 | } 40 | } 41 | 42 | void main() { 43 | new twosegmentdrag().run(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/ch14/twosegmentdrag/twosegmentdrag.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Two Segment Drag 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch14/twosegmentreach/twosegmentreach.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Two Segment Reach 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch15/bounce3d/bounce3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bounce 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch15/bouncyballs/bouncyballs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bouncy Balls 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/ch15/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch15/collision3d/collision3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Collision 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch15/easing3d/easing3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Easing 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch15/multibounce3d/multibounce3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Multi Bounce 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch15/perspective1/perspective1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Perspective 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch15/perspective2/perspective2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Perspective 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch15/rotatexy/rotatexy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate XY 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch15/rotatey/rotatey.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate Y 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch15/spring3d/spring3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch15/trees/trees.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Trees 1 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/ch15/trees2/trees2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Trees 2 6 | 7 | 12 | 13 | 14 |
15 | Example from Foundation HTML5 Animation with JavaScript 16 |
17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/ch15/velocity3d/velocity3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Velocity 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch15/zsort/zsort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Z-Sort 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch16/classes/triangle.dart: -------------------------------------------------------------------------------- 1 | class Triangle { 2 | Point3d pointA; 3 | Point3d pointB; 4 | Point3d pointC; 5 | String color; 6 | num lineWidth; 7 | num alpha; 8 | Triangle(this.pointA, this.pointB, this.pointC, this.color) { 9 | this.lineWidth = 1; 10 | this.alpha = 0.5; 11 | } 12 | 13 | draw(var context) { 14 | context.save(); 15 | context.lineWidth = this.lineWidth; 16 | context.fillStyle = context.strokeStyle = utilslib.Utils.colorToRGB(this.color, this.alpha); 17 | context.beginPath(); 18 | context.moveTo(this.pointA.getScreenX(), this.pointA.getScreenY()); 19 | context.lineTo(this.pointB.getScreenX(), this.pointB.getScreenY()); 20 | context.lineTo(this.pointC.getScreenX(), this.pointC.getScreenY()); 21 | context.closePath(); 22 | context.fill(); 23 | if (this.lineWidth > 0) { 24 | context.stroke(); 25 | } 26 | context.restore(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ch16/cube/cube.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cube 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/cylinder/cylinder.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cylinder 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/extrudeda/extrudeda.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Extruded A 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/fillede/fillede.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Filled E 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/lines3d1/lines3d1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Lines 3D 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/lines3d2/lines3d2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Lines 3D 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch16/movecube1/movecube1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Move Cube 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch16/movecube2/movecube2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Move Cube 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch16/pyramid/pyramid.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pyramid 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/spinninge/spinninge.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spinning E 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/square3d/square3d.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Square 3D 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch16/triangles1/triangles1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Triangles 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch17/classes/light.dart: -------------------------------------------------------------------------------- 1 | class Light { 2 | num x; 3 | num y; 4 | num z; 5 | num brightness; 6 | 7 | Light() { 8 | this.x = -100; 9 | this.y = -100; 10 | this.z = -100; 11 | this.brightness = 1; 12 | } 13 | 14 | Light.withParameters(this.x,this.y,this.z) { 15 | this.brightness = 1; 16 | } 17 | 18 | Light.withBrightness(this.x,this.y,this.z,this.brightness); 19 | 20 | setBrightness(var b) { 21 | this.brightness = Math.min(Math.max(b, 0), 1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/ch17/extrudedacull/extrudedacull.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Extruded A Cull 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch17/extrudedadepth/extrudedadepth.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Extruded A Depth 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/ch17/extrudedalight/extrudedalight.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Extruded A Light 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch18/matrixrotate/matrixrotate.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class matrixrotate { 5 | 6 | matrixrotate() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var angle = 0; 13 | 14 | drawFrame(int t) { 15 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 16 | context.clearRect(0, 0, canvas.width, canvas.height); 17 | 18 | angle += 0.03; 19 | var cos = Math.cos(angle), 20 | sin = Math.sin(angle), 21 | dx = canvas.width / 2, 22 | dy = canvas.height / 2; 23 | 24 | context.save(); 25 | context.fillStyle = "#ff0000"; 26 | context.transform(cos, sin, -sin, cos, dx, dy); 27 | context.fillRect(-50, -50, 100, 100); 28 | context.restore(); 29 | } 30 | drawFrame(0); 31 | } 32 | } 33 | 34 | void main() { 35 | new matrixrotate().run(); 36 | } 37 | -------------------------------------------------------------------------------- /examples/ch18/matrixrotate/matrixrotate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Matrix Rotate 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch18/rotatexy/rotatexy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Rotate XY 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch18/skewx/skewx.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class skewx { 5 | 6 | skewx() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | 14 | drawFrame(int t) { 15 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 16 | context.clearRect(0, 0, canvas.width, canvas.height); 17 | 18 | var skewX = (mouse.x - canvas.width / 2) * 0.01, 19 | dx = canvas.width / 2, 20 | dy = canvas.height / 2; 21 | 22 | context.save(); 23 | context.fillStyle = "#ff0000"; 24 | context.transform(1, 0, skewX, 1, dx, dy); 25 | context.fillRect(-50, -50, 100, 100); 26 | context.restore(); 27 | } 28 | drawFrame(0); 29 | } 30 | } 31 | 32 | void main() { 33 | new skewx().run(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/ch18/skewx/skewx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Skew X 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch18/skewxy/skewxy.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | 4 | class skewxy { 5 | 6 | skewxy() { 7 | } 8 | 9 | void run() { 10 | CanvasElement canvas = document.query('#canvas'); 11 | var context = canvas.getContext('2d'); 12 | var mouse = utilslib.Utils.captureMouse(canvas); 13 | 14 | drawFrame(int t) { 15 | document.window.webkitRequestAnimationFrame(drawFrame, canvas); 16 | context.clearRect(0, 0, canvas.width, canvas.height); 17 | 18 | var skewX = (mouse.x - canvas.width / 2) * 0.01, 19 | skewY = (mouse.y - canvas.height / 2) * 0.01, 20 | dx = canvas.width / 2, 21 | dy = canvas.height / 2; 22 | 23 | context.save(); 24 | context.fillStyle = "#ff0000"; 25 | context.transform(1, skewY, skewX, 1, dx, dy); 26 | context.fillRect(-50, -50, 100, 100); 27 | context.restore(); 28 | } 29 | drawFrame(0); 30 | } 31 | } 32 | 33 | void main() { 34 | new skewxy().run(); 35 | } 36 | -------------------------------------------------------------------------------- /examples/ch18/skewxy/skewxy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Skew XY 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/assets/boing.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch19/assets/boing.mp3 -------------------------------------------------------------------------------- /examples/ch19/assets/boing.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch19/assets/boing.ogg -------------------------------------------------------------------------------- /examples/ch19/assets/boing.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/ch19/assets/boing.wav -------------------------------------------------------------------------------- /examples/ch19/brownian1/brownian1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Brownian 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/brownian2/brownian2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Brownian 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/classes/bound.dart: -------------------------------------------------------------------------------- 1 | class localBound { 2 | num x; 3 | num y; 4 | num width; 5 | num height; 6 | localBound(this.x, this.y, this.width, this.height); 7 | } 8 | -------------------------------------------------------------------------------- /examples/ch19/classes/point.dart: -------------------------------------------------------------------------------- 1 | class point { 2 | num x; 3 | num y; 4 | num radius; 5 | point(this.x, this.y); 6 | } -------------------------------------------------------------------------------- /examples/ch19/random1/random1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random1 { 4 | 5 | random1() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 50; 12 | 13 | while (numDots--) { 14 | var x = canvas.width / 2 + Math.random() * 200 - 100, 15 | y = canvas.height / 2 + Math.random() * 200 - 100; 16 | 17 | context.fillStyle = "#000000"; 18 | context.beginPath(); 19 | //x, y, radius, start_angle, end_angle, anti-clockwise 20 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 21 | context.closePath(); 22 | context.fill(); 23 | } 24 | } 25 | } 26 | 27 | void main() { 28 | new random1().run(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/ch19/random1/random1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random2/random2.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random2 { 4 | 5 | random2() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300; 12 | 13 | while (numDots--) { 14 | var x = canvas.width / 2 + Math.random() * 100 - 50, 15 | y = canvas.height / 2 + Math.random() * 100 - 50; 16 | 17 | context.fillStyle = "#000000"; 18 | context.beginPath(); 19 | //x, y, radius, start_angle, end_angle, anti-clockwise 20 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 21 | context.closePath(); 22 | context.fill(); 23 | } 24 | } 25 | } 26 | 27 | void main() { 28 | new random2().run(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/ch19/random2/random2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random3/random3.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random3 { 4 | 5 | random3() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300; 12 | var maxRadius = 50; 13 | 14 | while (numDots--) { 15 | var radius = Math.random() * maxRadius, 16 | angle = Math.random() * (Math.PI * 2), 17 | x = canvas.width / 2 + Math.cos(angle) * radius, 18 | y = canvas.height / 2 + Math.sin(angle) * radius; 19 | 20 | context.fillStyle = "#000000"; 21 | context.beginPath(); 22 | //x, y, radius, start_angle, end_angle, anti-clockwise 23 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 24 | context.closePath(); 25 | context.fill(); 26 | } 27 | } 28 | } 29 | 30 | void main() { 31 | new random3().run(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/ch19/random3/random3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random4/random4.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random4 { 4 | 5 | random4() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300; 12 | var maxRadius = 50; 13 | 14 | while (numDots--) { 15 | var radius = Math.sqrt(Math.random()) * maxRadius, 16 | angle = Math.random() * (Math.PI * 2), 17 | x = canvas.width / 2 + Math.cos(angle) * radius, 18 | y = canvas.height / 2 + Math.sin(angle) * radius; 19 | 20 | context.fillStyle = "#000000"; 21 | context.beginPath(); 22 | //x, y, radius, start_angle, end_angle, anti-clockwise 23 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 24 | context.closePath(); 25 | context.fill(); 26 | } 27 | } 28 | } 29 | 30 | void main() { 31 | new random4().run(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/ch19/random4/random4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 4 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random5/random5.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random5 { 4 | 5 | random5() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300; 12 | 13 | while (numDots--) { 14 | var x1 = Math.random() * canvas.width, 15 | x2 = Math.random() * canvas.width, 16 | x = (x1 + x2) / 2, 17 | y = canvas.height / 2 + Math.random() * 50 - 25; 18 | 19 | context.fillStyle = "#000000"; 20 | context.beginPath(); 21 | //x, y, radius, start_angle, end_angle, anti-clockwise 22 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 23 | context.closePath(); 24 | context.fill(); 25 | } 26 | } 27 | } 28 | 29 | void main() { 30 | new random5().run(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/ch19/random5/random5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 5 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random6/random6.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random6 { 4 | 5 | random6() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300, 12 | iterations = 6; 13 | 14 | while (numDots--) { 15 | var xpos = 0; 16 | for (var i = 0; i < iterations; i++) { 17 | xpos += Math.random() * canvas.width; 18 | } 19 | var x = xpos / iterations, 20 | y = canvas.height / 2 + Math.random() * 50 - 25; 21 | 22 | context.fillStyle = "#000000"; 23 | context.beginPath(); 24 | //x, y, radius, start_angle, end_angle, anti-clockwise 25 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 26 | context.closePath(); 27 | context.fill(); 28 | } 29 | } 30 | } 31 | 32 | void main() { 33 | new random6().run(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/ch19/random6/random6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 6 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random7/random7.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | 3 | class random7 { 4 | 5 | random7() { 6 | } 7 | 8 | void run() { 9 | CanvasElement canvas = document.query('#canvas'); 10 | var context = canvas.getContext('2d'); 11 | var numDots = 300, 12 | iterations = 6; 13 | 14 | while (numDots--) { 15 | var xpos = 0; 16 | var ypos = 0; 17 | for (var i = 0; i < iterations; i++) { 18 | xpos += Math.random() * canvas.width; 19 | } 20 | for (var j = 0; j < iterations; j++) { 21 | ypos += Math.random() * canvas.height; 22 | } 23 | 24 | var x = xpos / iterations, 25 | y = ypos / iterations; 26 | 27 | context.fillStyle = "#000000"; 28 | context.beginPath(); 29 | //x, y, radius, start_angle, end_angle, anti-clockwise 30 | context.arc(x, y, 2, 0, (Math.PI * 2), true); 31 | context.closePath(); 32 | context.fill(); 33 | } 34 | } 35 | } 36 | 37 | void main() { 38 | new random7().run(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/ch19/random7/random7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 7 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/random8/random8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Random 8 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ch19/samemass/samemass.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Same Mass 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/soundevents/soundevents.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Sound Events 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 |

Your browser does not support the canvas element.

15 |
16 | 17 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/ch19/timebased1/timebased1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Time Based 1 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/timebased2/timebased2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Time Based 2 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/timebased3/timebased3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Time Based 3 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/ch19/timer1/timer1.dart: -------------------------------------------------------------------------------- 1 | #import('dart:html'); 2 | #import('../../include/utilslib.dart', prefix:'utilslib'); 3 | #source('../classes/ball.dart'); 4 | #source('../classes/bound.dart'); 5 | 6 | class timer1 { 7 | 8 | timer1() { 9 | } 10 | 11 | void run() { 12 | CanvasElement canvas = document.query('#canvas'); 13 | var context = canvas.getContext('2d'); 14 | var ball = new Ball(), 15 | fps = 30; 16 | 17 | ball.y = canvas.height / 2; 18 | ball.vx = 5; 19 | 20 | drawFrame () { 21 | context.clearRect(0, 0, canvas.width, canvas.height); 22 | 23 | ball.x += ball.vx; 24 | ball.draw(context); 25 | } 26 | 27 | window.setInterval(drawFrame, (1000/fps).toInt()); 28 | } 29 | } 30 | 31 | void main() { 32 | new timer1().run(); 33 | } 34 | -------------------------------------------------------------------------------- /examples/ch19/timer1/timer1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Timer 6 | 7 | 8 | 9 |
10 | Example from Foundation HTML5 Animation with JavaScript 11 |
12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/clean.sh: -------------------------------------------------------------------------------- 1 | find . -type f -name "*.app.js" -exec rm -f {} \; 2 | rm -rf out 3 | -------------------------------------------------------------------------------- /examples/gitClean.sh: -------------------------------------------------------------------------------- 1 | find . -type f -name "*.app.js" -exec git rm {} \; 2 | rm -rf out 3 | -------------------------------------------------------------------------------- /examples/include/book-thumb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/include/book-thumb.jpg -------------------------------------------------------------------------------- /examples/include/color.dart: -------------------------------------------------------------------------------- 1 | /* 2 | ** Describes a RGB color. */ 3 | class Color 4 | { 5 | num R, G, B; 6 | String _rawR, _rawG, _rawB; 7 | 8 | Color(Colors color){ 9 | _parseAndLoadColors(color._hex); 10 | } 11 | 12 | Color.fromRGB(this.R, this.G, this.B){ 13 | _rawR = R.toRadixString(16).toUpperCase(); 14 | _rawG = G.toRadixString(16).toUpperCase(); 15 | _rawB = B.toRadixString(16).toUpperCase(); 16 | } 17 | 18 | //TODO Color.fromHSV(...) 19 | 20 | Color.hex(String hex){ 21 | _parseAndLoadColors(hex); 22 | } 23 | 24 | void _parseAndLoadColors(String color){ 25 | if (!color.startsWith("#")) return; 26 | 27 | String c = color.replaceFirst("#",""); 28 | 29 | if (c.length != 6) return; 30 | 31 | _rawR = c.substring(0,2); 32 | _rawG = c.substring(2,4); 33 | _rawB = c.substring(4,6); 34 | R = Math.parseInt("0x" + _rawR); 35 | G = Math.parseInt("0x" + _rawG); 36 | B = Math.parseInt("0x" + _rawB); 37 | 38 | } 39 | 40 | String toString() => "#" + _rawR + _rawG + _rawB; 41 | 42 | String get _type() => "Color"; 43 | } 44 | -------------------------------------------------------------------------------- /examples/include/file_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adam-singer/dart-html5-animation/5e68acf8bd0872403cefa3db5224bd8916d63d03/examples/include/file_icon.png -------------------------------------------------------------------------------- /examples/include/mouse.dart: -------------------------------------------------------------------------------- 1 | class Mouse { 2 | int x; 3 | int y; 4 | MouseEvent event; 5 | Mouse() { x=0; y=0; } 6 | } 7 | -------------------------------------------------------------------------------- /examples/include/touch.dart: -------------------------------------------------------------------------------- 1 | //class touch { 2 | // num x; 3 | // num y; 4 | // TouchEvent event; 5 | // bool isPressed; 6 | // touch(this.x,this.y,this.isPressed,this.event); 7 | //} 8 | -------------------------------------------------------------------------------- /examples/include/utilslib.dart: -------------------------------------------------------------------------------- 1 | #library('utilslib'); 2 | 3 | #import('dart:html'); 4 | 5 | #source('utils.dart'); 6 | #source('mouse.dart'); 7 | #source('keycode.dart'); 8 | // #source('touch.dart'); 9 | --------------------------------------------------------------------------------