xxxxxxxxxx
481
let tboxName;
let tboxVirtue;
let zodiac;
let cancer;
let leo;
let virgo;
let libra;
let scorpio;
let sagittarius;
let capricorn;
let aquarius;
let pisces;
let aries;
let taurus;
let gemini;
let pentagram;
let sprit;
let celestite;
let air;
let sapphire;
let water;
let emerald;
let earth;
let quartz;
let fire;
let amber;
let smoke;
let candle;
let lines = RiTa.splitSentences("Welcome stranger! Let's cast a spell. Click the candle to begin the ritual.");
let name = RiTa.splitSentences("What is your name?");
let date = RiTa.splitSentences("What is your zodiac sign?");
let virtue = RiTa.splitSentences("What are you seeking?");
let element = RiTa.splitSentences("Select one of the 5 elements.");
let madness = RiTa.splitSentences("When you're ready, press the rune.");
let nameResult = "/";
let virtueResult = "/";
let zodiacResult = "/";
let elementResult = "/";
let files = [];
let spell = "/";
let spellFinal = [];
let xs = [];
let ys = [];
let bubbles = [];
let enterCount = 0;
let cancerx;
let leox;
let virgox;
let librax;
let scorpiox;
let sagittariusx;
let capricornx;
let aquariusx;
let piscesx;
let ariesx;
let taurusx;
let geminix;
let cancery;
let leoy;
let virgoy;
let libray;
let scorpioy;
let sagittariusy;
let capricorny;
let aquariusy;
let piscesy;
let ariesy;
let taurusy;
let geminiy;
//RiTa grammar
let grammar;
//RiTa n-grams
let markov;
let inc = [];
let incantation;
let seeks;
let seeks1;
let seeks2;
let seeks3;
let spelling;
function preload() {
zodiac = loadImage('zodiac.jpg');
pentagram = loadImage('pentagram.jpg');
celestite = loadImage('celestite.png');
amber = loadImage('amber.png');
sapphire = loadImage('sapphire.png');
emerald = loadImage('emerald.png');
quartz = loadImage('quartz.png');
smoke = loadImage('smoke.jpg');
candle = loadImage('candle.png');
cancer = loadStrings("cancer.txt");
leo = loadStrings("leo.txt");
virgo = loadStrings("virgo.txt");
libra = loadStrings("libra.txt");
scorpio = loadStrings("scorpio.txt");
sagittarius = loadStrings("sagittarius.txt");
capricorn = loadStrings("capricorn.txt");
aquarius = loadStrings("aquarius.txt");
pisces = loadStrings("pisces.txt");
aries = loadStrings("aries.txt");
taurus = loadStrings("taurus.txt");
gemini = loadStrings("gemini.txt");
spirit = loadStrings("spirit.txt");
air = loadStrings("air.txt");
water = loadStrings("water.txt");
earth = loadStrings("earth.txt");
fire = loadStrings("fire.txt");
}
function setup() {
createCanvas(1024, 768);
}
function draw() {
background(0);
fill(204, 204, 255);
rect(0, 0, 1024, 5);
rect(0, 0, 5, 768);
rect(0, 763, 1024, 5);
rect(1019, 0, 5, 768);
textFont('courier');
textSize(35);
noStroke();
fill(255);
textAlign(CENTER);
if (enterCount == 0) {
imageMode(CENTER);
image(candle, width/2, 590, 200, 400);
drawLines();
}
else if (enterCount == 1) {
drawName();
}
else if (enterCount == 2) {
drawVirtue();
}
else if (enterCount == 3) {
drawDate();
}
else if (enterCount == 4) {
imageMode(CENTER);
tint(255);
image(pentagram, width/2, height/2 + 80, 500, 500);
drawElement();
}
else if (enterCount == 5) {
textAlign(CENTER);
for (let i = 0; i < madness.length; i++)
text(madness[i], width / 2, 200 + i * 35);
text(nameResult, width / 2, 400);
text(virtueResult, width / 2, 450);
text(zodiacResult, width/2, 500);
text(elementResult, width / 2, 550);
fill(204, 204, 255, 200);
circle(width/2, 475, 350);
instantiateSpellGrammar();
}
else if (enterCount == 6) {
textFont('courier', 16);
textAlign(LEFT);
for (let i = 0; i < spellFinal.length; i++)
text(spellFinal[i], width / 12, 100 + i * 55, 900, 700);
}
else if (enterCount == 7) {
imageMode(CORNER);
image(smoke, 5, 5, width - 10, height - 10);
nameResult = "/";
virtueResult = "/";
zodiacResult = "/";
elementResult = "/";
files = [];
spell = "/";
spellFinal = [];
}
if (enterCount >= 2 && enterCount <= 4) {
textAlign(LEFT);
text(nameResult+" - "+virtueResult+" - "+zodiacResult+" - "+elementResult, 20, 40);
}
}
function drawLines() {
textAlign(CENTER);
for (let i = 0; i < lines.length; i++)
text(lines[i], width / 2, 200 + i * 45);
}
function drawName() {
textAlign(CENTER);
for (let i = 0; i < name.length; i++)
text(name[i], width / 2, 200 + i * 45);
nameField.changed(printName);
}
function drawVirtue() {
textAlign(CENTER);
for (let i = 0; i < virtue.length; i++)
text(virtue[i], width / 2, 200 + i * 45);
virtueField.changed(printVirtue);
}
function mousePressed () {
if(enterCount == 0) {
enterCount = 1;
nameField = createInput();
nameField.position(width / 2 - 100, height / 2);
nameField.size(200, 45);
}
else if(enterCount == 3) {
if(dist(mouseX, mouseY, cancerx, cancery) < circleRadius) {
zodiacResult = "Cancer";
files.push(join(cancer, ' '));
print(mouseX, mouseY, cancerx, cancery);
enterCount = 4;
}
else if(dist(mouseX, mouseY, leox, leoy) < circleRadius) {
zodiacResult = "Gemini";
files.push(join(gemini, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, virgox, virgoy) < circleRadius) {
zodiacResult = "Taurus";
files.push(join(taurus, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, librax, libray) < circleRadius) {
zodiacResult = "Aries";
files.push(join(aries, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, scorpiox, scorpioy) < circleRadius) {
zodiacResult = "Pisces";
files.push(join(pisces, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, sagittariusx, sagittariusy) < circleRadius) {
zodiacResult = "Aquarius";
files.push(join(aquarius, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, capricornx, capricorny) < circleRadius) {
zodiacResult = "Capricorn";
files.push(join(capricorn, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, aquariusx, aquariusy) < circleRadius) {
zodiacResult = "Sagittarius";
files.push(join(sagittarius, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, piscesx, piscesy) < circleRadius) {
zodiacResult = "Scorpio";
files.push(join(scorpio, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, ariesx, ariesy) < circleRadius) {
zodiacResult = "Libra";
files.push(join(libra, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, taurusx, taurusy) < circleRadius) {
zodiacResult = "Virgo";
files.push(join(virgo, ' '));
enterCount = 4;
}
else if(dist(mouseX, mouseY, geminix, geminiy) < circleRadius) {
zodiacResult = "Leo";
files.push(join(leo, ' '));
enterCount = 4;
}
}
else if(enterCount == 4) {
if(dist(mouseX, mouseY, width/2, 280) < 110) {
elementResult = "Spirit";
files.push(join(spirit, ' '));
enterCount = 5;
} else if(dist(mouseX, mouseY, 340, 400) < 110) {
elementResult = "Fire";
files.push(join(fire, ' '));
enterCount = 5;
} else if(dist(mouseX, mouseY, 670, 410) < 110) {
elementResult = "Air";
files.push(join(air, ' '));
enterCount = 5;
} else if(dist(mouseX, mouseY, 600, 590) < 110) {
elementResult = "Water";
files.push(join(water, ' '));
enterCount = 5;
} else if(dist(mouseX, mouseY, 430, 580) < 110) {
elementResult = "Earth";
files.push(join(earth, ' '));
enterCount = 5;
}
}
else if (enterCount == 5) {
drawSpell();
enterCount = 6;
}
else if (enterCount == 6) {
saveStrings(spellFinal, 'spell.txt');
enterCount = 7;
} else if(enterCount == 7) {
enterCount = 0;
}
}
function printName() {
console.log(nameField.value());
nameResult = nameField.value();
enterCount = 2;
nameField.hide();
virtueField = createInput();
virtueField.position(width / 2 - 100, height / 2);
virtueField.size(200, 45);
}
function printVirtue() {
console.log(virtueField.value());
virtueResult = virtueField.value();
enterCount = 3;
virtueField.hide();
}
function drawDate() {
textAlign(CENTER);
for (let i = 0; i < date.length; i++)
text(date[i], width / 2, 100 + i * 45);
//Display a wheel of zodiac signs to choose from
imageMode(CENTER);
tint(255);
image(zodiac, width/2, height/2, 500, 500);
//Draw invisible circles around each sign
let cx = width/2.0;
let cy = height/2.0;
//fill(100);
noFill();
noStroke();
circles = 12;
angle = Math.PI*2 / circles;
radius = 180;
circleRadius = sin(angle/2) * radius;
for(var i = 0; i < circles; i++){
xCircle = cx + cos(angle*i) * radius;
yCircle = cy - sin(angle*i) * radius;
ellipse(xCircle, yCircle, circleRadius*2, circleRadius*2);
xs.push(xCircle);
ys.push(yCircle);
}
//Variables to x and y values for mouse position when pressed on a zodiac sign
cancerx = xs[0];
leox = xs[1];
virgox = xs[2];
librax = xs[3];
scorpiox = xs[4];
sagittariusx = xs[5];
capricornx = xs[6];
aquariusx = xs[7];
piscesx = xs[8];
ariesx = xs[9];
taurusx = xs[10];
geminix = xs[11];
cancery = ys[0];
leoy = ys[1];
virgoy = ys[2];
libray = ys[3];
scorpioy = ys[4];
sagittariusy = ys[5];
capricorny = ys[6];
aquariusy = ys[7];
piscesy = ys[8];
ariesy = ys[9];
taurusy = ys[10];
geminiy = ys[11];
}
function drawElement() {
textAlign(CENTER);
for (let i = 0; i < element.length; i++)
text(element[i], width / 2, 160 + i * 45);
// imageMode(CENTER);
// tint(255);
// image(pentagram, width/2, height/2 + 80, 500, 500);
tint(255, 200);
image(celestite, width/2, 280, 150, 150);
image(amber, 340, 400, 120, 80);
image(sapphire, 670, 410, 220,160);
image(emerald, 600, 590, 120, 90);
image(quartz, 430, 580, 120, 90);
}
// //RiTa grammar and Markov to generate the spell. Code similar to RiTa library examples "HaikuGrammar" and "Kafgenstein".
function instantiateSpellGrammar() {
//New RiTa Markov with n-gram n=2 from files array including 2 .txt files (zodiac + element), stored in the data folder
markov = new RiMarkov(2);
markov.loadText(files.join(' '));
//Markov to generate and return 3 sentences
inc = markov.generateSentences(3);
incantation = join(inc, ' ');
//RiTa to generate ramdom words to be used in the grammar
seeks = RiTa.randomWord("nn");
seeks1 = RiTa.randomWord("nn");
seeks2 = RiTa.randomWord("nn");
seeks3 = RiTa.randomWord("nn");
spelling = RiTa.randomWord("vbg");
//RiTa grammar for the spell structure. After The Coding Train: Context-Free Grammar with RiTa.js - Programming with Text (https://www.youtube.com/watch?v=VaAoIaZ3YKs). Structure inspired by poems and texts by Shin, S. & Tamás, R. (2018) and Stupart, L. (2016).
grammar = new RiGrammar();
grammar.addRule("<start>", "To find <seek>, I want to <tell> you the <seeks>. They are <spelling>. There is a <seeks> and they are <spelling> - <seeks> become <seeks1> become <seeks2> become <seeks3>, and so they <tell>. <markov> There is a <seeks3> and they are <spelling>. A spell for <name>. Quench the candle to end the ritual.");
grammar.addRule("<seek>", virtueResult);
grammar.addRule("<tell>", "tell | show | narrate | illustrate | demonstrate | recount | sing | play | draw | highlight");
grammar.addRule("<seeks>", seeks);
grammar.addRule("<seeks1>", seeks1);
grammar.addRule("<seeks2>", seeks2);
grammar.addRule("<seeks3>", seeks3);
grammar.addRule("<spelling>", spelling);
grammar.addRule("<markov>", incantation);
grammar.addRule("<name>", nameResult);
}
function drawSpell() {
spell = grammar.expand();
spellFinal = RiTa.splitSentences(spell);
}