cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <!--

A full page view would be better.
Also, click on the game to be able to play.

-->
            
          
!
            
              html, body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;

  /* This centers our sketch horizontally. */
  justify-content: center;

  /* This centers our sketch vertically. */
  align-items: center;
}
            
          
!
            
              let counter = 1
let sequence = []
let index = 0
let numbers  = []

var attackLevel = 1.0
var releaseLevel = 0

var attackTime = 0.001
var decayTime = 0.2
var susPercent = 0.2
var releaseTime = 0.5

let wid = 1080
let hgt = 720

let dir = false   //direction of arc: top = true

let num = 300

function setup () {
  createCanvas(wid,hgt)
  background(210,90,0)

  env = new p5.Env()
  env.setADSR(attackTime, decayTime, susPercent, releaseTime)
  env.setRange(attackLevel, releaseLevel)

  osc = new p5.Oscillator()
  osc.setType('sine')
  // osc.freq(500)

  osc.amp(env)
  osc.start()

  // env.play()

  numbers[index] = true

  for (let i=0;i<num;i++) {

    if (numbers[i]) {
      stroke(255)
      fill(255)
    } else {
      stroke(0)
      fill(0)
    }
  }
}

function step () {
  let next = index - counter

  if (next < 0 || numbers[next]) {
    next = index + counter
    dir = true
  }

  numbers[next] = true
  sequence.push(next)
  index = next

  let diameter = next - index
  let x = (next + index)/2

  counter++
  console.log(sequence.length)
  if (sequence.length === 60) {
    noLoop()
    counter = 1
    sequence = []
    index = 0
    numbers  = []
    background(210,90,0)
    // clear()
    loop()
  }
}

function draw () {
  frameRate(5)
  step()

  for (var i=0;i<=360;i+=10) {
    for (var j in sequence) {
      fill(random(200,255))
      // fill(random(0))
      noStroke()
      ellipse(wid/2+(10*sequence[j])*cos(i),hgt/2+(10*sequence[j])*sin(i),4)
      let freq = pow(2,((index%88)-49)/12) * 440
      // console.log(freq)
      osc.freq(freq)
      env.play()
    }
  }
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console