Skip to content

Instantly share code, notes, and snippets.

View madebyjeffrey's full-sized avatar

Jeffrey Drake madebyjeffrey

View GitHub Profile
/*
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 {
// 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];
@madebyjeffrey
madebyjeffrey / NSColor+CGColor
Created November 16, 2010 06:30
CGColor property for NSColor
// 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];
@madebyjeffrey
madebyjeffrey / CABasicAnimation
Created November 16, 2010 20:31
Adapting an example, doesn't work fully yet
- (void) present
{
CABasicAnimation *a;
a = [CABasicAnimation animationWithKeyPath: @"transform.scale"];
a.duration = 6;
a.repeatCount = 0;
a.autoreverses = NO;
a.fromValue = [NSNumber numberWithFloat: 0];
@madebyjeffrey
madebyjeffrey / CALayer Animation
Created December 25, 2010 17:56
Animated ZoomBlur
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]];
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.
@madebyjeffrey
madebyjeffrey / pyglet3
Created February 22, 2011 00:49
displays a mesh
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
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)
Take:
1 2 3
4 5 6
7 8 9
Turn Into:
0 0 0 0 0
program euler002
implicit none
integer :: i = 0
integer :: f = 0
integer :: s = 0
do
i = i + 1
f = fib(i)