Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // 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

Console