Home Contact RSS

Interactive Spin Actionscript Tutorial

I have been thinking of different interactions that are possible with objects. If you’ve read this blog at all you’ll know that I’ve played with physics and gravity and throwing balls and bouncing balls and all sorts. But I hadn’t wrapped my head around an interactive spinner. I know it’d be easy to make a slider or something that would apply a spin to an object, but this just isn’t interactive enough for me.

Circle with slider to rotate and button for random spin:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

This attempt at spinning is ok. I mean, it spins the object and it even glides to a stop if you press the button for a random spin… But it’s just not intuitive and not fun. But if you want this, here’s how I did it.

Actionscript:

  1. drag = .96;
  2. speed = 0;
  3.  
  4. slider.handle.onPress = function() {
  5. spinning = false;
  6. //drag along the line
  7. this.startDrag(true, slider.line._x-slider.handle._width/2, slider.line._y-slider.handle._height/2, slider.line._width-slider.handle._width/2, slider.line._y-slider.handle._height/2);
  8. }
  9. slider.handle.onRelease = slider.handle.onReleaseOutside = function() {
  10. this.stopDrag();
  11. }
  12. _root.onEnterFrame = function() {
  13. if (spinning) {
  14. //apply the speed to the rotation
  15. knob._rotation += speed;
  16. //recalculate speed
  17. speed = speed*drag;
  18. //if speed gets unnoticeably tiny just set it to 0
  19. if (Math.pow(speed, 2) < .0001) {
  20. speed = 0;
  21. }
  22. }
  23. else {
  24. //set the rotation from the slider position
  25. knob._rotation = slider.line._x + slider.handle._x + slider.handle._width/2;
  26. }
  27.  
  28. //spit out feedback continuously
  29. feedbackr.text = knob._rotation;
  30. feedbackaccr.text = speed;
  31. }
  32. spinner.onRelease = function() {
  33. //find a random speed
  34. speed = (Math.random()* 50) - 25;
  35. spinning = true;
  36. }

I want to grab it and spin it though. I want to apply the same principles from physics, like acceleration and friction as forces to the object, so I can grab to spin and release to watch it glide gracefully to a stop. I’ve been thinking about this and how I’d have to use trigonometry and stuff to do it. One day I finally had the time and tried it out. It took me a minute but I figured out that what I needed was arctangent. So (with pointers from jbum, thanks Jim!) I came up with this:

Interactive grab-able circle to spin and twirl:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

This one is much more interactive and intuitive. I really think this is because there are no sliders or buttons, no controls, just an object to interact with. It’s much more like real life!

Steps:

In order to make a grab and spin object
1. You have to know where you grab. The user clicks on the shape (knob) and you must figure out what degree or rotation point they have started at. (atan2)
2. As the knob is clicked and the mouse moves (dragging), calculate new rotation by mouse position
3. When mouse is released figure out the current speed of rotation and apply it to the knob with friction, so it can be thrown and spun in that way. (Of course this is optional, if you just want to spin it when the mouse is down you’re done at step 2)

Actionscript:

  1. damp = .96; //friction
  2. r = 0; //rotation
  3. accr = 0; //speed of rotation
  4.  
  5. knob.onPress = function() {
  6. dragging = true;
  7. //find mouse y coordinate in relation to knob origin
  8. a = _root._ymouse - knob._y;
  9. //find mouse x coordinate in relation to knob origin
  10. b = _root._xmouse - knob._x;
  11. //using arctangent find the spot of rotation (in degrees)
  12. oldr = Math.atan2(a,b)*180/Math.PI;
  13. }
  14.  
  15. knob.onRelease = knob.onReleaseOutside = function() {
  16. dragging = false;
  17. }
  18.  
  19. knob.onEnterFrame = function() {
  20. if (dragging) {
  21. //find mouse y coordinate in relation to knob origin
  22. a = _root._ymouse-knob._y;
  23. //find mouse x coordinate in relation to knob origin
  24. b = _root._xmouse-knob._x;
  25. //using arctangent find the spot of rotation (in degrees)
  26. r = Math.atan2(a,b)*180/Math.PI;
  27.  
  28. //use current rotation and previous rotation
  29. //to find acceleration
  30. //averages the acceleration with the
  31. //previous acceleration for smoother spins
  32. accr = ((r - oldr) + accr)/2;
  33. //apply the acceleration to the rotation
  34. knob._rotation += accr;
  35. //remember current rotation as old rotation
  36. oldr = r;
  37. feedbacka.text = a;
  38. feedbackb.text = b;
  39. }
  40. else {
  41. knob._rotation += accr;
  42. //apply friction to acceleration force
  43. //and if acceleration gets tiny, just set it to zero
  44. if (Math.pow(accr, 2) > .0001 ) {
  45. accr *= damp;
  46. }
  47. else{
  48. accr = 0;
  49. }
  50. }
  51. //spit out feedback continuosly
  52. feedbackr.text = knob._rotation;
  53. feedbackaccr.text = accr;
  54. }

