xxxxxxxxxx
116
let server="https://tdb01.ruc.dk/tdb-api/?q=";
let img=[];
let rows=[];
let nodes=[];
let led=[];
let x = 0;
let y = 0;
let x1 = 0;
let y1 = 0;
let Stikord = "Covid19";
let farve = "";
function setup() {
createCanvas(600, 600);
imageMode(CENTER);
rectMode(CENTER);
textAlign(CENTER);
textSize(15)
loadJSON( server+ "select parti, partifarve, profile_image_url, count(*) tweet from tweet natural join user where text like '%25"+Stikord+"%25' group by parti", gotdata1 );
}
function gotdata1(data){
rows=data;
for(i =0;i<rows.length;i++) { let d=map(rows[i].tweet, 0, 110, 0, 25)
x = width/2 + cos(i*2*PI/10)*2*width/5;
y = height/2 + sin(i*2*PI/10)*2*height/5;
img[i]= loadImage("https://tdb01.ruc.dk/tdb-api/img/"+rows[i].user+".jpg");
nodes[i]=new Node(rows[i].user,rows[i].profile_image_url,rows[i].partifarve,x,y, rows[i].tweet);
print(d);
}
loadJSON( server+ "select parti, partifarve, profile_image_url, count(*) tweet from tweet natural join user where text like '%25"+Stikord+"%25' group by parti", gotdata2 );
}
function gotdata2(data){
rows=data;
print(rows.length);
x1 = width/2;
y1 = height/2;
for (let i=0; i<rows.length; i++) {
x = width/2 + cos(i*2*PI/10)*2*width/5;
y = height/2 + sin(i*2*PI/10)*2*height/5;
led[i] = new Led(Stikord,rows[i].partifarve,x1,y1,x,y);
}
}
function draw() {
background(50);
for (let i=0; i<nodes.length; i++){
nodes[i].tegn();
}
for (let i=0; i<led.length; i++){
led[i].tegn();
}
text(Stikord,x1,y1);
}
class Led {
constructor(text, color, x1, y1, x, y) {
this.text=text;
this.col=color;
this.x1=x1;
this.y1=y1;
this.x=x;
this.y=y;
}
tegn(){
push();
stroke(this.col);
//strokeWeight(10);
strokeWeight(this.d);
line(this.x,this.y,this.x1,this.y1);
//print(this.x,this.y,this.x1,this.y1);
pop();
}
}
class Node {
constructor(text, img_link, color, x, y, tweet) {
this.text=text;
this.img=loadImage(img_link);
this.x=x;
this.y=y;
this.col=color;
this.tweet = tweet;
this.d = map(tweet, 0, 110, 0, 25)
}
tegn(){
stroke(this.col);
fill(this.col);
rect(this.x,this.y,65,65);
image(this.img, this.x, this.y, 55, 55);
noStroke();fill(255);
text(this.text,this.x,this.y+40);
}
}