Skip to content

Instantly share code, notes, and snippets.

@randrews
randrews / console_fall.lua
Created June 16, 2011 04:50
Console version of Lua puzzle game
function make_board(size)
local board = { size = size }
setmetatable(board, { __tostring = board_tostring })
for n = 0, size * size - 1 do
board[n] = 0
end
return board
@hollance
hollance / gist:2936287
Created June 15, 2012 12:42
Drawing inner glow with Core Graphics
- (CGImageRef)createMaskFromAlphaChannel:(UIImage *)image
{
size_t width = image.size.width;
size_t height = image.size.height;
NSMutableData *data = [NSMutableData dataWithLength:width*height];
CGContextRef context = CGBitmapContextCreate(
[data mutableBytes], width, height, 8, width, NULL, kCGImageAlphaOnly);
@boredzo
boredzo / gist:4604459
Created January 23, 2013 11:04
Two-color angle gradient in Core Image
kernel vec4 coreImageKernel(__color startColor, __color endColor)
{
vec2 point = destCoord();
float angle = atan(point.y, point.x) + radians(180.0);
//Start from the upper middle, not the left middle
angle += radians(90.0);
angle = mod(angle, radians(360.0));
float fraction = angle / radians(360.0);
@mayoff
mayoff / drawArc.m
Created April 7, 2013 22:07
Use Core Graphics to draw an arc with a gradient fill, a stroked outline, and a shadow. http://stackoverflow.com/questions/15866179/draw-segments-from-a-circle-or-donut
static UIImage *imageWithSize(CGSize size) {
static CGFloat const kThickness = 20;
static CGFloat const kLineWidth = 1;
static CGFloat const kShadowWidth = 8;
UIGraphicsBeginImageContextWithOptions(size, NO, 0); {
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextAddArc(gc, size.width / 2, size.height / 2,
(size.width - kThickness - kLineWidth) / 2,
-M_PI / 4, -3 * M_PI / 4, YES);
@JossWhittle
JossWhittle / JOSS BNF Grammar
Last active July 22, 2020 08:09
A BNF Grammar for the JOSS Programming Language. The JOHNNIAC Open Shop System (JOSS) was a programming language developed by the RAND Corporation between 1963-1964 to allow mathematicians and engineers to run simple yet time consuming calculations with little to no knowledge of computers and without access to a computer expert. JOSS was the fir…
--- Strings & Numbers ---
<String> := <Char> | <Char> <String>
<Char> := <Alpha> | <Digit> | <SpecialChar>
<Alpha> := "A..Z" | "a..z"
<SpecialChar> := "." | "," | ";" | ":" | "'" | " " | "#" | "$" | "?"
<Number> := <NumberPart> | <Sign> <NumberPart>
<NumberPart> := <IntPart> | <IntPart> "." <DecimalPart>
<IntPart> := "0" | <NZDigit> | <NZDigit> <DecimalPart>
@mutoo
mutoo / LayerBlur.js
Last active June 21, 2021 21:10
blurred-modal-background-in-cocos2d-js
var LayerBlur = cc.Layer.extend({
ctor: function (blurRadius, maskColor) {
this._super();
// create shader program
var program = cc.GLProgram.create(res.blur_vsh, res.blur_fsh);
program.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
program.addAttribute(cc.ATTRIBUTE_NAME_COLOR, cc.VERTEX_ATTRIB_COLOR);
program.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
program.link();
@stramit
stramit / SpecialEventClass.cs
Last active November 21, 2018 06:36
SpecialEventClass
/*
* When developing the UI system we came across a bunch of things we were not happy
* with with regards to how certain events and calls could be sent in a loosely coupled
* way. We had this requirement because with a UI you tend to implement widgets that receive
* certain events, but you don't really want to have lots of glue code to manage them
* and keep track of them. The eventing interfaces we developed helped with this. One of
* the interesting things, is that they are not justfor the UI system! You can use this as
* a type-safe, fast, and simple alternative to SendMessage (never use SendMessage!).
* So how does it all work?
@nobnak
nobnak / LensShift.cs
Last active July 26, 2022 07:06
Camera Lens Shift func. for Unity
using UnityEngine;
using System.Collections;
namespace Gist {
public static class LensShift {
public static void Frustum(this Camera cam, out float left, out float right, out float bottom, out float top, out float near, out float far) {
near = cam.nearClipPlane;
far = cam.farClipPlane;
@armadsen
armadsen / SceneKitCheatSheet.swift
Created November 2, 2015 01:17
Cheat sheet for SceneKit learning app (Swift)
// Configure the Scene View
self.sceneView.backgroundColor = .darkGrayColor()
// Create the scene
let scene = SCNScene()
///
/// Simple pooling for Unity.
/// Author: Martin "quill18" Glaude (quill18@quill18.com)
/// Extended: Simon "Draugor" Wagner (https://www.twitter.com/Draugor_/)
/// Latest Version: https://gist.github.com/Draugor/00f2a47e5f649945fe4466dea7697024
/// License: CC0 (http://creativecommons.org/publicdomain/zero/1.0/)
/// UPDATES:
/// 2020-07-09: - Fixed a Bug with already inactive members getting Despawned again. thx AndySum (see: https://gist.github.com/Draugor/00f2a47e5f649945fe4466dea7697024#gistcomment-2642441)
/// 2020-06-30: - made the "parent" parameter avaible in the public API to spawn GameObjects as children
/// 2018-01-04: - Added Extension Method for Despawn on GameObjects