xxxxxxxxxx
114
"use strict";
const HTTP = 'https://',
//PROX = 'YaCDN.org/', MODE = 'proxy/',
PROX = 'api.AllOrigins.win/', MODE = 'raw?url=',
SITE = 'EkstraBladet.dk/', FOLD = 'rssfeed/', QRY = 'mest_laeste/',
LINK = HTTP + PROX + MODE + HTTP + SITE + FOLD + QRY,
FILE = 'mest_laeste.xml',
REMOTE = true,
TAG = 'title',
LIST = 'ol', ITEM = 'li',
titles = [];
let xml;
var x = 0;
var y = 0;
var stepSize = 5.0;
var font = 'Georgia';
var letters = '...';
var fontSizeMin = 10;
var angleDistortion = 0.0;
var articleIndex =0;
var counter = 0;
function preload() {
console.info(LINK);
//xml = loadXML(REMOTE && LINK || FILE, print, console.warn);
//xml = loadXML("https://api.AllOrigins.win/raw?url=https://EkstraBladet.dk/rssfeed/Verden_p__vrangen_RSS/",
xml = loadXML("https://api.AllOrigins.win/raw?url=https://EkstraBladet.dk/rssfeed/nyheder/", print, console.warn);
}
function setup() {
createCanvas(displayWidth, displayHeight);
background(255);
cursor(CROSS);
x = mouseX;
y = mouseY;
textFont(font);
textAlign(LEFT);
fill(0);
const items = xml.getChild('channel').getChildren('item');
for (const item of items) {
print(item.listChildren());
titles.push(item.getChild(TAG).getContent());
}
console.log(titles);
}
function draw() {
letters = titles[articleIndex];
if (mouseIsPressed && mouseButton == LEFT) {
var d = dist(x, y, mouseX, mouseY);
textSize(fontSizeMin + d / 2);
var newLetter = letters.charAt(counter);
stepSize = textWidth(newLetter);
if (d > stepSize) {
var angle = atan2(mouseY - y, mouseX - x);
push();
translate(x, y);
rotate(angle + random(angleDistortion));
text(newLetter, 0, 0);
pop();
counter++;
if (counter >= letters.length) counter = 0;
x = x + cos(angle) * stepSize;
y = y + sin(angle) * stepSize;
}
}
}
function mousePressed() {
x = mouseX;
y = mouseY;
}
function mouseClicked() {
counter = 0;
if (articleIndex < titles.length - 1) {
articleIndex++;
} else {
articleIndex = 0;
}
}
function keyReleased() {
if (keyCode == DELETE || keyCode == BACKSPACE) background(255);
}
function keyPressed() {
// angleDistortion ctrls arrowkeys up/down
if (keyCode == UP_ARROW) angleDistortion += 0.1;
if (keyCode == DOWN_ARROW) angleDistortion -= 0.1;
}