Skip to content

Instantly share code, notes, and snippets.

@u-ndefine
Last active April 27, 2020 09:50
Show Gist options
  • Save u-ndefine/175ec0f43ca08dc81a34c1308b4e6b02 to your computer and use it in GitHub Desktop.
Save u-ndefine/175ec0f43ca08dc81a34c1308b4e6b02 to your computer and use it in GitHub Desktop.
Recaman's sequence, old one
//MODIFICATION//
let gap = 10;
let w = 29;
////////////////
let seq = [1,2,2];
let index = 2;
let circleCount = [0,0,1];
let oneCount = 1;
let twoCount = 2;
let lines = [];
function setup() {
createCanvas(windowWidth, windowHeight);
background(0);
}
class Lines {
constructor(x1, y1, x2, y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
show() {
line(this.x1,this.y1,this.x2,this.y2);
}
}
function draw() {
background(0,25);
translate(width/2+(index%20-9.5)/18*500,300-(circleCount[index-2]*w));
fill(255);
frameRate(30);
// sequence
for(n=0;n<seq[index];n++) {
seq.push(index%2+1);
if(index%2==0) {
circleCount.push(oneCount);
oneCount++;
} else {
circleCount.push(twoCount);
twoCount++;
}
}
// draw circles
noStroke();
for(b=0;b<twoCount;b++) {
ellipse(gap,b*w,6,6);
}
for(c=0;c<oneCount;c++) {
ellipse(-gap,c*w,6,6);
}
stroke(255,0,0);
strokeWeight(2);
// draw lines
let a =
new Lines((seq[index-2]-1.5)*2*gap,
circleCount[index-2]*w,
(seq[index-1]-1.5)*2*gap,
circleCount[index-1]*w);
lines.push(a);
for(let a of lines) {
a.show();
}
index++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment