-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
69 lines (55 loc) · 2.26 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
compile();
function compile() {
var elem = document.getElementById('main-input');
elem.addEventListener('keypress', function(e){
if (e.keyCode == 13 && !event.shiftKey) {
e.preventDefault() // Prevents addition of extra line break
deleteEverything()
}
});
}
// Recursively randomizes characters in a string
function recursivelyRandomizeCharacters(string, positionInString, originalLength) {
// TODO: Preserve spaces
var randcharacters = '@#$%^&*{}~AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz@#$%^&*!{}[]~@#$%^&*!{}[]~'.split("")
let randomNumber = Math.floor(Math.random() * randcharacters.length)
var splitSentence = string.split("")
// Assign a random character, and set the view and the string, unless it's a space
if (splitSentence[positionInString] !== " ") {
splitSentence[positionInString] = randcharacters[randomNumber]
}
let newSentence = splitSentence.join("")
document.getElementById('main-input').value = newSentence
string = newSentence
// Break recursion
if (positionInString == 0) {
recursivelyRandomizeCharactersCallback()
return
}
// Else, call the next string in the set
setTimeout(()=>{
recursivelyRandomizeCharacters(string, positionInString - 1, originalLength)
}, parseInt( 400 / originalLength));
}
// Callback for recursivelyRandomizeCharacters
function recursivelyRandomizeCharactersCallback() {
document.getElementById('main-input').value = ""
}
// Deletes with a randomization process
function funDelete() {
// Grab the current sentence and split it
var sentence = document.getElementById('main-input').value
var sentenceLength = sentence.split("").length - 1
recursivelyRandomizeCharacters(sentence, sentenceLength, sentenceLength)
}
function deleteEverything() {
funDelete()
// document.getElementById('main-input').value = ""
}
/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */
particlesJS.load('particles-js', 'inc/particles.json', function() {
console.log('callback - particles.js config loaded');
});