xxxxxxxxxx
263
// press space to cycle screens
var screen = 1
var screens = 2
var noiseRes = 50
var noiseMatrix = [] // noiseMatrix[x][y][z]
var blinkX = 7
var blinkY = 3
var blinkArray = []
function preload(){
font = loadFont('/WorkSans-Regular.ttf')
}
function setup() {
createCanvas(600, 600);
// create a noiseRes x noiseRes x noiseRes matrix of noise values
for(let x = 0; x < noiseRes; x++){
noiseMatrix[x] = []
for(let y = 0; y < noiseRes; y++){
noiseMatrix[x][y] = []
for(let z = 0; z < noiseRes * 2; z++){
noiseMatrix[x][y][z] = noise((1/noiseRes)*x,(1/noiseRes)*y,(1/noiseRes)*z)
}
}
}
// initialize blink array
for(let x = 0; x < blinkX; x++){
blinkArray[x] = []
for(let y = 0; y < blinkY; y++){
let rand = random(1,100)
if(rand > 90){
blinkArray[x][y] = [true, 255]
} else {
blinkArray[x][y] = [false, 0]
}
}
}
}
var DTcount = 0;
var sineSpeed = Math.PI/10
var acInteg = 500
function keyPressed(){
if(keyCode == 32) screen++
if(screen > screens) screen = 1
}
function draw() {
background(20);
DTcount += round(deltaTime/1000,3)
if(screen == 1){
angleMode(RADIANS)
// value that goes up and down over time
let sineVal = sin(DTcount*sineSpeed)*0.5+0.5
let noiseAvg = 0
// go up and down the matrix, and draw a grid of squares with brightness corresponding to the value of the noise at that position
for(let x = 0; x < noiseRes; x++){
for(let y = 0; y < noiseRes; y++){
let noiseMult = noiseMatrix[x][y][floor(sineVal*noiseRes*2)]
noiseAvg += noiseMult
noiseMult = noiseMult * 2 - 0.5
fill(140 * noiseMult,
120 * noiseMult,
0 * noiseMult)
noStroke()
rect((600/noiseRes)*x,(600/noiseRes)*y,600/noiseRes,600/noiseRes)
}
}
noiseAvg /= (noiseRes * noiseRes)
noFill()
for(let x = 0; x < blinkX; x++){
for(let y = 0; y < blinkY; y++){
let rand = random(1,200)
// randomly switch the lights on or off, turning off is more likely
if(rand >= 199){
let rand2 = random(1,4)
if(rand2 >= 3){
blinkArray[x][y][0] = true
} else {
blinkArray[x][y][0] = false
}
}
// if the light is on, increase its alpha until it's at the maximum, otherwise set it to zero
if(blinkArray[x][y][0] == false){
blinkArray[x][y][1] = 0
} else {
blinkArray[x][y][1] += 20
if(blinkArray[x][y][1] < 100){
blinkArray[x][y][1] = 100
}
if(blinkArray[x][y][1] > 245){
blinkArray[x][y][1] = 245
}
}
// randomly set a light's alpha to zero, without turning it off, resulting in a flicker affect
if(rand <= 3){
blinkArray[x][y][1] = 0
}
// draw the circles
strokeWeight(5)
stroke(color(160,150,0,blinkArray[x][y][1]))
ellipse(80 + x*30, 50 + y*30, 20,20)
}
}
// that thing in the middle
noFill()
stroke(160,150,0)
strokeWeight(2)
ellipse(300,300,200,200)
for(let r = 0; r < 2; r++){
line(
300 + ( sin(sineVal * 2*PI + (PI/2 * r) + PI/4) * 100 ),
300 + ( cos(sineVal * 2*PI + (PI/2 * r) + PI/4) * 100 ),
300 + ( sin(sineVal * 2*PI + (PI/2 * r) + PI/4) * -100 ),
300 + ( cos(sineVal * 2*PI + (PI/2 * r) + PI/4) * -100 )
)
for(let i = 2; i <= 5; i++){
line(
300 + ( sin(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * 100 ),
300 + ( cos(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * 100 ),
300 + ( sin(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * 150 ),
300 + ( cos(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * 150 )
)
line(
300 + ( sin(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * -100 ),
300 + ( cos(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * -100 ),
300 + ( sin(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * -150 ),
300 + ( cos(sineVal * 2*PI * i + (PI/2 * r) + PI/4) * -150 )
)
}
}
acInteg -= noiseRes/2
acInteg += round(sineVal*noiseRes,2)
noStroke()
fill(0,0,0)
rect(0, 495, 450, 95)
fill(160,150,0)
textSize(15)
textAlign(LEFT,BOTTOM)
text("actuator position: " + round((sineVal*noiseRes - 40) * 2 ,2) + " m", 20, 520)
fill(round(acInteg,3)<1000?color(255,20,0):color(160,150,0))
text("actuator integrity: " + round(acInteg,3), 20, 540 )
fill(160,150,0)
text("actuator decay: " + -round(round(sineVal*noiseRes,2) - noiseRes/2 ,2) + " u/s", 20, 560)
text("void flux: " + noiseAvg*2, 20, 580)
}
if(screen == 2){
let stripeThickness = 30
let stripeAngle = 45
angleMode(DEGREES)
textFont("Work Sans")
background(5,5,10)
fill(255,255,0)
triangle(120 + cos(-90)*100, 300 + sin(-90)*100,
120 + cos(30)*100, 300 + sin(30)*100,
120 + cos(150)*100, 300 + sin(150)*100)
fill(5,5,10)
triangle(120 + cos(-90)*90, 300 + sin(-90)*90,
120 + cos(30)*90, 300 + sin(30)*90,
120 + cos(150)*90, 300 + sin(150)*90)
textAlign(CENTER,CENTER)
fill(255,255,0)
textSize(100)
text("!",120,300)
noStroke()
fill(255,255,0)
stroke(255,255,0)
strokeWeight(1)
let xOffset = (DTcount * 15) % (2 * stripeThickness) - (stripeThickness * 4)
for(let i = 0; i < ceil(((300 + (stripeThickness/2))/(stripeThickness*2))) + 1; i++){
xOffset += 2 * stripeThickness
triangle( 250 + xOffset, 240,
250 + xOffset + stripeThickness, 240,
250 + xOffset + sin(stripeAngle)*stripeThickness, 200)
triangle(250 + xOffset + sin(stripeAngle)*stripeThickness, 200,
250 + xOffset + stripeThickness + sin(stripeAngle)*stripeThickness, 200,
250 + xOffset + stripeThickness, 240)
}
strokeWeight(2.5)
stroke(5,5,10)
fill(5,5,10)
rect(248 - (stripeThickness * 2),200,(stripeThickness * 2),40)
rect(552,200,(stripeThickness * 4),40)
noStroke()
fill(255,255,0)
rect(325,200,150,40)
textAlign(CENTER,CENTER)
fill(5,5,10)
textSize(30)
text("WARNING",250,200,300,40)
fill(255,255,0)
textSize(18)
text("SYSTEMS CRITICALLY UNSTABLE",250,255,300,40)
textSize(22)
text("PLEASE STAND BY",250,255,300,110)
noFill()
stroke(255,255,0)
strokeWeight(2)
rect(250,200,300,150)
line(250,240,550,240)
}
if(screen == 3){
}
fill(255)
noStroke()
// text(round(1/(deltaTime/1000)),20,20)
// FPS counter
}