180 lines
5.2 KiB
HTML
180 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<!--<meta name="description" content="">
|
|
<meta name="keywords" content="">-->
|
|
<meta name="author" content="Victor Giers">
|
|
<meta name="date" content="2019-06-25" scheme="YYYY-MM-DD">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>1makk</title>
|
|
<style>
|
|
body{padding: 0; margin: 0; background-color: gray; position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden;}
|
|
canvas {display: block; overflow: hidden;}
|
|
</style>
|
|
<script src="p5.min.js"></script>
|
|
<script>
|
|
"use strict";
|
|
var width, height;
|
|
|
|
var rate = 200;
|
|
var tickMS = rate;
|
|
var previous;
|
|
var time = 0;
|
|
|
|
var maxEdge;
|
|
var minEdge;
|
|
|
|
var citizen = [];
|
|
var angle = 0;
|
|
|
|
let center, ring, ringBuffer, mask, rotatedMask;
|
|
|
|
const FOLDER = 'data/';
|
|
|
|
function setup() {
|
|
width = window.innerWidth;
|
|
height = window.innerHeight;
|
|
maxEdge = max(width, height);
|
|
minEdge = min(width,height);
|
|
|
|
createCanvas(width,height);
|
|
rotatedMask.imageMode(CENTER);
|
|
imageMode(CENTER);
|
|
textAlign(CENTER);
|
|
|
|
previous = millis();
|
|
|
|
for(var i = 0; i < 20; i ++){
|
|
citizen.push(new Citizen(random(width/2 - minEdge/16, width/2 + minEdge/16), random(height/2-minEdge/4, height/2+minEdge/4), color(255,255,255)));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function preload(){
|
|
center = loadImage(FOLDER + 'center.png');
|
|
|
|
ring = loadImage(FOLDER + 'ring.png', img => {
|
|
ringBuffer = img.get();
|
|
ringBuffer.loadPixels();
|
|
img.loadPixels();
|
|
});
|
|
|
|
mask = loadImage(FOLDER + 'mask.png', img => {
|
|
rotatedMask = createGraphics(img.width, img.height);
|
|
rotatedMask.image(img, 0, 0);
|
|
});
|
|
|
|
}
|
|
function draw() {
|
|
clear();
|
|
maxEdge = max(width,height);
|
|
minEdge = min(width,height);
|
|
angle = atan2(-width/2 + mouseX, -height/2 + mouseY);
|
|
rotatedMask.clear();
|
|
rotatedMask.resetMatrix();
|
|
rotatedMask.translate(ringBuffer.width/2,ringBuffer.height/2);
|
|
rotatedMask.rotate(map(angle, -PI, PI, PI, -PI));
|
|
rotatedMask.image(mask, 0, 0);
|
|
ring.pixels.set(ringBuffer.pixels);
|
|
ring.updatePixels();
|
|
ring.mask(rotatedMask);
|
|
|
|
image(center, width/2,height/2, minEdge/2, minEdge/2);
|
|
image(ring, width/2,height/2, minEdge/2, minEdge/2);
|
|
for(var i = 0; i < citizen.length; i++){ // go with -- here
|
|
citizen[i].update();
|
|
}
|
|
|
|
var current = millis();
|
|
var elapsed = current - previous;
|
|
previous = current;
|
|
time += elapsed;
|
|
while (time >= tickMS){
|
|
time -= tickMS;
|
|
var side = int(random(0,4));
|
|
var randcolor = color(random(0,255), random(0,255), random(0,255));
|
|
switch (side){
|
|
case(0): citizen.push(new Citizen(random(0,width), -30, randcolor));
|
|
break;
|
|
case(1): citizen.push(new Citizen(random(0,width), height+30, randcolor));
|
|
break;
|
|
case(2): citizen.push(new Citizen(-30, random(0,height), randcolor));
|
|
break;
|
|
case(3): citizen.push(new Citizen(width+30, random(0,height), randcolor));
|
|
break;
|
|
}
|
|
tickMS = random(rate/100,2*rate-(rate/100));
|
|
}
|
|
}
|
|
|
|
|
|
class Citizen{
|
|
constructor(x, y, color, id){
|
|
this.x = x;
|
|
this.y = y;
|
|
this.color = color;
|
|
this.id = citizen.length;
|
|
this.speedX = ((this.x-width/2)*-1)/dist(this.x, this.y, width/2, height/2);
|
|
this.speedY = ((this.y-height/2)*-1)/dist(this.x, this.y, width/2, height/2);
|
|
this.angle = atan2(width/2 - this.x, height/2 - this.y);
|
|
this.range = random(2,minEdge/5.33);
|
|
if(this.angle + 0.4 > PI || this.angle - 0.4 < -PI){
|
|
this.invalid = true;
|
|
this.despawn();
|
|
}
|
|
}
|
|
update(){
|
|
if(this.invalid) this.despawn();
|
|
if(dist(this.x, this.y, width/2, height/2) < minEdge/4 && dist(this.x, this.y, width/2, height/2) > minEdge/5.33){
|
|
if(angle + 0.4 > this.angle && angle - 0.4 < this.angle){
|
|
//fill(0,255,0);
|
|
//text("JUHU", this.x,this.y-30, 40);
|
|
} else {
|
|
this.despawn();
|
|
}
|
|
}
|
|
if(dist(this.x, this.y, width/2, height/2) > this.range){
|
|
this.x += this.speedX;
|
|
this.y += this.speedY;
|
|
}
|
|
fill(this.color);
|
|
ellipse(this.x, this.y, minEdge/40);
|
|
}
|
|
despawn(){
|
|
citizen.splice(this.id,1);
|
|
for(var i = this.id; i < citizen.length; i++){
|
|
citizen[i].id--;
|
|
}
|
|
}
|
|
}
|
|
|
|
function mouseClicked(){
|
|
//citizen.push(new Citizen(mouseX, mouseY, color(255,255,255), citizen.length));
|
|
}
|
|
|
|
window.onresize = function() {
|
|
var w = window.innerWidth;
|
|
var h = window.innerHeight;
|
|
width = w;
|
|
height = h;
|
|
resizeCanvas(width,height);
|
|
for(var i = 0; i < 20; i ++){
|
|
citizen.push(new Citizen(random(width/2 - minEdge/16, width/2 + minEdge/16), random(height/2-minEdge/4, height/2+minEdge/4), color(255,255,255)));
|
|
}
|
|
|
|
for(var i = 0; i < citizen.length; i++){
|
|
citizen[i].speedX = ((citizen[i].x-width/2)*-1)/dist(citizen[i].x, citizen[i].y, width/2, height/2);
|
|
citizen[i].speedY = ((this.y-height/2)*-1)/dist(citizen[i].x, citizen[i].y, width/2, height/2);
|
|
citizen[i].angle = atan2(width/2 - citizen[i].x, height/2 - citizen[i].y);
|
|
citizen[i].range = random(2,minEdge/5.33);
|
|
}
|
|
};
|
|
</script>
|
|
</head>
|
|
<body>
|
|
|
|
</body>
|
|
</html>
|