Skip to content

Commit 2ffa6c9

Browse files
Compiterator v1.7
- Added two iteration modes - Tweaked initial node placements - Added a few comments
1 parent 9cdd64d commit 2ffa6c9

2 files changed

Lines changed: 74 additions & 12 deletions

File tree

compiterator/readme.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ To clear the screen press `R` or go to edit mode and then back to render.
5454
Pressing `Q` toggles the rendering so that no changes occur, useful for pausing to inspect and for swapping modes for creative combinations.
5555

5656
Pressing `E` will cycle the different algorithms for the chaos game, it will not clear the screen.
57-
* In the first mode, sets the complex parameter for the linear interpolation algorithm.
58-
* In the second mode, sets the complex parameter for the constant distance algorithm.
59-
* In the third mode, sets the complex parameter for the fatou experimental algorithm
57+
1. linear interpolation algorithm.
58+
1. constant distance algorithm.
59+
1. linear interpolation algorithm with exponential sum output parameter
60+
1. constant distance with exponential sum output parameter
61+
1. exponential sum algorithm
6062

6163
Pressing `~` will cycle the different mouse-selector modes.
6264
The mouse (or `WASD` keys) will set/move the point that controls the:
@@ -65,7 +67,7 @@ The mouse (or `WASD` keys) will set/move the point that controls the:
6567
1. Location of the iterated point, can be used to demonstrate the attractor properties.
6668
1. Point at which the plot is drawn towards, also useful to demonstrate the attractors.
6769
1. Game probabilities, with the probability of iterated point resetting as x and layer swapping as y respectively.
68-
1. Most recently created node, mostly for making small adjustments in the fatou experimental mode.
70+
1. Most recently created node, mostly for making small adjustments in the exponential sum mode.
6971

7072
You can budge the point specified by the input settings that would otherwise be set by the mouse a small distance from its current position by pressing `WASD` in the way you would expect, `W` = up, `A` = left, `S` = down, `D` = right.
7173
This can be used to observe how small changes in the current state effect the outcome without having to locate the old point with the mouse.
@@ -98,7 +100,9 @@ There are three algorithms for the iteration:
98100
The parameter, based on the screen position, is mapped from the whole plane into the unit disk.
99101
1. The iterated point moves by a rotation of a constant complex vector towards the chosen node.
100102
The parameter, based on the screen position, is mapped in the reals by an exponential and in the imaginary by a branched logarithm.
103+
1. The iterated point moves on a linear interpolation to the chosen node with a complex parameter of the output of the sum of a complex expoentiation function and the chosen node.
104+
1. The iterated point moves by a rotation of a constant complex vector (the output of the sum of a complex exponentiation function and the chosen node) towards the chosen node.
101105
1. The iterated point moves to the output of the iterated sum of a complex exponentiation function and the chosen node
102106
The parameter, based on twice the screen position, is used as the exponent.
103107

104-
For this last algorithm to work the probability of the point being reset must be more than 0, adjustable via the fifth mouse-selector mode. Otherwise the point iterates away from the canvas in most cases and thus produces not much of an image.
108+
For the last two algorithms to work the probability of the point being reset must be more than 0, adjustable via the fifth mouse-selector mode. Otherwise the point iterates away from the canvas in most cases and thus produces not much of an image.

