Skip to content

Instantly share code, notes, and snippets.

View madebyjeffrey's full-sized avatar

Jeffrey Drake madebyjeffrey

View GitHub Profile
@madebyjeffrey
madebyjeffrey / pie.bas
Created June 4, 2011 03:08
Pie Slices
DECLARE FUNCTION atan2! (y AS DOUBLE, x AS DOUBLE)
DECLARE SUB PieSlice2 (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, ro AS SINGLE, ri AS SINGLE)
DECLARE SUB PieSlice (theta1 AS SINGLE, theta2 AS SINGLE, x AS SINGLE, y AS SINGLE, orad AS SINGLE, irad AS SINGLE)
' for PieSlice2
CONST sep = 10
DEF fnphi (x!, ri!) = ATN(x! / (2 * ri))
DEF fnAx (theta!, ri!) = ri! * COS(theta! + fnphi(sep, ri!))
DEF fnAy (theta!, ri!) = ri! * SIN(theta! + fnphi(sep, ri!))
DEF fnBx (theta!, ri!) = ri! * COS(theta! - fnphi(sep, ri!))
+ pieSliceWithCentre: (CGPoint) c innerRadius: (double) ir outerRadius: (double) or
startAngle: (double) theta1 endAngle: (double) theta2 {
UIBezierPath *path = [UIBezierPath bezierPath];
if (path) {
[path moveToPoint: CGPointMake(cos(theta1)*ir, sin(theta1)*or)];
[path addLineToPoint: CGPointMake(cos(theta1)*or, sin(theta1)*or)];
[path addArcWithCenter: CGPointZero radius: or startAngle: theta1 endAngle: theta2 clockwise: NO];
[path addLineToPoint: CGPointMake(cos(theta2)*ir, sin(theta2)*ir)];
[path addArcWithCenter: CGPointZero radius: ir startAngle: theta2 endAngle:theta1 clockwise: NO];
@madebyjeffrey
madebyjeffrey / PDF Draw.m
Created May 30, 2011 19:56
Drawing a PDF
- (void) awakeFromNib {
self.opaque = YES;
self.clearsContextBeforeDrawing = YES;
[self setNeedsDisplay];
NSBundle *main = [NSBundle mainBundle];
// Open PDF
CGPDFDocumentRef doc = CGPDFDocumentCreateWithURL((CFURLRef)[main URLForResource: @"NC.pdf" withExtension: nil]);
if (doc == NULL)
@madebyjeffrey
madebyjeffrey / gist:980971
Created May 19, 2011 15:08
Printf FileHandle
@implementation NSFileHandle (print)
- (void) printf: (NSString*) format, ...
{
NSString *output;
va_list ap;
va_start(ap, format);
program euler002
implicit none
integer :: i = 0
integer :: f = 0
integer :: s = 0
do
i = i + 1
f = fib(i)
Take:
1 2 3
4 5 6
7 8 9
Turn Into:
0 0 0 0 0
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)
@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
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 / 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]];