This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Displayable { | |
void display(); | |
} | |
interface Moveable extends Displayable { | |
void move(); | |
} | |
abstract class GeoObject implements Moveable { | |
float posX, posY; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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? |