xxxxxxxxxx
64
let mothsX;
let mothsY;
let prey;
let labels = ['škola', 'robota', 'ženy']
let desireX = [0, 0, 0]
let desireY = [0, 0, 0]
let noiseVal = 4;
let desireVal = 0.02;
let offSet;
function setup() {
offSet = [random(1000),random(1000),random(1000)]
prey = {x: random(width), y: random(height)}
mothsX = [random(width), random(width), random(width)]
mothsY = [random(height), random(height), random(height)]
createCanvas(windowWidth, windowHeight);
sliderDesire = createSlider(0, 100, 50);
sliderDesire.position(10, 10);
sliderDesire.style('width', '80px');
sliderNoise = createSlider(0, 100, 50);
sliderNoise.position(120, 10);
sliderNoise.style('width', '80px');
colorMode(HSB)
background(220, 90, 10)
noStroke()
}
function generatePositions() {
for(let i = 0; i < mothsX.length; i++) {
mothsX[i] = mothsX[i] + desireX[i] + map(noise(frameCount / 100 + offSet[i]), 0, 1, -noiseVal, noiseVal)
}
for(let i = 0; i < mothsY.length; i++) {
mothsY[i] = mothsY[i] + desireY[i] + map(noise(0, frameCount / 100 + offSet[i]), 0, 1, -noiseVal, noiseVal)
}
}
function calculateDesires() {
for(let i = 0; i < mothsX.length; i++) {
desireX[i] = (prey.x - mothsX[i]) * desireVal
}
for(let i = 0; i < mothsY.length; i++) {
desireY[i] = (prey.y - mothsY[i]) * desireVal
}
}
function drawMoths() {
fill(noise(frameCount/100) * 360, 90, 90)
for(let i = 0; i < mothsX.length; i++) {
text(labels[i], mothsX[i], mothsY[i])
}
}
function draw() {
textSize(24)
noiseVal = map(sliderNoise.value(), 0, 100, 0, 20)
desireVal = map(sliderDesire.value(), 0, 100, 0, 0.1)
fill(200, 30, 100)
prey = {x: noise(frameCount /50) * width, y: noise(frameCount/100, frameCount/50) * height}
text('ja', prey.x, prey.y)
background(220, 90, 10, 0.3);
drawMoths()
calculateDesires()
generatePositions()
}