I commented the code to explain what is happening, if you need more just post a comment. Let me know if you find this useful and what you end up making with it.

Downloads:

spin fla
interactive spin fla

Tags: , , , , , , , , , , ,

Flash Den Link

flashden banner

 

Circlecube at Flashden

flashden logo

Tags: ,

Circlecube Polls Readers for Content

Just added a poll plug-in to the site!

I’m polling readers to see what they want next, in regards to posts.

I have so many post drafts and even more post ideas and instead of letting them roll out in my usual leisurely fashion, I figured I’d let you prioritize them for me…
So vote in the poll to let me know what you want!

Feel free to contact me if you have any ideas that I haven’t listed yet. I enjoy knowing I’m writing for someone who is interested!

Please write about:

View Results

Loading ... Loading ...

Plug-in Credit to: Lester ‘GaMerZ’ Chan

Update:

This poll is closed, and I’m working on the winning post! Integrating Google Analytics with Flash!
So keep posted, or subscribe to the RSS for immediate automatic free update.

I’ll keep a running poll in the side bar of the site so keep voting and suggesting your Most Wanted Posts!

Tags: , , ,

New Circle Cube Logo

Here’s the new circlecube logo! I’ve had it for a while, but hadn’t uploaded it.

I still have to update my theme to incorporate it. I like the green transparent circlecube graphic in the header now but it’s gotta go… and plus it’s a little too green.

Circle Cube Logo Dec 2007

The common 2d © symbol and a 3d cube.
I’ll have to figure out a way to make it interactive… hm…

Any ideas?

Tags: , , , , ,

Circle Cube on Free IQ

Embedded player from Free IQ.
Nicholsong song by Dionysos, Music Video by Circle Cube Studio

Tags: , , , , , , , , , ,

Pog Portfolio - Interactive flash portfolio

An interactive flash portfolio featuring ‘pog’ thumbnails sortable by tags and adjustable properties.

open Circle Cube POG portfolio
Pog Thmb

Circle Cube . com
Toggle the help window with ‘h’.
Click the pogs to explore each piece, if applicaple click the ‘open window’ link.
Pog options are aligned across the top of the bay window, use them to adjust the properties within the bay area. Mix and match until you find your fit. Tag buttons are across the bottom, click to specify the genre of art to display.

Gravity:
Toggle the force of gravity acting on the pogs. Pogs with gravity on will be pulled down and bounce according to mass.
White is on. Black is off.

Spring:
Toggle the spring or elasticity option. Pogs will hinge to a point and orbit that point.
White is on. Black is off.

Grid:
Toggle the grid option. The pogs can either form into an array of pogs or move aimlessly in the space.
White is on. Black is off.

Friction:
Toggle the force of friction acting on the pogs. Pogs with friction will slow down and over time eventually stop.
White is on. Black is off.

Tags:
Click these tag button descriptors to see only that style of work in the portfolio.
Select all work, video, new media, animation, or drawing.

Tags: , , , , , , , , , , ,

Circle Cube

Circle cube graphic pushing colors. Thinking of the design as shapes in a stained glass window.

circle cube mixed up

ARST4810 CAD Fab class exhibition.
My Shattered Little World
Slide, Circle cube

Published in the Flagpole, April 4th 2007:
Rhinoceros Makes Art: Students in Michael Oliveri’s Computer Aided Design and Fabrication class at UGA are exhibiting their work in the Thomas Street Gallery. Using the computer program Rhinoceros, the students have created a diverse set of images.J.B. Courson ’s “Alpha Hab and Worker Drones” could be plans for the set of a Star Wars movie. Caroline Covington’s “Closure” re-invents the kamikaze bomb, with essential accompanying text. Diana Gurley’s circular imagery hovers on the page like hot-air balloons. Matthew McDonald’s “Lupa Ad Nauseam,” as the Latin title states, is an image of a wolf vomiting. The drawing of the wolf appears to be taken from a realistically executed etching, while the vomit is discretely portrayed as a splatter of color. Edward Whelan’s abstract geometric piece looks back to the Italian Futurists, with a fresh new design. Evan Mullins and Louis Grabowski have both created images of realistic-looking objects of play. Works by Andy Anzardo, Alex Castellanos, Jason Maddox, Chris Merz, Winston Parker and John Powers are also included in the show, which runs through Apr. 5, so hurry! The Thomas Street Gallery is located in UGA’s Sculpture Annex just off Broad Street.

Tags: , , , , , ,

Circle Cube

3D circle cube vector graphic.
circle cube green/purple/blue

Tags: , , , ,
Next entries »