xxxxxxxxxx
131
let otherWords;
let wordsToCheck = [
"up",
"up",
"up",
"up",
"friendly",
"happy",
"big",
"quiet",
];
// let wordsToCheck = [
// "The",
// "center",
// "for",
// "the",
// "recently",
// "possible",
// "Three",
// "words",
// "Collaboration",
// "Experimentation",
// "and",
// "Community",
// ];
let synonyms = [];
let antonyms = [];
let backgroundWords = [];
let bgColor = "white";
let fontColor = "light-pink";
let synImg;
let antImg;
function preload() {
otherWords = loadJSON("assets/syn-ant-updated.json", useJSON);
}
function setup() {
createCanvas(displayWidth, displayHeight);
pixelDensity(1);
synImg = getImages(synonyms);
antImg = getImages(antonyms);
background("white")
}
function draw() {
let radius = 100;
image(antImg, 0, 0);
let mouseDraw = get(mouseX - radius/2, mouseY - radius/2, radius, radius)
image(synImg, 0, 0);
image(mouseDraw, mouseX - radius/2, mouseY - radius/2, radius, radius);
}
function drawMask(){
fill(255, 255, 255, 50)
ellipse(mouseX, mouseY, 40, 40);
}
function useJSON() {
for (let i = 0; i < wordsToCheck.length; i++) {
wordsToCheck[i] = wordsToCheck[i].toLowerCase();
}
for (let i = 0; i < otherWords.words.length; i++) {
let thisWord = otherWords.words[i];
for (let j = 0; j < wordsToCheck.length; j++) {
let wordToCheck = wordsToCheck[j];
if (thisWord.KEY == wordToCheck) {
if (thisWord.SYN) {
thisWord.SYN.forEach((element) => synonyms.push(element));
}
if (thisWord.ANT) {
thisWord.ANT.forEach((element) => antonyms.push(element));
}
}
}
}
}
function getImages(wordArray) {
if (wordArray == synonyms) {
backgroundWords = synonyms;
bgColor = "white";
fontColor = "lightpink";
} else {
backgroundWords = antonyms;
bgColor = "lightpink";
fontColor = "white";
}
fill(bgColor);
noStroke();
rect(0, 0, width, height);
fill(fontColor);
let lineHeight = 60;
push();
translate(width / 2, height / 2);
translate(-width / 2, -height / 2);
let wordLine = "";
for (let i = 0; i < backgroundWords.length; i++) {
wordLine = wordLine + backgroundWords[i] + " ";
}
for (let i = 0; i < 10; i++) {
wordLine = wordLine + wordLine;
}
textWrap(WORD);
textLeading(lineHeight);
textSize(20);
text(wordLine, -10, 0, width + 100, height + lineHeight);
pop();
let img = get();
return img;
}