This is a SCRIPT-8 cassette.
Created
September 9, 2019 04:04
-
-
Save PJaros/97d50f6ac3cba14e354abc8bfc20e1d7 to your computer and use it in GitHub Desktop.
SCRIPT-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// title: Swirly squares | |
init = state => { | |
state.totalElapsed = 0 // total time passed | |
state.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) * 3 * (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) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iframeVersion": "0.1.255", | |
"lines": [ | |
36, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0 | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment