html5 - animating a shape created w/javascript/canvas -


i sort of new here , new javascript. trying learn how work javascript/html5/canvas. have been working way through several tutorials. have gone trough ones animating shape can not find 1 yet drawn shape reacts user input. mouse going on rectangle resulting in color change. or better this.

http://dan.forys.co.uk/experiments/mesmerizer/

can 1 point me tutorial achieve that? thank daniela

first clarify 1 thing, canvas doesn't know what's on it. can tell color pixel can't tell rectangle here or circle there. our purposed, consider canvas write-only. functionality exists in svg if want consider application, caveat canvas more universally supported.

knowing what's under mouse relates application is. in example posted, developer took x , y position mouse event (using jquery) , did quick math calculate row , column in. apply saying, "cell (x, y) moused over, when next redraw consider that."

canvas applications work following way:

  1. create environment entirely in javascript (with arrays, objects, etc).
  2. use rendering routine draw environment canvas.
  3. listen mouse events, timers, etc.
  4. check how event affects environment.
  5. apply changes environment.
  6. reuse rendering routine step 2 update canvas new environment.
  7. go step 3.

with in mind, tutorial should helpful, java, .net, android, etc. have own drawing surfaces , tutorials build on them.

in regards canvas, here's fun tutorial: http://billmill.org/static/canvastutorial/index.html

the tutorial builds breakout game listens mouse events , timer events. mouse event doesn't checking see over, timer event work check if ball exists in same space block or paddle , updates canvas , javascript environment accordingly.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -