XWidgetSoft Forum
https://xwidget.com/bbs/

Shake Animation TRICK???
https://xwidget.com/bbs/viewtopic.php?f=8&t=3737
Page 1 of 1

Author:  Jimking [ November 5th, 2013, 4:08 am ]
Post subject:  Shake Animation TRICK???

Check this out guys! Cool? 8-)
(the design is not completed yet that's why the top of the wires look like this)

Everyone knows this pendulum "clock".
Is there a trick so I can add 1 second delay between the shake animations, or a way so the movement will be as the real one??? :roll:
(The balls move parallelly)
Tony added the delay function but is only for switch animations...

Attachments:
ok.jpg
ok.jpg [ 94.91 KiB | Viewed 22568 times ]

Author:  Jimking [ November 6th, 2013, 4:17 am ]
Post subject:  Re: Shake Animation TRICK???

I found this:

var img = paper.image("image.png", 10, 10, 80, 80);
(function swingRight(){
img.animate({'rotation': 30}, 1000, '<>', function swingLeft(){
img.animate({'rotation': -30}, 1000, '<>', swingRight);
});
}());

how can this be applied on Designer...?

An image can be animated (shake-pendulum animation) using a script?

Author:  9yomo [ November 6th, 2013, 6:04 am ]
Post subject:  Re: Shake Animation TRICK???

you can also write this between every animate starts:
sleep(100);
It means that the next line of cade will start in 100 millisecond after the previous line of code of cade .

Author:  Dagedee [ November 6th, 2013, 7:45 am ]
Post subject:  Re: Shake Animation TRICK???

There is a nice widget by xwidgetsoft with "shaking script" http://url9.de/OBr.
Maybe it's helpful.

Author:  Jimking [ November 6th, 2013, 7:46 am ]
Post subject:  Re: Shake Animation TRICK???

Thanks 9yomo! :)

Author:  Jimking [ November 6th, 2013, 7:48 am ]
Post subject:  Re: Shake Animation TRICK???

Dagedee wrote:
There is a nice widget by xwidgetsoft with "shaking script" http://url9.de/OBr.
Maybe it's helpful.

Oh thanks Dagedee! :D
I will check it right now!

Author:  Jimking [ November 6th, 2013, 8:26 am ]
Post subject:  Re: Shake Animation TRICK???

The suggestion of Dagedee made the job! :D
Here is the script:

Quote:
var rockRange = 5; //»Î¶¯·ù¶È£¬¿É×ÔÐÐÐÞ¸ÄÆäÖµ

/////////////////////
var Counter= 1;
function timercore1OnUpdate(Sender)
{
Counter = Counter +1;
rotator1.rotateAngle = -15 + (Math.cos((Counter%40)/40*2*Math.PI)/rockRange+0.25)/Math.PI*180 ;

Counter = Counter +1;
rotator2.rotateAngle = -15 + (Math.cos((Counter%40)/40*2*Math.PI)/rockRange+0.25)/Math.PI*180 ;
}


But the delay function for the second ball (rotator2) sleep(100);
where exactly must be placed??


Pratically I think that the right ball when the widget starts, on the first run, needs 1 sec of delay.
And then a delay on each ball at the end of their movement (?)

Author:  Jimking [ November 6th, 2013, 12:29 pm ]
Post subject:  Re: Shake Animation TRICK???

Searching on Internter I found these:
http://stackoverflow.com/questions/9510 ... n-of-sleep

Quote:
var waitTillSomethingHappens = function(){
if(somethingHappened == 1)
{
alert('Something Happened get out of sleep');
}
else
{
setTimeout(waitTillSomethingHappens,1000);
}
};

Or:
Quote:
function yourFunction(){

//do something
setInterval(myFunc(),1000);
//do something else

}

function myFunc(){
return;
}


Could some apply it to my script...?

Author:  Dagedee [ November 6th, 2013, 2:12 pm ]
Post subject:  Re: Shake Animation TRICK???

It is just "sleep () //ms", for example:

function button1OnClick(Sender)
{
image1.visible = true;
sleep (2000); //ms
image1.visible = false;
}
Attachment:
sleep_example.rar [5.5 KiB]
Downloaded 349 times

Author:  Jimking [ November 6th, 2013, 4:32 pm ]
Post subject:  Re: Shake Animation TRICK???

