Every now and then, I get the opportunity to work on something really cool. Expansive is one of those apps, especially because of a feature that we initially dismissed as being too difficult to implement.
Expansive is an app that allows users to collaborate with their iPads in real time on virtual whiteboards without limits. Or – as Expansive puts it – limitless ideas.
A simple feature request
”Can you make the canvas infinitely large?”, was one of the first features the client requested. It was also one of the features we almost immediately dismissed. It sounded unpractical, unachievable, and all around too complex for us to spend our time working on it. Or was it?
Enter the wonderful world of math.
While working on the app, the concepts I used were nothing out of the ordinary for a graphics application. We used a number matrix to store the canvas state, and then we used that state to calculate the position of visible elements on the screen. Initially, we settled for a 16,000 x 16,000px canvas size because it seemed like a decently large canvas to work with.
A bit later into development, I decided to push the limits by increasing the canvas size to 100,000 x 100,000px. For some time, that seemed like a good size to work with.
Eventually, I wondered just how big the canvas could actually be. If I made sure to optimize smartly, the infinite canvas, in theory, could be achievable. I put my newly researched concepts into code (a test of faith) and started compiling my application.
The entire thing created a tiny singularity and imploded our office.
Just kidding! It worked surprisingly well. There were a few kinks to iron out, but the concept was sound and I was looking at a nearly infinite canvas.
Let’s crunch some numbers
- A typical iPad screen is 1,024×768 points
- The data type used to store the canvas size is called a float. A float has the size of 3.402823466 * 10^38 or 340,282,346,600,000,000,000,000,000,000,000,000,000
- We get to use this large number twice (for the negative and positive coordinates)
- This means that, starting from the center of the canvas, we can go as far as float in all directions (up, down, left, right)
To put things into perspective
- We can fit 2 * float / 1,024 = 6.6 * 10^35 screens horizontally, stacked next to one another
- If you start swiping from the middle, and can swipe an entire screen in 1 second, it will take you 10.5 octillion (10.5 * 10^27) years to hit the limit, in one direction, and that much again to get back to where you started
For reference, our universe is 13.8 billion years old. That’s 13.8 * 10^9 years.
Pretty neat, right?
Of course, the app itself is far more than just one great feature. Don’t take my word for it and check it out yourself. It’s available on the App Store for iPads.