Ran across this just now and found the comment by Pavol more interesting than curried functions. Yes Pavol! Totally. This is going to be a recurring problem for a lot of imperative programmers beginning to enter the world of functional programming through Swift. ‘Functional first’ is something I have to continually remind myself of. The original (imperative) gist went something like this:
Pavol advocates a more functional approach, without the “minutiae” of loops and temp vars:
Can we continue that train of functional thought? What if we move the separator up the chain, eliminating the function call:
That was an interim step to see if it worked. Now lets wrap it up and bring back that append function, allowing us to pass any separator:
Lastly, to make it even more compact, we can remove some syntax noise in the call to reduce:
In the process of trying to get an OpenGL snapshot working, I got this, which I thought was quite beautiful.
Starting to explore textured brushes in my drawing app. First attempt:
Wait for it…then click the video to start.
Grab the Box2D folder and drag it into your Xcode project.
Make sure copy items and the correct target are both checked.
In the project build settings, filter by “user”.
Under ‘User Header Search Paths’ add a . for the current directory and select recursive.
Set ‘Always Search User Paths’ to YES.
For the given source file, you need to change the extension to *.mm
Doing so, changes the default type to Objective-C++.
Finally, import Box2D and begin your journey.
Sample output from an iOS drawing app I’ve been working on:
simpl started as a Unity prototype before it became a minimalist endeavour.
Playing around with a fluid solver I ported to iOS:
Screenshot of a Flex/Flash drawing app I worked on until it reached beta:
Some of the resulting images you can create using the above tool:
I’ve stopped working on it, primarily because of the uncertainty surrounding the future of Flash. Source code available here.
It’s hard to find an example using CGDataProviderCreateDirect, so here’s a quick snippet:
static unsigned int* data; // used for manipulating pixel data directly
const void * getBytePointerCallback(void *info)
callbacks.version = 0;
callbacks.getBytePointer = getBytePointerCallback;
callbacks.releaseBytePointer = NULL;
callbacks.getBytesAtPosition = NULL;
callbacks.releaseInfo = NULL;
float w = self.layer.frame.size.width;
float h = self.layer.frame.size.height;
w *= [UIScreen mainScreen].scale;
h *= [UIScreen mainScreen].scale;
int numComponents = 4;
uint dataLength = w * h * numComponents;
data = malloc(dataLength * sizeof(uint)); // TODO: free
uint r = 255;
uint g = 0;
uint b = 0;
for(int i = 0; i < dataLength; ++i)
data[i] = 255 << 24 | b << 16 | g << 8 | r;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGDataProviderRef bitmapProvider = CGDataProviderCreateDirect(data,dataLength,&callbacks);
CGImageRef bitmap = CGImageCreate(w,
8, // bits per component
8*numComponents, // total bits
w*numComponents, // bytes per row
self.layer.contents = (__bridge id)(bitmap);