Dagedee wrote:
It is just "sleep () //ms", for example:

function button1OnClick(Sender)
{
image1.visible = true;
sleep (2000); //ms
image1.visible = false;
}
Attachment:
sleep_example.rar

Thanks man but with animations I think that is different...
That's why I asked how exactly the sleep function can be applied on my case...!
It will be more helpful if you can provide me exactly the script with this mode..

Author:  Dagedee [ November 7th, 2013, 4:03 am ]
Post subject:  Re: Shake Animation TRICK???

It is exactly the way 9yomo wrote already.

"you can also write this between every animate starts:
sleep(100);
It means that the next line of code will start in 100 millisecond after the previous line of code."
in your case e.g.:

Counter = Counter +1;
sleep(100)
rotator1.rotateAngle = -15 + (Math.cos((Counter%40)/40*2*Math.PI)/rockRange+0.25)/Math.PI*180 ;

Well, you asked for "sleep" but I don't think that this will meet your request. Most likely it would work with a timercore, "timeout" and "set interval". Maybe someone knows the exact code (unfortunately I don't know).
I would use a gif or animated png image to get this effect. It is easy to make and doesn't need much CPU power ("sleep" needs a lot).
Attachment:
sphere.gif
sphere.gif [ 13.27 KiB | Viewed 22516 times ]

Author:  Jimking [ November 7th, 2013, 4:47 am ]
Post subject:  Re: Shake Animation TRICK???

Dagedee wrote:
I would use a gif or animated png image to get this effect. It is easy to make and doesn't need much CPU power ("sleep" needs a lot).
Attachment:
sphere.gif

Thanks Dagedee! I will modify the code and I'll post the results... :)
About the gifs or animated pngs they need work to make all the frames and unfortunately especially with gifs, I have tested in the past and the cpu increases a lot!

Author:  Dagedee [ November 7th, 2013, 7:01 am ]
Post subject:  Re: Shake Animation TRICK???

Well, I know already that you are not very enthusiastic about gifs and animated png images. :D
But I made only positive experiences so far. Animated png and gif images need very little CPU power.
(You might check the attached widget) Okay, it takes some time to create them, but it saves a lot of CPU power on the other hand.
It took me not more than 10 min to create the gifs I used for the attached widget. I'm using Photoshop to create gifs but it is also possible to use Gimp or (the easiest way) to use Photoscape http://url9.de/OEo.

Author:  Jimking [ November 7th, 2013, 7:48 am ]
Post subject:  Re: Shake Animation TRICK???

Good job Dagedee! 8-)
I only use GIMP for my widgets and yes I'm not so fun of the gifs and animated png. :lol:
But don't forget these:
1) More big and complicate image/widget = more resources
I'm almost sure that if you try to reproduce the balls movement from my widget you will see the real cpu consumption..
2) Needs a lot of images/frames so the movement will be fluid and more realistic possible.
Just compare the movement of the gif and the test widget... ;)

Author:  Jimking [ November 8th, 2013, 4:42 pm ]
Post subject:  Re: Shake Animation TRICK???

Any help guys with the script..? :(

Author:  Dagedee [ November 11th, 2013, 5:23 am ]
Post subject:  Re: Shake Animation TRICK???

I've created some more widgets (gif & animated png) with smoother animation now, CPU is always at zero. (Used frames are 73, but I only had to create 36 the others are just copies.) If you will use very large images than the CPU consumption will increase, that's for sure. :)
Attachment:
spheres.gif
spheres.gif [ 118.05 KiB | Viewed 22460 times ]

Attachment:
spheres_examples.rar [188.89 KiB]
Downloaded 379 times

Author:  Jimking [ November 11th, 2013, 5:37 am ]
Post subject:  Re: Shake Animation TRICK???

Quote:
If you will use very large images than the CPU consumption will increase, that's for sure. :)

Yes I'm afraid so..! Damm I'm sure that only a little part is missing in my script. I just need only 1sec delay at the first run of the right ball, and after that 1sec delay for each ball at the end of their movement, when their return...
(if my calculations are right! :lol: )

Author:  Dagedee [ November 11th, 2013, 6:28 am ]
Post subject:  Re: Shake Animation TRICK???

