Skip to content

Instantly share code, notes, and snippets.

@erikjms
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikjms/504a989eb5951a7900ac to your computer and use it in GitHub Desktop.
Save erikjms/504a989eb5951a7900ac to your computer and use it in GitHub Desktop.
Iterator class for Processing: map iterated functions onto cartesian coordinate plane (c, f(x)) --or (f(x), c), depending on what looks best!
// can Processing graph iterated functions without undue pain?
// can I figure out how to try to ask it to do so?
/* note on mapping function values to window size:
* when using x and y conventionally to draw shapes
* point(x,y) for example
* for expected results from the map() method,
* y goes with the height
* x goes with the width
* ...obvious maybe but easy to get confused in the wee hours
*/
class Iterator {
float exponent = 2.0;
float initX = 0.0;
float initC = 0.0;
float initK = 1.0;
float xMin = -1.0;
float xMax = 1.0;
float cMin = -1.0;
float cMax = 1.0;
float minK = -1.0;
float maxK = 1.0;
// noise to go
float noiseFactor = 1.0;
float noiseFactorFactor = 1.1;
// starting noise() 1D parameter
float makeNoise = 1.0;
// increment noise()
float moarNoisePlease = 0.003;
// starting noise() 2D y parameter
float xtraNoise = 10000.0;
// noise enhancer for whatever one might need it for
float ajustement = -1.75;
int iterations = 0;
int generations = 0;
// generate = how many (c, f(x)) pairs to plot
// iterate = how many f(x) iterations before plotting
// x0,xn; c0,cn = ranges for x and c
// usually these will be floats
Iterator(int generate, int iterate, float expn, float x0, float xn, float c0, float cn, float k0, float kn){
generations = generate;
iterations = iterate;
exponent = expn;
xMin = x0;
xMax = xn;
cMin = c0;
cMax = cn;
minK = k0;
maxK = kn;
}
// draws cartesian graph axes if wanted
// color of low contrast to background does not get in the way
// put in setup() to draw only once!
void drawGraph(){
// for greater variation across c
int zeroX = int(map(0, cMin, cMax, 0, width));
int zeroY = int(map(0, xMin, xMax, 0, height));
// // for greater variation across f(x)
// int zeroY = int(map(0, cMin, cMax, 0, height));
// int zeroX = int(map(0, xMin, xMax, 0, width));
line(0,zeroY, width,zeroY);
line(zeroX,0, zeroX,height);
}
// choose (c,x) constrained by min and max values
void initPoint(){
initC = random(cMin, cMax);
initX = random(xMin, xMax);
}
void initKonstant(){
initK = random(minK, maxK);
// some ways of linking k, c, and x
// to try later
// initK = initC / initX;
// initK = random(initX-initC, initX);
// initK = random(initC-initX, initC);
}
// base functions so far
// x -> x^2 + c
// x -> √(c^2 - x^2)
// from "circle map" in 1dmaos.app
// parentheses deduced from title bar--could be inaccurate
// x -> k + x + ((c * sin(2πx))/2π)
void iterate(){
initKonstant();
if(abs(exponent) < 2.50)
exponent *= initK;
else
exponent = sin(exponent) * initK;
for( int i = 0; i < generations; i++){
initPoint();
for( int j = 0; j < iterations; j++){
// initX = sqrt((pow(initC, exponent) - sq(initX))/initK);
// initX = (pow(initX, exponent) * initK) + initC;
// // these two used in fx01
// // x -> √(c^2 - x^2)
// initX = sqrt((sq(initC) - sq(initX)));
// // x -> x^n + c
// initX = pow(initX, exponent) + initC;
// sort of circular thing
initX = initK + initX + ((initC * sin(initX * TWO_PI))/TWO_PI);
}
graphPoint();
}
}
void graphPoint(){
// graph c on x axis for greater variation across c
int x = int(map(initC, cMin, cMax, 0, width));
int y = int(map(initX, xMin, xMax, 0, height));
// graph f(x) on x axis for greater variation across f(x)
// int y = int(map(initC, cMin, cMax, 0, height));
// int x = int(map(initX, xMin, xMax, 0, width));
point(x, y);
}
color noiseColor(int r, int g, int b, int a){
int changeMe = int(random(3));
if (changeMe == 0)
r = (abs(int(r * noiseFactor))) % 255;
else if (changeMe == 1)
g = (abs(int(g * noiseFactor))) % 255;
else
b = (abs(int(b * noiseFactor))) % 255;
return color(r, g, b, a);
}
void noisePlease(){
noiseFactorFactor = random(-2.1, 2.0);
noiseFactor = noiseFactorFactor * noise(makeNoise);
makeNoise += moarNoisePlease;
}
void startNoise(){
makeNoise = random(10001.0);
xtraNoise = random(20001.0);
moarNoisePlease = random(0.001, 0.0051);
ajustement = random(-3.5, 3.56);
// println("noise x start: " + makeNoise);
// println("noise y start: " + xtraNoise);
// println("noise increment: " + moarNoisePlease);
// println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment