let len=10;
let x=0,y=0,x2=10,y2=0;
let strA='R'
let it = 2
let round =0
let sf=1;
function setup() {
createCanvas(500, 500);
stroke(0)
background(0);
x2=len;
angleMode(DEGREES)
strokeWeight(3);
for(let i=0;i<10;i++){
iterate()
}
}
function draw() {
translate(width/2,width/2);
scale(0.45,-0.45);
rotate(60+10*frameCount/200);
stroke(50,200-50*sin(frameCount),255-200*cos(frameCount));
drawCurve();
rotate(180);
drawCurve();
stroke(100,200-100*cos(frameCount),255-150*sin(frameCount));
push();
rotate(frameCount);
strokeWeight(2);
drawCurve();
pop();
}
function iterate(){
t = strA.length;
tmp = strA +'R';
tmp2='';
for (let i=t-1;i>=0;i--){
if (strA.charAt(i)== 'R'){
tmp = tmp+'L';
}
if (strA.charAt(i)== 'L'){
tmp=tmp+'R';
}
}
strA = tmp;
it = it+1;
}
function drawCurve(){
k=int(strA.length);
line(0,0,len,0)
x=0;y=0;x2=len;y2=0;
for (let j=0;j<k;j++){
if ((strA.charAt(j)=='R' && x2>x) ||(strA.charAt(j)=='L' && x2<x) ){
x3=x2;
y3=y2-len;
}
if ((strA.charAt(j)=='R' && y2>y) ||(strA.charAt(j)=='L' && y2<y) ){
x3=x2+len;
y3=y2;
}
if ((strA.charAt(j)=='R' && y2<y) ||(strA.charAt(j)=='L' && y2>y) ){
x3=x2-len;
y3=y2;
}
if ((strA.charAt(j)=='R' && x2<x) ||(strA.charAt(j)=='L' && x<x2) ){
x3=x2;
y3=y2+len;
}
line(x2,y2,x3,y3);
x=x2;
y=y2;
x2=x3;
y2=y3;
}
}