How to optimize acceleration / friction function more

Hello!

In a few words what the code does:

It begins to spin at a speed of 2 degrees and 5 seconds, it speeds up to 20 degrees per second.
After that, the rotational speed remains 20 for 10 seconds and after that dry 10 are more
He gets in the service of friction where it slows down to 2deg dry.

but! as I am not good with optimization and writing clean code I have a need to ask if this is a good code or we can do even better (more optimized and cleaner).

The code is the following:

Box() is a simple box shape, nothing more


          import flash.display.MovieClip;
          import flash.events.Event;


          public class Main extends MovieClip
          {

                    protected var _box:Box = new Box();

                    private var fps:Number = stage.frameRate;
                    private var step:Number = 20;
                    private var minStep:Number = 2;
                    private var time:Number = 5;
                    private var increment:Number = (step - minStep) / (time * fps);
                                                                                          // 20 - 2 / 5 * 30
                                                                                          // 18 / 150
                                                                                          // 0.12
                    protected var timePassed:Number = 0


                    public function Main()
                    {
                              _box.x = stage.stageWidth/2 - _box.width/2;
                              _box.y = stage.stageHeight/2 - _box.height/2;
                              this.addChild(_box);

                              stage.addEventListener(Event.ENTER_FRAME, constantMovement);
                    }



                    private function friction():void
                    {
                               _box.rotation += step;
                                  step -= increment;
                                  step = Math.max(2, step);
                    }

                    private function acceleration():void
                    {
                               _box.rotation += minStep;
                               minStep += increment;
                               minStep = Math.min(minStep, 20);
                    }

                    private function constantMovement(event:Event)
                    {
                              if(minStep < 20)
                              {
                                        acceleration()
                              }
                              else if(minStep >= 20 && timePassed <= 10)
                              {
                                        _box.rotation += 20;
                                        timePassed += 10 / (time * fps)
                                        trace("timePassed :" + timePassed)
                              }
                              else if (minStep >= 20 && timePassed >= 10)
                              {
                                        friction();
                              }
                    }


          }
}

If there is something more, that it can be please tell me / help me.

You can do the following:

1. replace the last ElseIf (minStep > = 20 & timePassed > = 10) with just something else, because the condition would be always true control reaches here.

2 store the value 10 / (time * fps) in a private variable and use that directly, rather than assess every time that the value remains constant.

You can also try to replace the if-else-if block with a block switch-box on a state variable in the class (with the values 0, 1, 2 mean acceleration, constant speed and slows down, you can set a constant symbolic to hold the values). Initialize the variable with the value 0 (acceleration), change to 1 when minStep becomes 20 and so on. Point No. 2 is always good too.

DIA-

Tags: Adobe Animate

