Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am jamiegilmartin on github.
* I am jamiegilmartin (https://keybase.io/jamiegilmartin) on keybase.
* I have a public key ASD_BeSps-SN3-y42UN1jFwIhbXWpfjsnTFCKWkiRL_eFQo
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am jamiegilmartin on github.
* I am jamiegilmartin (https://keybase.io/jamiegilmartin) on keybase.
* I have a public key ASD_BeSps-SN3-y42UN1jFwIhbXWpfjsnTFCKWkiRL_eFQo
To claim this, I am signing this object:
@jamiegilmartin
jamiegilmartin / NSImage+Mat.mm
Last active October 11, 2018 21:25
NSImage From Mat & Mat From NSImage || Mat to NSImage & NSImage to Mat 🙃
//@see https://stackoverflow.com/questions/8563356/nsimage-to-cvmat-and-vice-versa
Mat matFromNSImage(NSImage* image) {
//https://stackoverflow.com/a/2548861/1308629
CGImageSourceRef source;
source = CGImageSourceCreateWithData((CFDataRef)[image TIFFRepresentation], NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
//https://gist.github.com/dominiklessel/1716068
//CGImageRef imageRef = cgImage;
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
CGFloat cols = image.size.width;
@jamiegilmartin
jamiegilmartin / bp3.1.swift
Last active February 22, 2018 19:54
Lerp
override func update(deltaTime seconds: TimeInterval) {
super.update(deltaTime: seconds)
let lerpRate = 0.5 // or some normalized percentage
x += (Target — x) * lerpRate
myNode.position.x = x
}
@jamiegilmartin
jamiegilmartin / bp2.4.swift
Last active February 22, 2018 19:54
CGMutablePath
let path = CGMutablePath()
path.move(to: p1 )
path.addLine(to: p2 )
let node = SKShapeNode(path: path)
node.name = name
node.zPosition = 0
parentNode.addChild(node)
@jamiegilmartin
jamiegilmartin / bp2.3.swift
Last active February 22, 2018 19:54
SKColor
SKColor(red: 255, green: 0, blue: 255, alpha: 0.7)
@jamiegilmartin
jamiegilmartin / bp2.1.swift
Last active February 22, 2018 19:53
CGPoint
let p1 = CGPoint(x: 0, y: 0)
@jamiegilmartin
jamiegilmartin / bp2.2.swift
Last active February 22, 2018 19:53
SKShapeNode
let node = SKShapeNode(circleOfRadius: radius)
node.position = p1
node.glowWidth = 1.0
node.strokeColor = .white
node.lineWidth = 2
node.fillColor = .clear
node.alpha = 0.5