Challenges and Solutions

Jonathan Cardasis edited this page Aug 15, 2016 · 2 revisions

Welcome! Here we have a short writeup on how I completed a few challenges I faced on this project. Enjoy!

Rainbow Track

This one proved to be a bit of a challenge. With no easy way on iOS to have a changing color gradient follow a circle path, so I had to get creative. If a circle with a gradient was so hard to do what's the next best option? Simulate a circle!

In the func drawRainbowCircle(in context: CGContextRef?, outerRadius: CGFloat, innerRadius: CGFloat, resolution: Float) I create a number of squares which are rotated around an origin point to simulate a circle. The max number of squares is 512. The resolution argument specifies a number between 0 and 1 which is multiplied by 512 to determine the number of sub-divisions.

Here's a gif illustrating just how this function works (gray images shown for contrast):

As each sub-divison is created, the hue of the sub-division is slightly changed from the previous division, this will lead to the visual illusion of a gradient effect on a circle. Pretty nifty!

After running multiple tests with XCTest's measureBlock the current implementation was very fast and efficient for generating a high quality (simulated) image.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.