xxxxxxxxxx
170
var xm1=0;
var xm2=0;
var y1=0;
var y2=0;
var changeDirection;
var changeDirectopn1;
let words = {}; // HashMap object
let linesMaravillas;
let linesEspejo;
function preload() {
linesMaravillas= loadStrings("Alicia-maravillas.txt")
linesEspejo = loadStrings("Alicia-espejo.txt")
}
function setup() {
createCanvas(windowWidth,windowHeight);
xm1=windowWidth/2-150;
xm2=windowWidth/2+150;
y1=windowHeight/2-150;
y2 =windowHeight/2-150;
changeDirection= false;
changeDirection1= false;
// Load two files
loadFile(linesMaravillas, "maravillas");
loadFile(linesEspejo, "espejo");
}
function draw() {
background(88);
drawCat();
fill(0);
ellipse(xm1,y1,35,200);
ellipse(xm2,y2,35,200);
if(xm1> (windowWidth/2-120)){
changeDirection=true}
//if the circle passes the right side, change the direction
//effects of direction change happen below
else if (xm1<=(windowWidth/2-180)){
changeDirection=false}
//if the circle passes the left side (or becomes equal to 0)
//changes the direction, effects are in the next if statement below
if (xm1>=0 && changeDirection == false){
xm1=xm1+1}
//if x is greater than OR equal to 0, move right
else if(changeDirection == true){
xm1=xm1-1}
if(xm2> (windowWidth/2+180)){
changeDirection1=true}
//if the circle passes the right side, change the direction
//effects of direction change happen below
else if (xm2<=(windowWidth/2+120)){
changeDirection1=false}
//if the circle passes the left side (or becomes equal to 0)
//changes the direction, effects are in the next if statement below
if (xm2>=0 && changeDirection1 == false){
xm2=xm2+1}
//if x is greater than OR equal to 0, move right
else if(changeDirection1 == true){
xm2=xm2-1}
// Show words
let keys = Object.keys(words);
for (let key of keys) {
let w = words[key];
if (w.qualify()) {
w.display();
w.move();
}
}
}
// Load a file
function loadFile(lines, file) {
let allText = join(lines, " ").toLowerCase();
let tokens = allText.split(/[.?!\s,-]+/);
for (let s of tokens) {
// Is the word in the HashMap
if (words[s]) {
// Get the word object and increase the count
// Which book am I loading?
if (file == "maravillas") {
words[s].incrementMaravillas();
} else if (file == "espejo") {
words[s].incrementEspejo();
}
} else {
// Otherwise make a new word
let w = new Word(s);
// And add to the HashMap put() takes two arguments, "key" and "value"
// The key for us is the String and the value is the Word object
words[s] = w;
if (file == "maravillas") {
w.incrementMaravillas();
} else if (file == "espejo") {
w.incrementEspejo();
}
}
}
}
function drawCat(){
fill (0)
ellipse(windowWidth/2-150,windowHeight/2-150,210);
ellipse(windowWidth/2+150,windowHeight/2-150,210);
fill(51, 204, 204)
ellipse(windowWidth/2-150,windowHeight/2-150,200);
ellipse(windowWidth/2+150,windowHeight/2-150,200);
triangle(windowWidth/2-420,windowHeight/2-400,windowWidth/2-390, windowHeight/2-250,windowWidth/2-250, windowHeight/2-350);
triangle(windowWidth/2+420,windowHeight/2-400,windowWidth/2+390, windowHeight/2-250,windowWidth/2+250, windowHeight/2-350);
fill(color(200,165,179));
//noStroke();
triangle(windowWidth/2-70,windowHeight/2,windowWidth/2+70, windowHeight/2,windowWidth/2, windowHeight/2+50)
triangle(windowWidth/2-410,windowHeight/2-390,windowWidth/2-350, windowHeight/2-280,windowWidth/2-270, windowHeight/2-340);
triangle(windowWidth/2+410,windowHeight/2-390,windowWidth/2+350, windowHeight/2-280,windowWidth/2+270, windowHeight/2-340);
fill(0);
noStroke();
triangle(windowWidth/2-50,windowHeight/2,windowWidth/2+50, windowHeight/2,windowWidth/2, windowHeight/2+50)
fill(255);
arc(windowWidth/2, windowHeight/2+150, 700, 100, 0, PI, OPEN);
triangle(windowWidth/2-45,windowHeight/2+175,windowWidth/2-65, windowHeight/2+175,windowWidth/2-40, windowHeight/2+65);
triangle(windowWidth/2-15,windowHeight/2+175,windowWidth/2-35, windowHeight/2+175,windowWidth/2-20, windowHeight/2+65);
triangle(windowWidth/2-5,windowHeight/2+175,windowWidth/2+15, windowHeight/2+175,windowWidth/2, windowHeight/2+65);
triangle(windowWidth/2+25,windowHeight/2+175,windowWidth/2+55, windowHeight/2+175,windowWidth/2+40, windowHeight/2+65);
triangle(windowWidth/2+75,windowHeight/2+175,windowWidth/2+95, windowHeight/2+175,windowWidth/2+82, windowHeight/2+65);
triangle(windowWidth/2+105,windowHeight/2+175,windowWidth/2+125, windowHeight/2+175,windowWidth/2+105, windowHeight/2+55);
triangle(windowWidth/2+185,windowHeight/2+175,windowWidth/2+165, windowHeight/2+175,windowWidth/2+145, windowHeight/2+55);
triangle(windowWidth/2+195,windowHeight/2+175,windowWidth/2+210, windowHeight/2+175,windowWidth/2+195, windowHeight/2+52);
triangle(windowWidth/2+225,windowHeight/2+175,windowWidth/2+245, windowHeight/2+175,windowWidth/2+220, windowHeight/2+50);
triangle(windowWidth/2+255,windowHeight/2+175,windowWidth/2+275, windowHeight/2+175,windowWidth/2+250, windowHeight/2+50);
triangle(windowWidth/2+285,windowHeight/2+175,windowWidth/2+305, windowHeight/2+175,windowWidth/2+260, windowHeight/2+65);
triangle(windowWidth/2+315,windowHeight/2+155,windowWidth/2+335, windowHeight/2+155,windowWidth/2+325, windowHeight/2+65);
triangle(windowWidth/2+340,windowHeight/2+150,windowWidth/2+351, windowHeight/2+150,windowWidth/2+335, windowHeight/2+65);
triangle(windowWidth/2-75,windowHeight/2+175,windowWidth/2-100, windowHeight/2+175,windowWidth/2-80, windowHeight/2+45);
triangle(windowWidth/2-120,windowHeight/2+175,windowWidth/2-145, windowHeight/2+175,windowWidth/2-130, windowHeight/2+45);
triangle(windowWidth/2-175,windowHeight/2+175,windowWidth/2-195, windowHeight/2+175,windowWidth/2-180, windowHeight/2+45);
triangle(windowWidth/2-235,windowHeight/2+175,windowWidth/2-215, windowHeight/2+175,windowWidth/2-215, windowHeight/2+45);
triangle(windowWidth/2-265,windowHeight/2+175,windowWidth/2-245, windowHeight/2+175,windowWidth/2-255, windowHeight/2+45);
triangle(windowWidth/2-295,windowHeight/2+175,windowWidth/2-275, windowHeight/2+175,windowWidth/2-265, windowHeight/2+45);
triangle(windowWidth/2-310,windowHeight/2+165,windowWidth/2-299, windowHeight/2+165,windowWidth/2-285, windowHeight/2+55);
triangle(windowWidth/2-335,windowHeight/2+165,windowWidth/2-315, windowHeight/2+165,windowWidth/2-315, windowHeight/2+55);
triangle(windowWidth/2-350,windowHeight/2+155,windowWidth/2-335, windowHeight/2+155,windowWidth/2-342, windowHeight/2+75);
ellipse(windowWidth/2-200,windowHeight/2-200,15,20);
ellipse(windowWidth/2+200,windowHeight/2-200,15,20);
fill(color(200,165,179));
triangle(windowWidth/2-30,windowHeight/2,windowWidth/2+30, windowHeight/2,windowWidth/2, windowHeight/2+50)
}