Skip to content

Instantly share code, notes, and snippets.

View craigmjohnston's full-sized avatar
👍

Craig Johnston craigmjohnston

👍
View GitHub Profile
@craigmjohnston
craigmjohnston / drawblock.py
Last active December 13, 2015 17:39
Draws a pretty block using pygame's draw functions. Written up for this tutorial: http://superbase.tumblr.com/post/43037844981/presenting-pretty-blocks-programmatically-in-python
import pygame
import sys
def lightened(colour, amount):
newcolour = pygame.Color(colour.r, colour.g, colour.b, colour.a)
h, s, l, a = newcolour.hsla
if l+amount > 100: l = 100
elif l+amount < 0: l = 0
else: l += amount
newcolour.hsla = (h, s, l, a)
@craigmjohnston
craigmjohnston / MultiplicativeTextureMask.shader
Created October 27, 2013 08:13
Slight modification to the Texture Mask shader on the Unity3D wiki (http://wiki.unity3d.com/index.php?title=Texture_Mask). It multiplies the main texture's alpha channel with the mask's, so it preserves any transparency your main texture has.
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
@craigmjohnston
craigmjohnston / VisualiseMeshNormals.cs
Last active August 29, 2015 14:05
A little script that draws the direction of mesh normals into the scene window in Unity3D, and also draws little number labels for each of the mesh's vertices. Just add the component to the object containing the mesh. Works with MeshFilter and MeshCollider meshes.
using UnityEditor;
using UnityEngine;
public class VisualiseMeshNormals : MonoBehaviour {
public enum MeshType { Filter, Collider }
public MeshType meshType = MeshType.Filter;
protected MeshFilter meshFilter;
protected MeshCollider meshCollider;
@craigmjohnston
craigmjohnston / Mathfx.cs
Created December 10, 2014 17:28
Extra maths stuff for Unity - taken from http://wiki.unity3d.com/index.php?title=Mathfx
using UnityEngine;
using System;
public class Mathfx
{
public static float Hermite(float start, float end, float value)
{
return Mathf.Lerp(start, end, value * value * (3.0f - 2.0f * value));
}
@craigmjohnston
craigmjohnston / .gitignore
Last active August 29, 2015 14:18
Gamejam .gitignore file for Unity projects. Ignores all of the usual disposable Unity files, as well as a Assets/Libraries folder that holds any 3rd party libraries.
# Unity
*.unityproj
[Oo]bj/
[Tt]emp/
[Ll]ibrary/
[Bb]uild/
# OSX
.DS_Store*
._*
@craigmjohnston
craigmjohnston / qwerty_nearbykeys_alphanum
Created May 21, 2015 12:25
A mapping of the alphanumeric keys on a QWERTY keyboard to all adjacent alphanumeric keys. Intended for use in generating possible typos.
'1': ['q', '2'],
'2': ['1', 'q', 'w', '3'],
'3': ['2', 'w', 'e', '4'],
'4': ['3', 'e', 'r', '5'],
'5': ['4', 'r', 't', '6'],
'6': ['5', 't', 'y', '7'],
'7': ['6', 'y', 'u', '8'],
'8': ['7', 'u', 'i', '9'],
'9': ['8', 'i', 'o', '0'],
'0': ['9', 'o', 'p'],
///
/// Simple pooling for Unity.
/// Author: Martin "quill18" Glaude (quill18@quill18.com)
/// Latest Version: https://gist.github.com/quill18/5a7cfffae68892621267
/// License: CC0 (http://creativecommons.org/publicdomain/zero/1.0/)
/// UPDATES:
/// 2015-04-16: Changed Pool to use a Stack generic.
///
/// Usage:
///
@craigmjohnston
craigmjohnston / Build.cs
Created April 1, 2016 15:07
A Unity3d editor script used to perform generic builds from the command line.
using System;
using System.Collections.Generic;
using UnityEditor;
public class Build {
static string[] SCENES = FindEnabledEditorScenes();
static void PerformBuild() {
GenericBuild(
SCENES,
@craigmjohnston
craigmjohnston / SpotifySaveToMusic.ahk
Last active June 5, 2017 21:51
AutoHotkey script for saving current song to your music. Moves to Spotify, rightclicks the currently playing song's title, checks the pixel colour of a certain position to find out the size of the context menu (it's wider if you've already added the song) and then saves it if it isn't already and moves back to what you were doing before.
/*
Spotify "Save to Music"
Based on: http://superuser.com/a/879589
Fires on Ctrl+Shift+L, but obviously you can change that to whatever you want.
*/
^+l::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.
@craigmjohnston
craigmjohnston / MusicControls.ahk
Created May 26, 2016 14:07
AutoHotkey script for media controls, including the SpotifySaveToMusic script snippet.
/*
Spotify "Save to Music"
Based on: http://superuser.com/a/879589
Fires on Ctrl+Shift+L, but obviously you can change that to whatever you want.
*/
^+l::
spotify = ahk_class SpotifyMainWindow
IfWinExist, %spotify%
{
;Store active window and mouse position.