Core Animation is so cool!

Discussion in 'iOS Programming' started by Duncan C, Mar 6, 2014.

  1. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #1
    I just posted a new demo project called RandomBlobs to github.

    It creates a couple of different kinds of random, smoothly curved, non self-intersecting shapes.

    It starts out creating a UIBezierPath that is an irregular 8-sided polygon.

    It then uses a modified version of a "Catmull-Rom" curve generating recipe I got from Erica Sadun's "The Core iOS 6 Developer's Cookbook" to turn the polygon into a smoothly curved shape.

    It installs the CGPath from the resulting UIBezierPath into a CAShapeLayer, which draws the path.

    Since all the resulting CGPaths have the same number and type of control points, it was trivial to make the program animate the shape changes, so when you click the "Change shape" button in the app, the shape morphs before your eyes.

    Download the project from github and give it a look.
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    That was a fun little distraction. :)

    I may have to look into that smoothing technique.
     
  3. Duncan C thread starter macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #3
    I just pushed changes that let you loop animated changes to the shape, which makes it even more entertaining to watch. Check it out.
     
  4. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #4
    LOL! The silly things we entertain our selfs with.

    Way cooler now!
     
  5. Duncan C thread starter macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #5
    Do you like the circle-based blobs or square-based blobs better?
     
  6. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #6
    I prefer the circular presentation but think it is good you have the option so one can see the difference.
     
  7. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #7
    Must say I love Core Animation too. I really wish more of my work required it.

    Personal preference, the blob, deffo!

    Thanks for that, it was fun!
     
  8. Duncan C thread starter macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #8
    They're both blobs. You mean the circle-based blobs? The first version used 8 control points for both circle-based blobs and the square-based blobs. I've since updated it to allow a variable number of control points for the circle-based blobs, up to 40, which makes for a much more... "blobbish" shapes.

    There's fodder for several tutorials in that app. Using CAKeyframeAnimation; shifting your view up for the keyboard; using the new UIView keyframe animation, etc.
     
  9. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #9
    I meant the non-circle based blob :
    The more blobby one
    That is just visual personal preference though.
    Having both is super helpful for learning though.
     

Share This Page