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 / barcode.pde
Last active March 27, 2023 19:46
Barcode generator in Processing
/*
Barcode Generator (EAN-13) by @denkspuren, 2014-08-27, 14:22
Minor update for Processing 3, 2015-11-19, 00:44
New BSD License: http://opensource.org/licenses/BSD-3-Clause
http://en.wikipedia.org/wiki/International_Article_Number_(EAN)
http://de.wikipedia.org/wiki/European_Article_Number
Use: Press number keys to input a sequence of digits or use
right/left arrow for navigation.
@denkspuren
denkspuren / Game2048
Created September 11, 2014 09:48
Game 2048 in Processing
/* Game 2048 by @denkspuren, 2014-09-11, 11:47
New BSD License: http://opensource.org/licenses/BSD-3-Clause
This is an implementation of 2048 without animation effects.
Use arrow keys (left, right, up and down) to move tiles on the
grid. Game ends if the tiles cannot be moved anymore.
For the game and its history see e.g. Wikipedia:
http://en.wikipedia.org/wiki/2048_(video_game)
// http://www.thm.de/site/corporate-design/hausfarben.html
// http://www.farbtabelle.at/farben-umrechnen/
color THMGreen = color(128, 186, 36);
color THMGrey = color(74, 92, 102);
color THMRed = color(184, 0, 64);
float x, y;
int time;
int count = 0;
@denkspuren
denkspuren / drawCircle
Last active August 29, 2015 14:07
Draw Circle according to Horn's Method
// https://de.wikipedia.org/wiki/Rasterung_von_Kreisen#Methode_von_Horn
void drawCircle(int xPos, int yPos, int r) {
int d = -r;
int x = r;
int y = 0;
while (y <= x) {
point(xPos+x,yPos+y); // might be executed in parallel
point(xPos-x,yPos+y);
point(xPos+x,yPos-y);
@denkspuren
denkspuren / CostsLoadingFont
Created October 21, 2014 11:59
Costs of loading a font for use in text()
// textFont(createDefaultFont(12));
println(millis());
text("Hello World!",10,15);
println(millis());
text("Hello again!",10,35);
println(millis());
/*
On my console the output is:
@denkspuren
denkspuren / StopwatchW4314
Last active January 15, 2016 11:47
Stopwatch demonstrating use of millis(), arc() and text()
/* Stopwatch by @denkspuren
Start and Stop by pressing space-bar.
Program requires some startup time to load fonts
used by text().
*/
// http://www.thm.de/site/corporate-design/hausfarben.html
// http://www.farbtabelle.at/farben-umrechnen/
@denkspuren
denkspuren / Snake
Created November 5, 2014 09:27
Snake goes OO
class Position {
int x;
int y;
Position(int x, int y) { // new Position(3,0);
this.x = x;
this.y = y;
}
void display(int radius) {
ellipse(x,y,2*radius,2*radius);
}
@denkspuren
denkspuren / delco.txt
Created November 6, 2014 15:41
Delimited Continuations (call/dc, shift, shift/reset) in Consize
% Implementation of Delimited Continuations in Consize, @denkspuren 2014-11-06
% The words `scan` and `scanWithDefault` are helpers to built implementations
% for `call/dc` and `shift` by means of `call/cc`.
% Note: Word `\` is not treated in a special manner. It is an artefact
% of call/cc. With delimited continuations only, the backslash must be
% superseeded by an equivalent convention such as `\ <word> \`. Here,
% the backslash initiates and marks the end of a sequences of words
% pushed on the datastack without further ado.
@denkspuren
denkspuren / usedelco.txt
Last active August 29, 2015 14:09
A simple parser for parentheses implemented with delimited continuations using Consize
% A simple parser for parentheses implemented with delimited continuations
% using Consize, @denkspuren 2014-11-12 (Update)
%
% The implementation demonstrates parsing of brackets with delimited
% continuations. Since parentheses are already used in Consize,
% left and right parentheses are written as `((` and `))`, respectively.
%
% Take a program such as: `(( @A (( @B (( @C )) @D (( @E )) @F )) @G ))`;
% `@A `up to `@G` denote arbitrary code without any parentheses. As soon as
% word `((` is processed, `shift` starts looking for left and right
@denkspuren
denkspuren / XSlider.pde
Created November 12, 2014 13:15
SliderControl in Processing
color THMGreen = color(128,186,36);
color THMGrey = color(74,92,102);
final float R = 10; // `final` declares R as a constant
class XSlider {
float x_min, x_max; // Slider range to capture mouse
float y_min, y_max; // Slider range to capture mouse
float x, y; // Position of slider