xxxxxxxxxx
function preload() {
ku = loadStrings("bashou.txt");
}
sx=400;
class word {
constructor(x, y, tx, sz, c, sp, sw) {
this.x = x;
this.y = y;
this.tx = tx;
this.sz = sz;
this.c = c;
this.sp= sp;
this.sw = sw;
}
display() {
textSize(this.sz);
//fill(20,20,20,200);
fill(this.c);
textAlign(CENTER);
textFont("青柳疎石フォント2");
//textFont("MS MINCHO");
text(this.tx, this.x, this.y+this.sz/2);
}
update() {
if (this.sw==0) {this.sz=this.sz-sp;}
if (this.sw==1) {this.sz=this.sz+sp;}
if (this.sz <= 0) {this.sw=1}
if (this.sz >= sx) {this.sw=0}
}
}
words = []; kami = []; naka=[]; simo=[];
function setup() {
createCanvas(1280,720);
for (i=0; i<ku.length; i++) {
k3 = split(ku[i], " ");
kami[i] = k3[0]; naka[i] = k3[1]; simo[i] = k3[2];
}
sz=sx; sw=0;
for (i=0; i<4; i++) {
sw=int(random(2));
sz=sx-int(random(50));
//c = color(random(255),random(255),random(255),255*0.8);
c = color(20,20,20,160)
sp = int(random(1,4));
kw = ku[int(random(ku.length))]
newWord = new word(random(width), random(height), kw, sz, c, sp, sw);
words.push(newWord);
//print(kw);
}
frameRate(10);
}
function draw() {
background("white");
fill("white");
for (i = 0; i < words.length; i++) {
// much cleaner!
words[i].display();
words[i].update();
}
if (keyIsPressed) {
sz=200; sp=1; sw=0;
c = color(255,0,0,200);
newWord = new word(mouseX, mouseY, "芭蕉", sz, c, sp, sw);
words.push(newWord);
}
}
//function mousePressed() {
document.onclick=function(){
words=[];
sz=sx; sw=0;
for (i=0; i<4; i++) {
sw=int(random(2));
sz=sx-int(random(50));
c = color(20,20,30,160)
sp = int(random(1,4));
kw = ku[int(random(ku.length))]
newWord = new word(random(width), random(height), kw, sz, c, sp, sw);
words.push(newWord);
//print(kw);
}
}
document.ondblclick=function(){
words=[];
sz=sx; sw=0;
for (i=0; i<4; i++) {
sw=int(random(2));
sz=sx-int(random(50));
c = color(20,20,30,160)
sp = int(random(1,4));
//kw = ku[int(random(ku.length))]
kw = kami[int(random(ku.length))] + " " + naka[int(random(ku.length))] + " " + simo[int(random(ku.length))];
newWord = new word(random(width), random(height), kw, sz, c, sp, sw);
words.push(newWord);
// print(kw);
}
}
/*
document.ondblclick=function(){
for (i=0; i<50; i++) {
kw = kami[int(random(ku.length))] + " " + naka[int(random(ku.length))] + " " + simo[int(random(ku.length))];
print((i+1) + " " + kw);
}
}
*/