Skip to content

Instantly share code, notes, and snippets.

@DWGitHubPage
Created March 3, 2019 22:02
Show Gist options
  • Select an option

  • Save DWGitHubPage/710b97475b681fe961d3be97809e1994 to your computer and use it in GitHub Desktop.

Select an option

Save DWGitHubPage/710b97475b681fe961d3be97809e1994 to your computer and use it in GitHub Desktop.

Revisions

  1. DWGitHubPage created this gist Mar 3, 2019.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    This is a [SCRIPT-8](https://script-8.github.io) cassette.
    1 change: 1 addition & 0 deletions chains.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}
    34 changes: 34 additions & 0 deletions code.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    initialState = {
    totalElapsed: 0, // total time passed
    rotations: [], // each rectangle's individual rotation
    }

    // given a number of milliseconds and square index,
    // returns the square's rotation
    const getRotation = (milliseconds, i) => {
    return Math.sin(milliseconds / 400) * 16 * (i + 1)
    }

    update = (state, input, elapsed) => {
    state.totalElapsed += elapsed
    state.rotations = range(8).map(i => getRotation(state.totalElapsed, i))
    }

    draw = (state) => {
    clear()
    const { angle } = state
    range(8).forEach(i => {
    const halfSide = 8 * i / 2
    const topLeft = [64 - halfSide, 64 - halfSide]
    const topRight = [64 + halfSide, 64 - halfSide]
    const bottomRight = [64 + halfSide, 64 + halfSide]
    const bottomLeft = [64 - halfSide, 64 + halfSide]
    const color = i % 7

    // add 10 degrees to each successive square.
    // e.g. the first square gets 0 new degrees, the second one gets 10,
    // the third one gets 20, etc.
    const customAngle = state.rotations[i]
    polyStroke([topLeft, topRight, bottomRight, bottomLeft], customAngle, color)
    })
    }
    1 change: 1 addition & 0 deletions map.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    []
    12 changes: 12 additions & 0 deletions misc.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {
    "lines": [
    34,
    0,
    0,
    0,
    0,
    0,
    0,
    0
    ]
    }
    1 change: 1 addition & 0 deletions phrases.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}
    1 change: 1 addition & 0 deletions songs.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}
    1 change: 1 addition & 0 deletions sprites.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}