This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This code present a way to implement textView:doCommandBySelector, as sent by an NSTextView to its delegate, and implement the method as - (BOOL) method: (NSTextView*)aTextView and avoid the need for if statement chaining. | |
*/ | |
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector { | |
if ([self respondsToSelector: aSelector]) { | |
BOOL (*method)(id, SEL, NSTextView*); | |
method = (BOOL (*)(id, SEL, NSTextView*))[self methodForSelector: aSelector]; | |
return method(self, aSelector, aTextView); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The Controller: | |
// The controller is created: | |
viewDidLoad: | |
CGRect starsize = CGRectMake(0, 0, 2048, 2048); | |
self.starmap.scrollView.bounds = starsize; | |
self.starmap.frame = starsize; | |
[self.starmap setNeedsDisplay]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Version 3: Simplified, but still can have an exception thrown in the case of a non-floating point colour space. | |
@implementation NSColor (CGColor) | |
@dynamic CGColor; | |
- (CGColorRef) CGColor | |
{ | |
CGColorSpaceRef colorspace = [[self colorSpace] CGColorSpace]; | |
const NSInteger nComponents = [self numberOfComponents]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) present | |
{ | |
CABasicAnimation *a; | |
a = [CABasicAnimation animationWithKeyPath: @"transform.scale"]; | |
a.duration = 6; | |
a.repeatCount = 0; | |
a.autoreverses = NO; | |
a.fromValue = [NSNumber numberWithFloat: 0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CIFilter *filter = [CIFilter filterWithName: @"CIZoomBlur"]; | |
[filter setDefaults]; | |
[filter setValue: [CIVector vectorWithX: self.title.bounds.size.width / 2 | |
Y: self.title.bounds.size.height / 2] | |
forKey: @"inputCenter"]; | |
[filter setValue: [NSNumber numberWithFloat: 0.0] | |
forKey: @"inputAmount"]; | |
// [filter setValue: [NSNumber numberWithFloat: 90.0] forKey: @"inputAngle"]; | |
[filter setName: @"zoomBlur"]; | |
[self.title setFilters: [NSArray arrayWithObject: filter]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CIAdditionCompositing - Adds color components to achieve a brightening effect. This filter is typically used to add highlights and lens flare effects. | |
CIAffineClamp - Performs an affine transform on a source image and then clamps the pixels at the edge of the transformed image, extending them outwards. This filter performs similarly to the CIAffineTransform filter except that it produces an image with infinite extent. You can use this filter when you need to blur an image but you want to avoid a soft, black fringe along the edges. | |
CIAffineTile - Applies an affine transform to an image and then tiles the transformed image. | |
CIAffineTransform - Applies an affine transform to an image. You can scale, translate, or rotate the input image. You can also apply a combination of these operations. | |
CIAreaAverage - Calculates the average color for the specified area in an image, returning the result in a pixel. | |
CIAreaHistogram - Calculates a histogram for the specified area in an image, returning the result in a 1D image. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from pyglet import clock, font, image, window, text | |
from pyglet.gl import * | |
import numpy | |
SIZE = 64 | |
TWO_PI = 2.0 * 3.1415926535 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class World(object): | |
def __init__(self): | |
self.verts_id = GLuint() | |
glGenBuffers(1, self.verts_id) | |
self.mesh = [] | |
for x in xrange(SIZE): | |
for z in xrange(SIZE): | |
self.mesh.extend((float(SIZE//2 - x), 0.0, float(SIZE//2 - z))) | |
data = (GLfloat*len(self.mesh))(*self.mesh) | |
glBindBuffer(GL_ARRAY_BUFFER, self.verts_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Take: | |
1 2 3 | |
4 5 6 | |
7 8 9 | |
Turn Into: | |
0 0 0 0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program euler002 | |
implicit none | |
integer :: i = 0 | |
integer :: f = 0 | |
integer :: s = 0 | |
do | |
i = i + 1 | |
f = fib(i) |
OlderNewer