xxxxxxxxxx
233
let vOff; //viewer offset
let vAng = 0;
let vAcc;
let wallH = 300;
let walls = []
let movespeed = 10
let turnspeed = 1
let showHUD = false
let wallDebug = false
let wallCol = [180, 180, 130]
let ceilCol = [180, 180, 170]
let floorCol = [90, 90, 80]
let carpet
let piper
let wp
let spacer = 10
let depth = 1800
let shadowBegin = 500
let forward = 10
let drop = []
function preload() {
carpet = loadImage('carpet.jpeg')
piper = loadImage('piper.png')
wp = loadImage('br_wall.png')
pc = loadImage('popcorn.jpg')
}
function getDir(x, y) {
let x2 = x*cos(vAng) - y*sin(vAng)
let y2 = x*sin(vAng) + y*cos(vAng)
return [x2, y2]
}
function keyTyped() {
let d = [0, 0]
if (key === 'w') {
d[1] += movespeed
} if (key === 's') {
d[1] -= movespeed
} if (key === 'a') {
d[0] -= movespeed
} if (key === 'd') {
d[0] += movespeed
} if (key === 'q') {
vAng += PI/(pow(10, turnspeed))
} if (key === 'e') {
vAng -= PI/(pow(10, turnspeed))
}
vAcc.x += d[0]*cos(vAng) - d[1]*sin(vAng)
vAcc.y += d[0]*sin(vAng) + d[1]*cos(vAng)
}
function setup() {
createCanvas(600, 600, WEBGL);
vOff = createVector(0,0)
vAcc = createVector(0,0)
gl = this._renderer.GL;
gl.disable(gl.DEPTH_TEST);
walls.push(new Wall(-50, depth, -50, -1000, [wallCol[0], wallCol[1], wallCol[2]], s=true, flip=true))
walls.push(new Wall(50, -depth, 50, 1000, [wallCol[0], wallCol[1], wallCol[2]], s=true))
//walls.push(new Wall(-50, -depth, 50, -depth, [20,20,20, 40]))
for (let i=0;i<250;i++) {
walls.push(new Wall(-50, shadowBegin - i*spacer, 50, shadowBegin - i*spacer, [20-2*i/25, 20-2*i/25, 10-i/25, i/50]))
}
//rectMode(CENTER)
}
function draw() {
walls[0].pos1.y=-depth
walls[0].pos2.y=-depth
walls[1].pos1.y=-depth
walls[1].pos2.y=-depth
walls[0].theta += 0.00009
walls[1].theta -= 0.00009
// walls[1].len += forward/10
//walls[0].len += forward/10
background(0);
vAcc.mult(0.9)
vOff.add(vAcc)
//spacer += 1/2
spacer *= 1.0001
depth += forward*0.9
shadowBegin = -vOff.y+700
ambientLight(90)
spotLight(255, 255, 255, 0,0, 800, 0,0, -1, PI/2*(1+noise(frameCount)), 1)
push()
rotateY(vAng)
rotateX(PI/2)
translate(0, 300, -250)
for (let i=0;i<50;i++) {
let x = 0
if (frameCount > 20) {
x = floor(frameCount/30)
}
let r = 3
image(carpet, -100-r*frameCount/2, -2*(i+x)*200+vOff.y, 200+r*frameCount, 200)
image(carpet, -100-r*frameCount/2, -2*(i+x)*200+vOff.y, 200+r*frameCount, -200)
}
fill(0, 90)
translate(-30,400,200)
rect(0, 0, 60, -2000)
pop()
//floor + ceil
push()
rotateX(PI/2)
//translate(vOff.x, vOff.y, -wallH/2)
noStroke()
translate(0, -400, -wallH/2)
fill(floorCol[0], floorCol[1], floorCol[2])
//plane(4000, 4000)
fill(ceilCol[0], ceilCol[1], ceilCol[2])
translate(0, 0, wallH)
//plane(4000, 4000)
pop()
push()
rotateY(vAng)
translate(-50, -wallH/2,-depth + frameCount*1.2 + vOff.y)
//image(piper, 0, 0, 100, wallH)
translate(0, 0, 2)
fill(0, 250-frameCount/5)
//rect(0, 0, 100, wallH)
pop()
push()
rotateY(vAng)
rotateX(PI/2)
translate(0, 200, 300)
for (let i=0;i<50;i++) {
let x = 0
if (frameCount > 20) {
x = floor(frameCount/60)
}
let r = 3.5
image(pc, -100-r*frameCount/2, -2*(i+x)*400+vOff.y, 200+r*frameCount, 400)
image(pc, -100-r*frameCount/2, -2*(i+x)*400+vOff.y, 200+r*frameCount, -400)
}
pop()
translate(0, 10, 0)
fill(20, 100)
rect(-100-3.5*frameCount/2, -depth, 200+3.5*frameCount, depth)
rotateY(vAng)
push()
//rotateY(vAng)
let d = frameCount*1.1 + vOff.y
translate(-50, -wallH/2, -depth + d)
//d = walls[0].pos1.y
let r = 1.1
console.log(d*tan(-walls[0].theta+PI/2))
image(piper, sqrt(d)*tan(-walls[0].theta+PI/2), 0, 100 + sin(walls[0].theta), wallH)
translate(0, 0, 2)
fill(0, 250-frameCount/5)
rect(0, 0, 100, wallH)
pop()
walls[0].show()
walls[1].show()
for (let w=2;w<walls.length;w++) {
walls[w].pos1.y = shadowBegin - w*spacer
walls[w].pos2.y = shadowBegin - w*spacer
walls[w].pos1.x -= frameCount*0.1 - (frameCount-1)*0.1
walls[w].len += frameCount*0.2 - (frameCount-1)*0.2
if (walls[w].pos1.y < -depth + 800 && !drop.includes(w)) {
drop.push(w)
console.log(w)
}
if (!drop.includes(w)) {
walls[w].show()
}
}
rotateY(-vAng)
//imageLight(carpet)
let cf = depth + 1800
vOff.y += forward * (vOff.y < (cf))
if (vOff.y > cf) {
console.log('slow', cf, vOff.y)
}
if (vOff.y >= depth - 600) {
noLoop()
}
forward *= 1.001
//HUD
if (showHUD) {
push()
translate(-110, 80, 500)
stroke(255)
fill(0)
square(0, 0, 30)
point(15, 15)
for (let w of walls) {
let gd1 = getDir(w.pos1.x, w.pos1.y)
let gd2 = getDir(w.pos2.x, w.pos2.y)
line(15+(gd1[0]+vOff.x)/50, 15+(-gd1[1]+vOff.y)/50, 15+(gd2[0]+vOff.x)/50, 15+(-gd2[1]+vOff.y)/50)
}
pop()
}
}