Programing
I have been teaching myself how to program since the 8th grade when I first started hammering out BASIC programs on my Ti-83+ calculator. Since then my skills as a programmer have advanced concurrently with my skills as an artist on two separate but not entirely divergent paths. I approach both as creative ventures and exercises of the mind, and find that each enhances and compliments the other sometimes in surprising ways.
Today I am comfortable writing in many languages, and just as comfortable picking up new ones. I am familiar with many programming constructs, theories, and patterns and I am always learning new ones. Very few days go by where I do not learn something new about computers.
Below I have pasted some randomly selected code snippets in various languages. I find displaying code in a gallery to be somewhat of an awkward endeavor though, so for more in depth samples please feel free to contact me or have a look at my Github account.
Objective C
- (id)init
{
self = [super init];
if (self) {
srand((unsigned)time(NULL));
self.drinks = [[NSMutableArray alloc] init];
self.quizDrink = [[Drink alloc] init];
self.shelfCorrect = NO;
self.priceCorrect = NO;
self.tfoCorrect = NO;
}
return self;
}
- (id)init
{
self = [super init];
if (self) {
srand((unsigned)time(NULL));
self.drinks = [[NSMutableArray alloc] init];
self.quizDrink = [[Drink alloc] init];
self.shelfCorrect = NO;
self.priceCorrect = NO;
self.tfoCorrect = NO;
}
return self;
}
- (id)init
{
self = [super init];
if (self) {
srand((unsigned)time(NULL));
self.drinks = [[NSMutableArray alloc] init];
self.quizDrink = [[Drink alloc] init];
self.shelfCorrect = NO;
self.priceCorrect = NO;
self.tfoCorrect = NO;
}
return self;
}
Python
from Tkinter import *
class Color():
def __init__(self,master,color):
self.master = master
self.color = color
self.f = Frame(self.master, background=self.color)
self.f.configure(width=50, height=50)
self.f.pack()
mycolors = ['red',
'orange',
'yellow',
'green',
'blue',
'purple'
]
def build():
for color in mycolors:
exec color + ' = Color(root, \'%s\')' % color
build()
Processing
import processing.opengl.*;
import saito.objloader.*;
OBJModel model;
float rotateX;
float rotateY;
void setup() {
size(1280,1060);
//load the model file
//use triangles as the basic geometry
model = new OBJModel(this, "testguy.obj", "relative", TRIANGLES);
model.translateToCenter();
noStroke();
}
void background() {
background(255);
//turn on the lights
lights();
translate(width/2, height/2, 0);
rotateX(rotateY);
rotateY(rotateX);
model.draw();
}
void mouseDragged() {
rotateX += (mouseX - pmouseX) * .01);
rotateY += (mouseX - pmouseY) * .01);
}
Javascript
#pragma strict
//This file is intended to be an outline for subclassing
//Common functions are outlined here to be overwritten in subclasses
var canMove : boolean = true;
var canMoveHorizontal : boolean = true;
var canMoveVertical : boolean = true;
var currentBlock : String = "Floor";
enum Facing {Up = 0, Right = 90, Down = 180, Left = 270};
var currentDirection : Facing;
//Tile Specific interactions
//These get called through the OnTriggerEnter function of the triggered tile
function Fire() {
//Enter code to deal with Fire here
Kill();
}
function Water() {
//Enter code to deal with Water here
Kill();
}
function Conveyer() {
//Enter code to deal with Conveyer Floors here
}
function Ice() {
//Enter code to deal with Ice here
}
function IceCorner() {
//Enter code to deal with Ice Corners here
}
function Monster() {
//Enter code to deal with Monsters here
}
//These functions are typically called internally and
//manipulate the gameObject in some manner
function DisallowMove() {
//Stops ability to move
canMove = false;
}
function AllowMove() {
//Starts ability to move
canMove = true;
}
function UpdateCurrentBlock() {
//Detects the name of the first block found up to one block beneath gameObject
var ray : Ray = new Ray (transform.position,transform.TransformDirection(Vector3.down));
var hit : RaycastHit;
if (Physics.Raycast(ray,hit,2)) {
currentBlock = hit.collider.name;
}
}
function UpdateRestrictions() {
switch (currentBlock) {
case "Water":
canMove = false;
break;
case "Fire":
canMove = false;
break;
case "Ice":
canMove = false;
break;
case "Ice Corner":
canMove = false;
break;
case "Conveyer":
//need to update this to canMovePerpendicular somehow
canMove = false;
break;
case "Floor":
canMove = true;
break;
default:
canMove = true;
break;
}
}
function UpdateDirection () {
//Turns keypress into rotation currentDirection
//Moves forward if clear ahead
if (Input.anyKeyDown) {
if (canMoveVertical) {
if (Input.GetAxisRaw("Vertical") > 0)
KeyMove(Facing.Up);
if (Input.GetAxisRaw("Vertical") < 0)
KeyMove(Facing.Down);
}
if (canMoveHorizontal) {
if (Input.GetAxisRaw("Horizontal") > 0)
KeyMove(Facing.Right);
if (Input.GetAxisRaw("Horizontal") < 0)
KeyMove(Facing.Left);
}
}
}
function Move() {
//Moves object forward one block
if (canMove) {
transform.Translate(Vector3.forward * 2);
}
}
function KeyMove(dir : Facing) {
//Movement induced by key press
transform.eulerAngles.y = parseInt(dir);
currentDirection = dir;
Invoke("CheckAhead", .1);
Invoke("Move", .1);
}
function CheckAhead() {
//Sends a ray one block in front of gameObject
//if object in the way is tagged as impassible Activate() sent to object and second ray sent
//if object still in way prevents movement in that currentDirection
var ray : Ray = new Ray (transform.position,transform.TransformDirection (Vector3.forward));
var hit : RaycastHit;
if (Physics.Raycast(ray,hit,2)) {
hit.transform.gameObject.SendMessage("Activate",SendMessageOptions.DontRequireReceiver);
Physics.Raycast(ray,hit,2);
//either change the method for detecting immovable objects or further exand tagging system
//i dont like this solution right now...
if (hit.collider != null && hit.collider.tag == "Impassible") {
DisallowMove();
return false;
}
}
AllowMove();
return true;
}
function Kill() {
//Destroys current object
DisallowMove();
Hide();
Destroy(gameObject,5);
}
function Hide() {
//Draws object below floor - useful when sound needs to play on object destruction
//or object needs to complete some action before it is destroyed
transform.Translate(0,-100,0);
}
C#
using UnityEngine;
using System.Collections;
public class StartMenu : MonoBehaviour {
public Texture2D buttonTexture, windowTexture, bgTexture;
public Texture2D startImg, tutorialImg, optionsImg, creditsImg;
private float bWidth = 250;
private float bHeight = 75;
private bool showStartMenu = true;
private Rect startMenuRect,buttonRect;
public GUIStyle startStyle, titleStyle, shaddowTitleStyle, buttonStyle, buttonTextStyle, buttonTextShaddowStyle;
// Use this for initialization
void Start () {
startMenuRect = new Rect(0,0,Screen.width,Screen.height);
//GameManager.LevelStart += LevelStart;
//GameManager.GameStart += StartGame;
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
if (showStartMenu) {
GUI.Box(startMenuRect,bgTexture);
startMenuRect = GUI.Window(0,startMenuRect, StartWindow, windowTexture,startStyle);
}
}
private void StartWindow(int windowID) {
GUI.Label(new Rect(155,10,350,70),"Flamboyant",shaddowTitleStyle);
GUI.Label(new Rect(165,95,350,70),"Battle Boy",shaddowTitleStyle);
GUI.Label(new Rect(150,5,350,70),"Flamboyant",titleStyle);
GUI.Label(new Rect(160,90,350,70),"Battle Boy",titleStyle);
if (GUI.Button(new Rect(250, 215, bWidth, bHeight), "", buttonStyle)) {
StartClicked();
}
GUI.Label(new Rect(326,209,bWidth,bHeight),"Start",buttonTextShaddowStyle);
GUI.Label(new Rect(321,204,bWidth,bHeight),"Start",buttonTextStyle);
if (GUI.Button(new Rect(250, 300, bWidth, bHeight), "", buttonStyle)) {
TutorialClicked ();
}
GUI.Label(new Rect(281,295,bWidth,bHeight),"Tutorial",buttonTextShaddowStyle);
GUI.Label(new Rect(276,290,bWidth,bHeight),"Tutorial",buttonTextStyle);
if (GUI.Button(new Rect(250, 385, bWidth, bHeight), "", buttonStyle)) {
CreditsClicked();
}
GUI.Label(new Rect(296,385,bWidth,bHeight),"Credits",buttonTextShaddowStyle);
GUI.Label(new Rect(291,380,bWidth,bHeight),"Credits",buttonTextStyle);
if (GUI.Button(new Rect(250, 470, bWidth, bHeight), "", buttonStyle)) {
QuitClicked();
}
GUI.Label(new Rect(346,465,bWidth,bHeight),"Quit",buttonTextShaddowStyle);
GUI.Label(new Rect(341,460,bWidth,bHeight),"Quit",buttonTextStyle);
}
private void StartClicked() {
//Start Level
GameManager.TriggerLevelStart();
}
private void QuitClicked() {
//Quit Game
Application.Quit();
}
private void CreditsClicked() {
//Start Credits
GameManager.TriggerCreditsStart();
}
private void TutorialClicked() {
//Start Credits
GameManager.TriggerTutorialStart();
}
}
SML
fun is_older (day1 : (int * int * int) , day2 : (int * int * int)) =
let val year_comp = #1 day1 < #1 day2
val year_eq = #1 day1 = #1 day2
val mo_comp = #2 day1 < #2 day2
val mo_eq = #2 day1 = #2 day2
val day_comp = #3 day1 < #3 day2
in
year_comp orelse (year_eq andalso mo_comp orelse (mo_eq andalso day_comp))
end
fun number_in_month (dates : (int * int * int) list, month : int) =
if null dates
then 0
else
if #2 (hd dates) = month
then 1 + number_in_month(tl dates, month)
else number_in_month(tl dates, month)
fun number_in_months (dates : (int * int * int) list, months : int list) =
if null months
then 0
else number_in_month(dates, hd months) + number_in_months(dates, tl months)
fun dates_in_month (dates : (int * int * int) list, month : int) =
if null dates
then []
else
if #2 (hd dates) = month
then hd dates :: dates_in_month(tl dates, month)
else dates_in_month(tl dates, month)
fun dates_in_months (dates : (int * int * int) list, months : int list) =
if null months
then []
else dates_in_months(dates, tl months) @ dates_in_month(dates, hd months)
fun get_nth (words : string list, pos : int) =
if pos = 1
then hd words
else get_nth(tl words, pos-1)
fun date_to_string (date : (int * int * int)) =
let val months = ["January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December "]
in
get_nth(months, #2 date) ^ Int.toString(#3 date) ^ ", " ^ Int.toString(#1 date)
end
fun number_before_reaching_sum (sum : int, nums : int list) =
if sum - hd nums > 0
then 1 + number_before_reaching_sum((sum - hd nums), tl nums)
else 0
fun what_month (day : int) =
let val month_lookup = [31,28,31,30,31,30,31,31,30,31,30,31];
in 1 + number_before_reaching_sum (day, month_lookup)
end
fun month_range (day1 : int, day2 : int) =
if day1 > day2
then []
else what_month(day1) :: month_range(day1+1, day2)
fun oldest (dates : (int * int * int) list) =
if null dates
then NONE
else
let
val day1 = hd dates
val day2 = oldest(tl dates)
in if day2 = NONE orelse is_older(day1, (valOf day2))
then SOME day1
else day2
end
fun remove_duplicates (nums: int list) =
if null nums
then []
else
let
val new_list = remove_duplicates(tl nums)
in
let
fun num_in_list (test : int, nums : int list) =
if null nums
then NONE
else
if test = hd nums
then SOME true
else num_in_list(test, tl nums)
in
if isSome (num_in_list(hd nums, tl nums))
then new_list
else hd nums :: new_list
end
end
fun number_in_months_challenge (dates : (int * int * int) list, months : int list) =
number_in_months(dates, remove_duplicates(months))
fun dates_in_months_challenge (dates : (int * int * int) list, months : int list) =
dates_in_months(dates, remove_duplicates(months))
fun get_nth_int (nums : int list, pos : int) =
if pos = 1
then hd nums
else get_nth_int(tl nums, pos-1)
fun reasonable_date (date : (int * int * int)) =
let
val month_lookup = [31,28,31,30,31,30,31,31,30,31,30,31];
val year = #1 date
val month = #2 date
val day = #3 date
in
let
val good_year = year >= 1
val good_month = month >= 1 andalso month <= 12
in
if good_year andalso good_month
then
if month <> 2
then day >= 1 andalso day <= get_nth_int(month_lookup,month)
else
if (year mod 400 = 0) orelse ((year mod 4 = 0) andalso (year mod 100 <> 0))
then day >= 1 andalso day <= 29
else day >= 1 andalso day <= 28
else
false
end
end
Racket
#lang racket
(provide (all-defined-out))
(define (sequence low high stride)
(if (> low high)
null
(cons low (sequence (+ low stride) high stride))))
(define (string-append-map xs suffix)
(map (lambda (str) (string-append str suffix)) xs))
(define (list-nth-mod xs n)
(cond [(< n 0) (error "list-nth-mod: negative number")]
[(null? xs) (error "list-nth-mod: empty list")]
[#t (car (list-tail xs (remainder (length xs) n)))]))
(define (stream-for-n-steps s n)
(if (= n 0)
null
(cons (car (s)) (stream-for-n-steps (cdr (s)) (- n 1)))))
(define funny-number-stream
(letrec ([f (lambda (x) (cons (if (= (remainder x 5) 0)
(* x -1)
x) (lambda () (f (+ x 1)))))])
(lambda () (f 1))))
(define ones (lambda () (cons 1 ones)))
Lua
local args = {...}
quarrySize = tonumber(args[1])
os.loadAPI("move")
os.loadAPI("build")
os.loadAPI("mine")
local coal = 1
local torh = 2
local cobblePipe = 3
local obPipe = 4
local chest = 5
local woodPipe = 6
function constructPipes()
move.turnLeft()
move.back()
placeItem(cobblePipe)
move.down()
placeItem(obPipe)
move.back()
end
function replacePipes()
move.forward()
turtle.dig()
placeItem(cobblePipe)
end
function addTorches()
move.turnLeft()
build.placeItem(torch)
end
function nextLevel()
move.turnLeft(2)
end
function startQuarry()
move.turnLeft(2)
shell.run(go, 3)
print("setting up quarry...")
print("placing chests...")
build.placeItem(chest)
move.back()
build.placeItem(chest)
move.back()
print("placing woodenpipe...")
build.placeItem(woodPipe)
move.back()
print("placing cobblestone pipe...")
build.placeItem(cobblePipe)
print("finishing collection infrastructure...")
move.turnLeft(2)
end
function makeQuarry()
level = 0
moreToMine = true
startQuarry()
while moreToMine do
mine.digSquare(quarrySize)
mine.returnHome(quarrySize)
addTorches()
constructPipes()
build.dumpLoad(5,16)
replacePipes()
moreToMine = nextLevel()
level = level + 1
end
print("Quarry complete.")
end