Turn
How do I make an turn?
Forked from Gregory Potdevin's Pen bpxKQM.. What is a turn? How do you make a turn? This script and codes were developed by Gregory Potdevin on 01 October 2022, Saturday.
Turn - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Turn</title>
</head>
<body> <button onclick="refresh()">refresh</button>
<pre id="level"></pre> <script src="js/index.js"></script>
</body>
</html>
Turn - Script Codes JS Codes
var SIZE = 12
var REVERSE_PROBA = 0.3
var CHAIN_PROBA = 0.4
var START_SPEED = 1
var END_SPEED = 1.3
var PATTERNS = [ "solo", "duo", "duo_color", "sequence_2", "sequence_3", "sequence_3colors", "all_4", "all_4_delayed", "line_4colors", "machine_gun", "machine_gun_color", "random_4", "zigzag_4", "zigzag", "next_same_color", "next_color", "next_next_color", "turn2", "sin", "change", "change2", "change_random_4", "change_next_4", "change_4colors", "change_all_4", "change_all_4_turn",
]
var CENTERS = [ {center: "arc2", colors: [0, 1]}, {center: "arc2", colors: [0, 1], baseAngle: 90}, {center: "arc2", colors: [0, 1], baseAngle: 45}, {center: "arc3", colors: [0, 1, 2]}, {center: "arc4", colors: [0, 1, 0, 1]}, {center: "arc4", colors: [0, 1, 0, 1], baseAngle: 45}, {center: "arc4", colors: [0, 1, 2, 3]}, {center: "arc4", colors: [0, 1, 2, 3], baseAngle: 45}, {center: "arc4", colors: [0, 1, 0, 2]}, {center: "arc8", colors: [0, 1, 2, 3, 0, 1, 2, 3]}, {center: "arc8", colors: [0, 0, 1, 1, 2, 2, 3, 3]}, {center: "triangle", colors: [0, 1, 2]}, {center: "triangle", colors: [0, 1, 2]}, {center: "square", colors: [0, 1, 0, 1]}, {center: "square", colors: [0, 1, 0, 2]}, {center: "square", colors: [0, 1, 0, 1], baseAngle: 45}, {center: "square", colors: [0, 1, 2, 3]}, {center: "square", colors: [0, 1, 2, 3], baseAngle: 45},
]
function randomLevel(){ var level = ""; var forceChain = false var center = randomEntry(CENTERS) level += ' // TURN XXX\n' level += ' {center: "' + center.center + '", colors: ' + JSON.stringify(randomizeColors(center.colors)) + ', baseAngle: ' + (center.baseAngle || 0) + ', speed: 1, fallTime: 3, waitTime: 2, patterns: [\n'; for(var i=0; i<SIZE; i++){ var pattern = randomEntry(PATTERNS); var entry = { type: pattern } entry.speed = roundDecimals(lerp(i/(SIZE-1), START_SPEED, END_SPEED)) if (Math.random() < REVERSE_PROBA) entry.reverse = true var canChain = i > 0 && pattern != "all_4" if (canChain && (forceChain || (pattern == "turn2" || Math.random() < CHAIN_PROBA) ) ) { entry.chain = true } level += ' ' + JSON.stringify(entry) + ',\n' forceChain = (pattern == "turn2"); } level += ' ]},'; return level;
}
var el = document.getElementById("level");
el.innerHTML = randomLevel()
function refresh(){ var el = document.getElementById("level"); el.innerHTML = randomLevel()
}
function lerp(ratio, start, end){ return start + ratio * (end - start)
}
function roundDecimals(value){ return Math.round(value * 100) / 100
}
function randomEntry(arr){ return arr[Math.floor(Math.random()*arr.length)]
}
function shuffle(a) { var j, x, i; for (i = a.length; i; i -= 1) { j = Math.floor(Math.random() * i); x = a[i - 1]; a[i - 1] = a[j]; a[j] = x; } return a
}
function randomizeColors(colors){ var newColors = shuffle([1, 2, 3, 4]) return colors.map(function(color){return newColors[color]})
}
Developer | Gregory Potdevin |
Username | GregoryPotdevin |
Uploaded | October 01, 2022 |
Rating | 3 |
Size | 2,437 Kb |
Views | 16,192 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Control | 2,855 Kb |
Page Numbers generator | 3,330 Kb |
HTML Select | 1,362 Kb |
Searchkit 0.8 | 4,227 Kb |
RefinementListFilter sort | 5,022 Kb |
A Pen by Gregory Potdevin | 2,432 Kb |
Shape Maker | 2,056 Kb |
A Pen by Gregory Potdevin | 1,713 Kb |
RangeInputFilter | 5,221 Kb |
Penninghen | 26,306 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Velocity.js custom stagger | Tommiehansen | 4,805 Kb |
A Pen by boilzzz | Boilzzz | 2,761 Kb |
Animate a paper plane along an SVG path, looking ahead | PotatoDie | 3,734 Kb |
Fading text with CSS blend modes | Giana | 3,305 Kb |
Week7 replicate | Hwcasis | 1,620 Kb |
Sticky Navbar | Phantomesse | 5,106 Kb |
A Pen by Jim Savage | Madebyjam | 2,418 Kb |
Vanilla JS - A toggleClass function | Woodwork | 2,532 Kb |
Content Changer | Cliffpyles | 4,538 Kb |
Prototype Responsive Homepage | Heyitsolivia | 7,677 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!