I saw a video about the Recaman Sequence by Numberphile. If you don't know the algorithm you can look at this link: https://www.youtube.com/watch?v=FGC5TdIiT9U or this one: https://blogs.mathworks.com/cleve/2018/07/09/the-oeis-and-the-recaman-sequence/
I wrote a little piece of software with Processing and p5.js to visualize the sequence. My algorithm makes steps in which the next hop gets defined and then I try to draw a semicircle from the previous point to the new point. My problem is that the current semicircle disappears when the next is drawn. I want all of the semicircles to remain visible.
Here is the link to CodePen where you can see my Code and the Output: https://codepen.io/stefan_coffee/pen/QBBKgp
let S = [];
let count = 0;
let active_num = 0;
function setup() {
}
function draw() {
createCanvas(600, 400);
background(50, 50, 50);
for(i = 0; i < 20; i++) {
step();
drawStep();
}
}
function drawStep() {
var x = (S[S.indexOf(active_num)-1] + active_num ) /2;
var y = height / 2;
var w = active_num - S[S.indexOf(active_num)-1];
var h = w;
if (count % 2 == 0) {
stroke(255);
noFill();
arc(x, y, w, h, PI, 0)
} else {
stroke(255);
noFill();
arc(x, y, w, h, 0, PI);
}
}
function step() {
count++;
S.push(active_num);
console.log('active_num: ' + active_num +' count: ' + count + ' ' + S);
if (S.indexOf(active_num - count) > 0) {
active_num += count;
} else {
if (active_num - count <= 0) {
active_num += count;
} else {
active_num -= count;
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>