Jump to content
Search Community

Having a Big problem for scaling randomly generated circle using canvas and tweenmax

rk25028 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

i want to make a animation where circle is created randomly using canvas and i want scale all the circle at the same time with their origigin X and Y.

please help me solve this issue .

i have generated the circle but they were not scaling when i scale property it scale the  whole circle as a single object.

please help me

thank you.

 

 

here is a codepan link  

 

please solve this i want every circle should scale.

See the Pen QNObbd by rk25028 (@rk25028) on CodePen

Link to comment
Share on other sites

You now scale the entire canvas with your tween. So what you see makes sense. I don't have much experience with canvas but if all circle elements have the same class like '.randCircle' than that's the thing you have to tween. It then will scale all items with that class.

 

Sitting in a bus right now and not sure if it works that way also in a canvas but you have to think in that direction I think.

  • Like 1
Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

As OzBoz mentions what you're seeing now is expected behaviour.

 

If want to animate each circle, then things get a bit more complicated, but it shouldn't bee too much though. The good thing is that you have all your circles in an array (randomCircles), so you can access them there and animate their scale.

 

Unfortunately I'm far from being a canvas expert, but you could use one of the canvas plugins GSAP has to offer or use Pixi in order to animate the element's scale (I've seen many cool things done with GSAP and Pixi so it should work).

 

EaslJS plugin

http://greensock.com/docs/#/HTML5/Plugins/EaselPlugin/

 

Kinetic Plugin

http://greensock.com/docs/#/HTML5/Plugins/KineticPlugin/

 

PixiJS

http://www.pixijs.com/

  • Like 2
Link to comment
Share on other sites

Just what  said. You're scaling the canvas element when you should be scaling the canvas context.

ctx.save();
ctx.scale(scale.x, scale.y);
// Draw some stuff...
ctx.restore();

I don't have a good a example of canvas scaling to show you. How about a circle that gets bigger?

See the Pen eNrQqV?editors=0010 by osublake (@osublake) on CodePen

 

Working with the canvas can be complicated. I'd take Rodrigo's advice and use a library. I like using PIXI, which will let you scale as many circles as you want.

See the Pen vNwRdO?editors=0010 by osublake (@osublake) on CodePen

  • Like 2
Link to comment
Share on other sites

You now scale the entire canvas with your tween. So what you see makes sense. I don't have much experience with canvas but if all circle elements have the same class like '.randCircle' than that's the thing you have to tween. It then will scale all items with that class.

 

Sitting in a bus right now and not sure if it works that way also in a canvas but you have to think in that direction I think.

 

 

i done with this process to create same class for all element. i have to do with only with  canvas.

Link to comment
Share on other sites

I shall echo what everybody else has said - what you have at the moment is expected behaviour. 

 

However, I wouldn't say Canvas is any more complicated than what some people are doing here. It just has a few different concepts to grasp.

 

The main point is that everything inside the <canvas> is a drawn bitmap. If you are going to animate, you need to move everything to its position and draw again for every frame of the animation.

 

Coincidentally I was doing some tests yesterday following this tutorial, made some minor changes to work with GreenSock's 'tick' but it is still pretty much copy and paste someone else's code.

 

See the Pen pydqOy by dipscom (@dipscom) on CodePen

 

Here are two eBooks you can read to get deep knowledge of <canvas>. It will probably be far too technical for what you are after at the moment but useful in the long run.

 

http://joshondesign.com/p/books/canvasdeepdive/title.html

http://bucephalus.org/text/CanvasHandbook/CanvasHandbook.html

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...