You can determine the interval of every frame of a gif. :)
... I know you prefer a solution via script, hence I will not bug you any longer with gifs and animated pngs. :D
Attachment:
gif_setting.png
gif_setting.png [ 16.42 KiB | Viewed 22455 times ]

Author:  Jimking [ November 11th, 2013, 8:44 am ]
Post subject:  Re: Shake Animation TRICK???

No Dagedee of course you're not bother me! I appreciate your interest.. :)
Let's hope that someone will give me a hand with the script...

Author:  Dagedee [ November 11th, 2013, 10:08 am ]
Post subject:  Re: Shake Animation TRICK???

All right! :D

Author:  digigamer [ November 15th, 2013, 10:39 pm ]
Post subject:  Re: Shake Animation TRICK???

What's the thing with classic newtonian physics :lol: ?? :lol: :lol:
SHM was always difficult for me.... :mrgreen:

I'll see what I can do.

Author:  digigamer [ November 15th, 2013, 11:13 pm ]
Post subject:  Re: Shake Animation TRICK???

Add a datetimecore and set it to update the datetimecore1OnUpdate
Code:
var even = false;      //set true to start animation from left

function datetimecore1OnUpdate(Sender)
{
  //do your animation!!!
  if(even) {
    for(i = 7; i >= 0; i--)
    {
        sleep(62); //delay(62); ???
        right.RotateAngle = i;
    }
    for(i = 1; i <= 8; i++)
    {
        sleep(62); //delay(62); ???
        right.RotateAngle = i;
    }
  } else { //odd
  for(i = 353; i <= 360; i++)
    {
        sleep(62); //delay(62); ???
        left.RotateAngle = i;
    }
    for(i = 359; i >= 352; i--)
    {
        sleep(62); //delay(62); ???
        left.RotateAngle = i;
    }
  }
  even = !even;
}

had to 'simulate' shake animation in code. Though not so perfect but... :( Works with rocketing CPU's unfortunately. Couldn't help, the sleep() kills the CPU time! (Usage goes upto 10%-15%)

Xwidget had a delay function but it appears that Tony had removed it (still exists in Autocomplete though!). That was a bit soft on the CPU

Author:  Jimking [ November 16th, 2013, 2:49 am ]
Post subject:  Re: Shake Animation TRICK???

Thanks man!!! And yes I tested and the CPU is not good.. I will try to modify the delay times a bit so the movement will be more realistic as possible. There is too much delay between the balls at the end of their movement. About the delay function I will ask Tony if can provide me a patch with the delay enable. But I think that the other users must have the patch too so the widget will work fine on their pc right..? :(

Author:  digigamer [ November 19th, 2013, 6:47 pm ]
Post subject:  Re: Shake Animation TRICK???

Yeah

Author:  Jimking [ November 19th, 2013, 6:53 pm ]
Post subject:  Re: Shake Animation TRICK???

digigamer wrote:
Yeah

Just leave it man..! So much trouble... :|

Author:  hamid [ December 3rd, 2013, 3:22 pm ]
Post subject:  Re: Shake Animation TRICK???

i never had this kind of clock, so i don't know how exactly these clocks work,
but i guessed it should be this way:
so here's my solution:

Attachment:
Pendulum_Sphere_Clock.XWidgetPkg [254.49 KiB]
Downloaded 377 times


and just to note:
left ball doesn't have shadow on the ground

Author:  Jimking [ December 3rd, 2013, 3:54 pm ]
Post subject:  Re: Shake Animation TRICK???

hamid wrote:
i never had this kind of clock, so i don't know how exactly these clocks work,
but i guessed it should be this way:
so here's my solution:

Attachment:
Pendulum_Sphere_Clock.XWidgetPkg


and just to note:
left ball doesn't have shadow on the ground

Oh my God!!!! UNBELIEVABLE! :shock:
You did it!!! How?!
Yes I know about the ball shadows but this was the minimum...
Really I don't know what can I say....

T H A N K S

I will finish the design and I will post it as soon as possible! :D

Author:  digigamer [ December 14th, 2013, 9:11 am ]
Post subject:  Re: Shake Animation TRICK???

viewtopic.php?f=10&t=3667
Some interesting things were found here... it solves the cpu usage problem nicely, the rotateto() function specifically

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/