Spaces:
Sleeping
Sleeping
File size: 1,406 Bytes
13f40ff |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
function setup() {
createCanvas(window.innerWidth, window.innerHeight);
background(153);
textSize(32)
textAlign(CENTER);
text("Loading...", width / 2, height / 2)
}
let txt;
class SMessage {
constructor(send, content) {
this.send = send;
this.content = content;
this.alive = true;
this.x = 0;
this.y = 32;
this.alpha = 255;
}
draw() {
fill(color(0, 0, 0, this.alpha));
textSize(18);
text(`<${this.send}>: ${this.content}`, this.x, this.y);
}
update() {
this.x += 1;
if (this.x > 920) {
this.x = 0;
this.y += 32;
}
}
}
var _messages = [new SMessage("CLIENT", "Connected!")];
const minp = document.querySelector("#message_input");
minp.addEventListener("submit", (evt) => {
_messages.push(new SMessage("Me", msg));
});
const minp3 = document.querySelector("#yomama");
minp3.addEventListener("click", (evt) => {
const _minp = document.querySelector("#message_input");
const val = _minp.value;
_minp.value = "";
_messages.push(new SMessage("Me", msg));
});
socket.on("messag", function(mstr, msg) {
_messages.push(new SMessage(mstr, msg));
console.log(msg)
});
function draw() {
background(153);
textSize(50)
//text(txt, width / 2, height / 2)
_messages.forEach((itm) => {
if (itm) {
itm.draw();
itm.update();
}
});
}
socket.on("update", function(number) {
txt = number
}) |