xxxxxxxxxx
125
let words = ['word', 'search', 'word', 'search', 'word', 'search', 'word', 'search']
let sideL = 10
let w = 600
let h = w
let letter = Math.floor(w/(sideL+1))
let fontS = letter*0.75
let b
let userGenerated = []
let _font
let user
let button
let button2
let showHighlight = false
let showGuide = false
let slider_sideL
let makeFrame = 999999
function preload() {
_font = loadFont('Volkhov-Bold.ttf')
}
function make() {
//b = newBoard(user.value())
makeFrame = frameCount
txt = user.value()
user.value('')
txt = txt.replace(/[^\w]|_|\d/g, ' ')
txt = txt.split(/\s+/)
let newtxt = []
for (let i=0;i<txt.length;i++) {
if (txt[i].length > 3) {
newtxt.push(txt[i])
}
}
txt = newtxt
if (txt.length > sideL) {
newtxt = []
for (let i=0;i<sideL;i++) {
newtxt.push(random(txt))
}
txt = newtxt
}
if (txt.length == 0) {
txt = words
}
console.log(txt)
words = txt
userGenerated.shift()
userGenerated.push(new Board(txt, sideL))
}
function guideShow() {
showGuide = !showGuide
}
function keyTyped() {
if (key == 'H') {
showHighlight = !showHighlight
}
}
function keyPressed() {
if (keyCode == ENTER && user.value().length > 3) {
make()
} else if (keyCode == ENTER && user.value().length == 0) {
user.value(words.join(' '))
make()
}
}
function setup() {
let canvas = createCanvas(w, h);
user = createInput()
user.position(windowWidth/2-20, h+20)
button = createButton('Create WordSearch');
button.position(user.x + user.width, user.y);
button.mousePressed(make);
button2 = createButton('User Guide')
button2.position(user.x - user.width*1.8, user.y)
button2.mousePressed(guideShow)
slider_sideL = createSlider(8, 30, 10)
slider_sideL.position(user.x-user.width, h+20)
b = new Board(words, sideL)
}
function draw() {
background(255);
sideL = slider_sideL.value()
text(slider_sideL.value(), windowWidth/2, h+80)
if (!userGenerated.length) {
if (showHighlight) {
b.highlight()
}
b.show()
}
if (userGenerated.length){
if (showHighlight) {
userGenerated[userGenerated.length-1].highlight()
}
userGenerated[userGenerated.length-1].show()
//noLoop()
}
if (showGuide) {
push();
fill(220, 252)
rect(0,0,width,height)
stroke(0)
fill(0)
textAlign(LEFT)
textSize(16)
text('Enter your desired words into the box below', w*0.1,h*0.1)
text('Press ENTER/RETURN at any time to re-generate the word search', w*0.1, h*0.2)
text('Press Shift+H to highlight hidden words', w*0.1, h*0.3)
text('Use the slider to set the size of the word search', w*0.1, h*0.4)
text('Save using [right-click] -> Save Image As...', w*0.1, h*0.5)
pop();
}
}