fin
This commit is contained in:
parent
d6c8ae6f21
commit
117f99087f
36 changed files with 123064 additions and 249 deletions
19
5/index.html
Normal file
19
5/index.html
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>Sketch</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
|
||||
<script src="libraries/p5.min.js"></script>
|
||||
<script src="libraries/p5.sound.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
If banana on a wall can be art, then an unfinished JavaScipt project can be art too.
|
||||
<script src="sketch.js"></script>
|
||||
</body>
|
||||
</html>
|
10
5/jsconfig.json
Normal file
10
5/jsconfig.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6"
|
||||
},
|
||||
"include": [
|
||||
"*.js",
|
||||
"**/*.js",
|
||||
"/home/melody/.vscode-oss/extensions/samplavigne.p5-vscode-1.2.16/p5types/global.d.ts"
|
||||
]
|
||||
}
|
2
5/libraries/p5.min.js
vendored
Normal file
2
5/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
3
5/libraries/p5.sound.min.js
vendored
Normal file
3
5/libraries/p5.sound.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
5/shake.txt
Normal file
7
5/shake.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
word word word word
|
||||
|
||||
From fairest creatures we desire increase,
|
||||
That thereby beauty's rose might never die,
|
||||
But as the riper should by time decease,
|
||||
His tender heir might bear his memory:
|
||||
word
|
122185
5/shakespeare.txt
Normal file
122185
5/shakespeare.txt
Normal file
File diff suppressed because it is too large
Load diff
56
5/sketch.js
Normal file
56
5/sketch.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
let shakespeareArray;
|
||||
function preload() {
|
||||
loadStrings("shakespeare.txt", handleShakespeare);
|
||||
}
|
||||
|
||||
function setup() {
|
||||
createCanvas(400, 400);
|
||||
console.log(shakespeareArray);
|
||||
const shakespeareTable = new Map();
|
||||
for (i = 0; i < shakespeareArray.length; i++) {
|
||||
const word = shakespeareArray[i];
|
||||
|
||||
// prettier-ignore
|
||||
if (!(shakespeareTable.get(word))) { // in => all object keys
|
||||
shakespeareTable.set(word, new Map());
|
||||
}
|
||||
wordMap = shakespeareTable.get(word);
|
||||
let nextWord;
|
||||
if (shakespeareArray.length > i) {
|
||||
nextWord = shakespeareArray[i + 1];
|
||||
}
|
||||
if (wordMap.get(nextWord)) {
|
||||
wordMap.set(nextWord, wordMap.get(nextWord) + 1);
|
||||
} else {
|
||||
wordMap.set(nextWord, 1);
|
||||
}
|
||||
}
|
||||
console.log(shakespeareTable);
|
||||
const probabilityPostfix = "___PROBABILITY___"
|
||||
shakespeareTable.forEach((meowmeowmeow) => { // CONTINUE HERE
|
||||
console.log("UWU")
|
||||
let combinedAmount = 0
|
||||
for (nextWord in word) {
|
||||
combinedAmount += word.get(nextWord)
|
||||
}
|
||||
for (nextWord in word) {
|
||||
probabilityNextWord = word.get(nextWord) / combinedAmount
|
||||
word.set(nextWord + probabilityPostfix, probabilityNextWord)
|
||||
console.log(probabilityNextWord)
|
||||
}
|
||||
})
|
||||
|
||||
console.log(shakespeareTable);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
background(220);
|
||||
}
|
||||
|
||||
function handleShakespeare(data) {
|
||||
joinedShakespeareString = data.join(" ");
|
||||
cleanedShakespearString = joinedShakespeareString.replaceAll(/\s+/g, " ");
|
||||
shakespeareArray = joinedShakespeareString
|
||||
.split(/\s*(\b|\W|\s)\s*/)
|
||||
.filter((item) => item !== "");
|
||||
}
|
8
5/style.css
Normal file
8
5/style.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue