A Pen By
Jacek

JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.

Any URL's added here will be added as `<script>`

s in order, and run *before* the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.

If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.

You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.

+ add another resource

` ````
// Daniel Shiffman
// http://youtube.com/thecodingtrain
// http://codingtra.in
// Recaman Sequence
// https://youtu.be/DhFZfzOvNTU
let numbers = [];
let count = 1;
let sequence = [];
let index = 0;
//how long between a new number is generated
let newTickEveryMS=1000
let oldTickTime=Date.now()
let currStep
let scl = 0;
let arcs = [];
let biggest = 0;
class Arc {
constructor(start, end, dir) {
this.start = start;
this.end = end;
this.dir = dir;
}
show() {
let diameter = abs(this.end - this.start);
let x = (this.end + this.start) / 2;
stroke(255);
strokeWeight(0.5);
noFill();
if (this.dir == 0) {
//TOP
arc(x, 0, diameter, diameter, PI, 0);
} else {
//BOTTOM
arc(x, 0, diameter, diameter, 0, PI);
}
}
showPartial(){
stroke(255);
strokeWeight(0.5);
noFill();
let diameter = abs(this.end - this.start);
let x = (this.end + this.start) / 2;
if (this.dir == 0) {
//TOP
if(this.end<this.start){
drawLeftTop(x,0,diameter,currStep)
}
else{
drawRightTop(x,0,diameter,currStep)
}
} else {
//BOTTOM
if(this.end<this.start){
drawLeftBottom(x,0,diameter,currStep)
}
else{
drawRightBottom(x,0,diameter,currStep)
}
}
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(30);
background(0);
numbers[index] = true;
sequence.push(index);
}
function step() {
let next = index - count;
if (next < 0 || numbers[next]) {
next = index + count;
}
numbers[next] = true;
sequence.push(next);
let a = new Arc(index, next, count % 2);
arcs.push(a);
index = next;
if (index > biggest) {
biggest = index;
}
count++;
}
function draw() {
if (oldTickTime < Date.now()) {
step()
oldTickTime = Date.now() + newTickEveryMS;
//when did the new tick start
start=Date.now()
//when is it going to end
end=start+newTickEveryMS
}
// at what point in the tick are we? map that to radians
// v if this is 0 there phantom arcs appearing for a few frames
currStep=map(end-Date.now(),newTickEveryMS,0, 0.1 ,PI)
translate(0, height / 2);
scl = lerp(scl, width / (biggest*1.1), 0.1);
scale(scl);
background(0);
for(let i=0;i<arcs.length-1;i++){
arcs[i].show()
}
arcs[arcs.length-1].showPartial()
// if (count > windowWidth) {
// noLoop();
// }
}
/**
* drawing functions
* naming scheme
* draw[direction it is going on x axis][direction on y axis]()
*/
function drawRightBottom(x,y,diameter,currStep) {
arc(x, y, diameter, diameter, PI - currStep, PI);
}
function drawRightTop(x,y,diameter,currStep) {
arc(x, y, diameter, diameter, PI, currStep - PI);
}
function drawLeftBottom(x,y,diameter,currStep) {
arc(x, y, diameter, diameter, 0, currStep);
}
function drawLeftTop(x,y,diameter,currStep) {
arc(x, y, diameter, diameter, 0 - currStep, 0);
}
```

999px

Loading
..................

Alt F
Opt F
Find & Replace

Also see: Tab Triggers