Skip to content

Instantly share code, notes, and snippets.

View denkspuren's full-sized avatar
💭
Getting thinking done!

Dominikus Herzberg denkspuren

💭
Getting thinking done!
View GitHub Profile
@denkspuren
denkspuren / FunctionViewerSimple.pde
Created November 19, 2014 14:24
FunctionViewer displays a function object at specified coordinates in window
class Function {
float calc(float x) {
float y = sin(x);
return y;
}
}
class FunctionViewer {
Function function;
float xPos_min, xPos_max, yPos_min, yPos_max;
@denkspuren
denkspuren / mymap.pde
Created November 23, 2014 12:31
Reimplementation of function 'map' in Processing
float mymap(float x1, float from1, float to1, float from2, float to2) {
// formula: (x1-from1)/(to1-from1) = (x2-from2)/(to2-from2)
// <=> x2 = (x1-from1)/(to1-from1)*(to2-from2)+from2;
return (x1-from1)/(to1-from1)*(to2-from2)+from2;
}
void setup() {
println(map(3.4,0.1,12.7,-11.3,4.3),mymap(3.4,0.1,12.7,-11.3,4.3));
}
@denkspuren
denkspuren / BirdsBalloons.pde
Created November 28, 2014 14:06
A tiny game with a bird and balloons
class Bird {
float w, h;
float x, y;
Bird(float x, float y, float w, float h) {
this.x = x; this.y = y; this.w = w; this.h = h;
}
void move(float vx) {
x -= vx;
}
boolean visible() {
@denkspuren
denkspuren / BirdsBalloonsInheritance.pde
Created November 29, 2014 12:16
Bird and Balloons with Inheritance
class FlyingObject {
float w, h;
float x, y;
FlyingObject(float x, float y, float w, float h) {
this.x = x; this.y = y; this.w = w; this.h = h;
}
void display() {
ellipse(x,y,w,h);
}
}
@denkspuren
denkspuren / GameOfLife.pde
Created December 3, 2014 12:29
Conway's Game of Live in Processing
class Universe {
int[][] grid;
int xSize, ySize; // try an implementation without these vars
Universe(int xSize, int ySize) {
this.xSize = xSize; this.ySize = ySize;
grid = new int[ySize+2][xSize+2]; // include invisible borders
}
void toggleCell(int x, int y) {
@denkspuren
denkspuren / KochSnowflake.pde
Created December 10, 2014 08:50
An recursive implementation of the Koch snowflake
// https://de.wikipedia.org/wiki/Koch-Kurve
// https://en.wikipedia.org/wiki/Koch_snowflake
class Pen {
float x,y;
float angle;
boolean down = true;
Pen(float x, float y, float angle) {
this.x = x; this.y = y; this.angle = -angle;
@denkspuren
denkspuren / Thing.pde
Created December 17, 2014 12:17
Code demonstrating object management, use of assert, ArrayList<>, for(each)
static class Thing {
static private ArrayList<Thing> inventory = new ArrayList<Thing>();
static private IntList codes = new IntList();
private int code;
private float price = Float.NaN;
Thing(int code) {
assert !Thing.codes.hasValue(code);
this.code = code;
Thing.codes.append(code);
Thing.inventory.add(this);
@denkspuren
denkspuren / primes.pde
Created January 13, 2015 22:17
Calculating primes
// inspired by http://yoyo.cc.monash.edu.au/~bunyip/primes/2dPrimes.htm
// calculation of primes can be optimzed
int x=0;
int y=0;
class Primes {
IntList primes = new IntList();
int number = 1;
@denkspuren
denkspuren / polymorphism.pde
Created January 21, 2015 13:33
Polymorphism
interface Displayable {
void display();
}
interface Moveable extends Displayable {
void move();
}
abstract class GeoObject implements Moveable {
float posX, posY;
@denkspuren
denkspuren / maybe-monad.txt
Created September 8, 2015 11:58
Maybe monad in Consize
% Implementation of the Maybe Monad in Consize
% The implementation refers to
% https://en.wikipedia.org/wiki/Monad_(functional_programming)#The_Maybe_monad
% The datatype Maybe is informally defined as
% t Maybe = [ t Just ] | Nothing
: bind ( Maybe quot -- Maybe ) % ( [a] ma ([a] a -- [a'] mb) [a'] mb )
over \ Nothing equal?