Similar Questions

  • I have more endurance, remove or insert the option pages after upgrade to Adobe DC. How to get back these functions?

    I have more endurance, remove or insert the option pages after upgrade to Adobe DC. How to get back these functions?

    Looks like you may have updated to misapplication. Probably, you have Adobe Acrobat (the full version) and installed Adobe Acrobat Reader instead. If you had "improved" Adobe Acrobat, it would have cost you money. Acrobat Reader is free.

  • I used the text tool function more than the reminder function, how do I get it back?

    I used the text tool function more than the reminder function, how do I get it back?

    Hi Slate7Berta,

    Please use Adobe acrobat reader DC Acrobat Reader DC Learn & support instead of touch Adobe, there seems to be a compatibility issue.

    Kind regards

    Nicos

  • Pop - up saying that I am low on memory and close the files. How to check my memory or more or delete files that take memory?

    Original title: HOW TO CHECK FOR an INSUFFICIENT MEMORY

    I have a Toshiba laptop (110 GB Vista, Windows 7), but I don't know how to check the memory and get a pop up saying that I am low on memory and close the files... How to check my memory or more or delete files that take memory? Thank you

    Hello

    ·         You will remember to do recent changes on the computer before this problem?

    ·         Fact the occurs when you only access Internet Explorer?

    ·         You have dual boot on the computer operating system? If yes the issue is limited to Windows vista?

    Low memory message may appear if the system hard drive is full, or running out of memory. I suggest you follow the steps in the link and check if the problem persists:

    http://Windows.Microsoft.com/en-us/Windows-Vista/preventing-low-memory-problems

    You can also optimize Windows vista for better performance. Follow the steps in the link:

    http://Windows.Microsoft.com/en-us/Windows-Vista/optimize-Windows-Vista-for-better-performance

  • How to associate the key function on thinkpad T61p

    How to associate the key function on thinkpad__Fn Key__Hibernate mapping of keys for Lenovo Thinkpads

    How to map the keys "Fn F4" on my Thinkpad T61p to keyboard MS Wireless Comfort Keyboard 5000 to Hibernate?

    Your Thinkpad keyboard doesn't have access to the MS Wireless Comfort Keyboard 5000 drivers, firmware and add the functioon of Microsoft for the Thinkpad (and vice versa).

    Here is an article on how to remap the keys in Vista (with a link to a program that will help): http://www.howtogeek.com/howto/windows-vista/map-any-key-to-any-key-on-windows-xp-vista/. I don't know if this works with the function keys, but it's worth a try.

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • How to use the @accum function in the calculation script

    Dear all.

    I'm new in essbase - calculation script so don't know how to use the @accum function.

    I want the aggregation value of child to parent

    Hierarchy

    Product

    100 > Storage Dimensions marked as stored (marked as intentionally as I want to calculate the value using the calculation script)

    100. 10 (+)

    100-20 (+)

    100-30 (+)

    I'm trying calculation Script

    100 = @Accum (@children("100"), jan: Feb);

    It works when I use below

    100 = @Accum("100-10",Jan:Feb);

    Error:-number of Dimensions [1] does not match number of gen/lev [3] office [@Dim]

    Don't know how I can roll up to an aggregate value of all the members of the child to the parent.

    Error.PNGhierachy.PNG

    you do this more difficult it must be. If you want to accumulate up to 100 then you could just make your calc

    '100 '.

    but that would be only 100, to make the OU any dimension would

    AGG (Product);

    Or better yet

    AGG (Product, Market);

  • Ask for advice on how to optimize a website that loads slowly in the browser?

    My site works fine when I saw Muse or choose to view the site in the browser, but when I publish the BC site loads very slowly, even after optimizing file sizes & minimizing the use of the widget.  Online site is: http://www.northernharvest.com.au love thoughts or tips on how to optimize?  See you soon

    As long as you decide to use exorbitant oversized images in quantities that , you will have no chance to achieve faster load times!

    The images are much, much more then really necessary. Reduce their size to the dimensions in pixels, you really need them in your layout and minimize the size of the file by using a higher JPG compression.

  • Illustrators function more simple most stopped working. Probably just a shortened misstake?

    Illustrators function more simple most stopped working. I am an experienced user of Adobe programs but now I accidentally turn off something. I can't change a form. to scale or rotate... Normally, it is enough to move the cursor to the corner of an image / shape and press ctrl. Thus, it becomes a symbol to rotate, but it no longer works... How to get back my dear regular Illustrator? Please help me.

    chnas,

    It sounds like view > show the rectangle enclosing.

    You can switch between displaying and hiding it by (inadvertently) by pressing Ctrl / command + SHIFT + B.

  • How to make a hollow functions var?

    Can someone explain how to make a hollow functions var?

    Daniel

    Do you mean something like this?

    var itemsearchcount = null;
    
    previewdata();
    nextviewdata();
    
    function previewdata(){
        // do something
        itemsearchcount = 1;
        return itemsearchcount;
        };
    function nextviewdata(){
        // do something more
        alert(itemsearchcount);
        };
    
  • How to make the menu letters more when you use Lightroom 4?

    How to make the menu letters more when you use Lightroom 4?

    Hey Lenovo W510,.

    The police of interface only option in Lightroom of sizing is in the preferences > Interface > panels > Font Size (Small/Large)

    The configuration in grand and then restarting Lightroom will increase the fonts you see in the signs that describe the functions of LR.

    If you're on Mac or Windows you might also decrease your screen/display resolution that will make everything look bigger on your screen.

    Hope this helps,

    Kind regards

    Pete

  • How to optimize PDF files for mobile phones?

    I am wanting to offer a white paper downloadable report on mobile devices, but do not know how to optimize PDF files so that they:

    1. download quickly

    2 are easy to navigate

    3 display correctly without having to enlarge and scroll left and right

    I know it's doable because my HTC Desire came with a few classic, easily installed PDF eBooks on it. Stories like "Dracula" and a "Tale of Two Cities' etc.

    Any help would be appreciated

    Dave has mentioned very good points to optimize the PDF for mobile devices. Its very easy to do using Acrobat. You can read more here: (I don't know the version that you are, then I'll try to include links for Acrobat 9 and X)

    Optimizing PDF (learn how to reduce the size, remove embedding fonts, delete unnecessary data, etc.)

    Acrobat 9

    http://help.Adobe.com/en_US/Acrobat/9.0/Professional/WS58a04a822e3e50102bd615109794195ff-7 c84.w.html

    Acrobat X

    http://help.Adobe.com/en_US/Acrobat/Pro/using/WS58a04a822e3e50102bd615109794195ff-7c88.w.h tml

    In addition to this, here are my recommendations:

    Conversion process:

    To create smaller PDF, I'd say this plan from the beginning. As Dave mentioned - the smaller size PDF, you can select this joboption in the conversion dialog box (if you have the original word etc.which document that you create a PDF from). This will automatically make maximum part of the work for you. So, try to keep the smaller size since the beginning of the PDF creation will not give you a lot of trouble later.

    Images:

    You can also create some small thumnails of images and insert them into the original document before conversion. not resize in the document because it still contains the size of the original. Try to compress or resize them outside the document and then finally insert.

    For example: If the image is 640 x 480 and you want only 50 x 50 in the PDF document. Try to resize using some applications like Adobe Photoshop or MS Office Manager pictures (comes in suite MS Office) or a lot of apps available for free online. then, finally, insert them into the document. If you resize them in the document itself, they will always be containing the size of the original.

    Alongside this, try downsampling images at 72 dpi (using optimization PDF Acrobat) and use images poster rather than the videos. These images can having links pointed out the videos on the website.

    PDF size:

    Try to keep the size PDF between 1-2 MBs.

    Some other links to watch videos, to understand the different characteristics and when and how to use are:

    http://TV.Adobe.com/watch/Acrobat-x-tips-tricks/quick-tip-how-to-compress-a-PDF-file/

    http://TV.Adobe.com/watch/Acrobat-x/how-to-optimize-your-PDF-file/

    http://TV.Adobe.com/watch/Acrobat-tips-and-tricks/optimizing-your-PDF-document/

    Do not hesitate to let us know if you need more information.

    ~ Sandeep V.

  • How to make a components functions or eventhandlers visible from the outside

    Afternoon,

    I created a custom component with some public functions called function1, function2 function3 (no real names) my question is I am willing to do the below

    < custom: Com1 height = "100%" width = "100%" function1 = "{this.someFunction}" / > "

    problem is that the function1 is not visible outside Com1,

    My second question is how do I mark my functions as events, so when you look at intellisense they lightning rather than methods I think that the two are closely linked.

    few things are more my code for all my components is separated from my mxml via setting one actionscript actionscript for the parent class, and the class extends hbox or application. hope this makes sense, I am a vb developer not an actionscripter, which is probably why I'm doing something obviously wrong...

    Thanks in advance for any help

    See you soon

    Tom.

    1. you must tell you all that this component has events

    [Event (name = "showPreview", type = "flash.events.Event")]

    2 dispatches the event when it comes

    private void clickHandler(event:MouseEvent):void

    {

    var eventObject:Event = new Event ("showPreview");

    dispatchEvent (eventObject);

    }

    3 listen to the event from outside the component

    customComponent:Component showPreview = "showPreviewHandler (event)" / > "

    4 handle the event.

    private void showPreviewHandler(event:Event):void

    {

    }

  • How 2 test a db function... ?

    Hello

    How 2 test a db function... ?

    Kind regards

    Abdetu...

    In this case, you could return 0 when all has done very well, return 1 (or the error ORA-) in your exception block.
    That way, your calling program could whether it succeeded or not.

    In addition, you are passing date right now in your function call, but your settings entry is a date data type... you change your data type of input parameter or you change your call as follows:

    exec :vmonths := EMP_ATTENDANCEE_MONA (1009,'01/01/2008' ,'08:00:00','IN');
    

    And if you change the data type of input parameter, then you will not need the TO_DATE function within the service more.

    Nicolas.

  • How can I update my iPhone more than 8.4 of iOS iOS 9.3.5 6?

    How can I update my iPhone more than 8.4 of iOS iOS 9.3.5 6?

    You do not have. You can only upgrade to the current version which is 10.0.2

  • How to recover lost on 6 more contacts

    How to recover lost on 6 more contacts

    Your contacts are synchronized to iCloud-

    If so - then

    Disconnect from the iCloud

    Force restart the device

    Sign again in iCloud - contacts should be pushed to the device

    If you have a backup iTunes made when contacts were present - restoration that will restore your contacts

    Finally if you use Gmail or another email provider - your contacts can be on the web portal of the provider of e-mail under contacts

Maybe you are looking for

  • Changing the IP address

    I recently bought a new iMac, gave my old to my son, it's always on the same network. I downloaded all my data from the old to the new via Time Machine. Should I change IP address on a new or old?

  • Can I enlarge the video "Getting Started." The words are too small.

    Watch the videos on the new version, but it is not full screen and this makes it very difficult to read the words in the video clips. I can zoom in or make full screen?

  • How to change the Apple ID in the ap store

    IN the ap store, there is an identifier Apple that no longer exist.  The IPL for this account will not work. I reset my Apple on my Mac and iPad without any ID, but trying to do the same thing on my iPhone, my new PW does not work and there is no pos

  • I can't export my video because I get errors, please help!

    I use a Macbook Pro. Mac OS X Version 10.8.5 Processor: Intel Core i5 to 2.3 GHz Memory: 4 GB 1333 MHz DDR3 Final Cut Pro X Version 10.0.9 WARNING: I can't move to Mavericks like I have no way to back up my computer. So please don't tell me to level

  • Can connect ATA device wihtout VOIP provider

    Hello I want to connect two devices ATA SPA3102 and PAP2T to different countries by internet wihtout using the VOIP service provider. Appeal to other countries to the PSTN. Help.