Skip to content

Instantly share code, notes, and snippets.

Texture2D[] layers;
Texture2D compiledTexture = new Texture2D(layers[0].width, layers[0].height);
foreach(Texture2D layer in layers){
Color[] baseColors = compiledTexture.GetPixels();
Color[] layerColors = layer.GetPixels();
for(int p = 0; p < baseColors.Length; p++){
/***********************************************
* Copyright ? Far-Flung Creations Ltd.
* Author: Marius George
* Date: 25 October 2017
* Email: marius@farflunggames.com
* DISCLAIMER: THE SOURCE CODE IN THIS FILE IS PROVIDED ?AS IS? AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FAR-FLUNG CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) SUSTAINED BY YOU OR A THIRD
///
/// 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
@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()
@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;
@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?
@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();
@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>
@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);
@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);