compiterator/sketch.js

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ function setup() {
44
//Stuff you can change
55
g.t = createVector(1,0)
66
g.attrs = [[
7-
createVector(0,2/sqrt(3)),
8-
createVector(1,-1/sqrt(3)),
9-
createVector(-1,-1/sqrt(3)),
7+
createVector(0,4/sqrt(3)/3),
8+
createVector(2/3,-2/sqrt(3)/3),
9+
createVector(-2/3,-2/sqrt(3)/3),
1010
],
1111
[
12-
createVector(0,-2/sqrt(3)),
13-
createVector(1,1/sqrt(3)),
14-
createVector(-1,1/sqrt(3)),
12+
createVector(0,-4/sqrt(3)/3),
13+
createVector(2/3,2/sqrt(3)/3),
14+
createVector(-2/3,2/sqrt(3)/3),
1515
]
1616
]
1717
g.reps = 500
@@ -54,7 +54,9 @@ function setup() {
5454

5555
function iterate() {
5656
switch (g.e){
57+
//Choose iteration algorithm
5758
case 0:
59+
//Linear Interpolation
5860
R0 = sqrt(g.t.x*g.t.x+g.t.y*g.t.y)
5961
R1 = (1-1/(R0+1))/R0
6062
x0 = g.t.x*R1
@@ -67,6 +69,7 @@ function iterate() {
6769
y3 = (1-x0)*y1-y0*x1+x0*y2+y0*x2
6870
break
6971
case 1:
72+
//Constant Distance
7073
x0 = exp(g.t.x)
7174
y0 = log(abs(g.t.y)+1)*(g.t.y<0 ? -1 : 1)
7275
x0 = exp(g.t.x)
@@ -80,6 +83,50 @@ function iterate() {
8083
y3 = y2+(x0*y1+x1*y0)/R
8184
break
8285
case 2:
86+
//Exponential Iteration -> Linear Interpolation
87+
x4 = g.t.x*2
88+
y4 = g.t.y*2
89+
x1 = g.attr.x
90+
y1 = g.attr.y
91+
x2 = g.pnt.x
92+
y2 = g.pnt.y
93+
R2 = sqrt(x2*x2+y2*y2)
94+
T = atan2(y2,x2)
95+
x5 = x1+pow(R2,x4)*exp(-y4*T)*cos(T*x4+y4*log(R2))
96+
y5 = y1+pow(R2,x4)*exp(-y4*T)*sin(T*x4+y4*log(R2))
97+
R0 = sqrt(x5*x5+y5*y5)
98+
R1 = (1-1/(R0+1))/R0
99+
x0 = x5*R1
100+
y0 = y5*R1
101+
x3 = (1-x0)*x1+y0*y1+x0*x2-y0*y2
102+
y3 = (1-x0)*y1-y0*x1+x0*y2+y0*x2
103+
break
104+
case 3:
105+
//Exponential Iteration -> Constant Distance
106+
x4 = g.t.x*2
107+
y4 = g.t.y*2
108+
x5 = g.attr.x
109+
y5 = g.attr.y
110+
x2 = g.pnt.x
111+
y2 = g.pnt.y
112+
R2 = sqrt(x2*x2+y2*y2)
113+
T = atan2(y2,x2)
114+
x6 = x5+pow(R2,x4)*exp(-y4*T)*cos(T*x4+y4*log(R2))
115+
y6 = y5+pow(R2,x4)*exp(-y4*T)*sin(T*x4+y4*log(R2))
116+
x0 = exp(x6)
117+
y0 = log(abs(y6)+1)*(y6<0 ? -1 : 1)
118+
x0 = exp(x6)
119+
y0 = log(abs(y6)+1)*(y6<0 ? -1 : 1)
120+
x1 = g.attr.x-g.pnt.x
121+
y1 = g.attr.y-g.pnt.y
122+
x2 = g.pnt.x
123+
y2 = g.pnt.y
124+
R = sqrt(x1*x1+y1*y1)
125+
x3 = x2+(x0*x1-y0*y1)/R
126+
y3 = y2+(x0*y1+x1*y0)/R
127+
break
128+
case 4:
129+
//Exponential Iteration
83130
x0 = g.t.x*2
84131
y0 = g.t.y*2
85132
x1 = g.attr.x
@@ -104,10 +151,12 @@ function iterate() {
104151
}
105152

106153
function mod(a,b){
154+
//Float modulo function
107155
return a-b*int(a/b)
108156
}
109157

110158
function mout(x,y,a){
159+
//Change variable point
111160
switch(g.mfix){
112161
case 1:
113162
g.colx=(x-g.x)/g.scal
@@ -142,6 +191,7 @@ function mout(x,y,a){
142191
}
143192

144193
function mget(){
194+
//Get point data to vary
145195
let x=0.0
146196
let y=0.0
147197
switch(g.mfix){
@@ -173,11 +223,13 @@ function mget(){
173223
}
174224

175225
function draw() {
226+
//Main Draw loop
176227
background(0)
177228
translate(g.x,g.y)
178229
let tepnt=g.attrs[g.addr]
179230
g.epnt=tepnt[tepnt.length-1]
180231
if (g.edit) {
232+
//Edit mode
181233
len = g.attrs.length
182234
brk = []
183235
brek = 1
@@ -207,6 +259,7 @@ function draw() {
207259
}
208260
}
209261
else {
262+
//Render mode
210263
for (let i = 0;i<g.reps/(g.mem+(g.mem==0));i++){
211264
if(random()>g.regen){
212265
regen()
@@ -270,6 +323,7 @@ function draw() {
270323
let cp=g.pnt.copy().sub(createVector(g.colx,g.coly))
271324
let cph=ph.sub(createVector(g.colx,g.coly))
272325
switch(g.col){
326+
//Choose colour
273327
case 1:
274328
h = cph.heading()
275329
if (h<0){
@@ -315,6 +369,7 @@ function draw() {
315369
}
316370

317371
function windowResized() {
372+
//Event for when window is resized
318373
resizeCanvas(windowWidth*g.cr,windowHeight*g.cr)
319374
t = min(width,height)/(1080*g.cr)
320375
g.g = createGraphics(width,height)
@@ -328,11 +383,13 @@ function windowResized() {
328383
}
329384

330385
function regen() {
386+
//Reset iterated point to a random value
331387
g.pnt.x = 2*random()-1
332388
g.pnt.y = 2*random()-1
333389
}
334390

335391
function keyPressed() {
392+
//Event for handling keypresses
336393
print(keyCode)
337394
if (keyCode==32){
338395
//space
@@ -445,7 +502,7 @@ function keyPressed() {
445502
}
446503
if (keyCode==69){
447504
//e
448-
g.e=mod(g.e+1,3)
505+
g.e=mod(g.e+1,5)
449506
}
450507
if (keyCode==72){
451508
//h
@@ -487,6 +544,7 @@ function keyPressed() {
487544
}
488545

489546
function mouseClicked(){
547+
//Separate event for alt clicking in edit mode
490548
if (keyCode==18 && keyIsPressed && g.edit){
491549
g.attrs[g.addr].push(createVector(mouseX-g.x,g.y-mouseY).div(g.scal))
492550
}

0 commit comments

Comments
 (0)