let planeImage
var easycam;
let eyex=200, eyey=100, eyez=200;
let cx=100, cy=10, cz=100;
let angle = 339;
let dx = 1.0, dy=1.0, dz = 1.0;
let pg =[];
let tv;
let p1, p2, p3, p4, p55, p6, p7, p8;
let d1, d2, d3, d4, d5, d6, d7, d8;
let shortWall, wall, wallN, wallS, s;
function preload() {
planeImage = loadImage('data/plane.jpg');
wall = loadImage ("data/sheet.jpg");
p1 = loadImage ("data/sheet.jpg");
p2 = loadImage ("data/sheet.jpg");
p3 = loadImage ("data/sheet.jpg");
p4 = loadImage ("data/sheet.jpg");
p55 = loadImage ("data/sheet.jpg");
p6 = loadImage ("data/sheet.jpg");
s = loadImage ("data/sheet.jpg");
tv = createVideo('data/splick.mp4');
tv.loop();
//tv.volume(50);
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
setAttributes('antialias', true);
//easycam = createEasyCam();
textureMode(NORMAL);
perspective(1.15, float(width)/float(height), 10., 40000.);
pg[0] = createGraphics(1920, 1080, WEBGL);
keyPressed();
}
// function windowResized() {
// resizeCanvas(windowWidth, windowHeight);
// easycam.setViewport([0,0,windowWidth, windowHeight]);
// }
function keyPressed ()
{
// console.log(keyCode);
// Motion keys - avatar moves, viewpoint changes.
if (angle<0) angle = angle + 360.0;
else if (angle > 360.0) angle = angle - 360.0;
dx = bigcos(angle);
cx = dx*20000.0;
dz = bigsin(angle);
cz = dz*20000.0;
//console.log(eyex,eyey,eyez,angle,dx,dz);
if (eyey < 20) eyey = 20.0; // Enforce depth rules.
else if (eyey > 500.0) eyey = 500.0;
if (eyex < 0) eyex = 1;
if (eyex > 1000) eyex = 999;
if (eyez < 0) eyez = 0;
if (eyez > 1000) eyez = 1000;
}
function draw() {
// dx = mouseX;
//dy = mouseY;
background(0);
pg[0].background(0);
pg[0].push();
pg[0].rotateZ(PI);
pg[0].translate(-pg[0].width / 2, -pg[0].height / 2,0);
//D
pg[0].image(tv,0,0);
pg[0].ellipse(150, 75, 60, 60);//Error in this place!!! :sob:
//
// pg[0].strokeWeight(4);
pg[0].pop();
//pg[0].rect(pg[0].width / 2, pg[0].height / 2, 50, 50);
push()
translate(100,100,10);
image(pg[0],0,0,192,108);
pop();
if (keyIsPressed === true) {
if (keyCode == UP_ARROW) // Move 'forward'
{
eyex += 2*dx; eyez += 2*dz;
} else if (keyCode == DOWN_ARROW) // Move 'backward
{
eyex -= 1*dx; eyez -= 2*dz;
}
if (keyCode == LEFT_ARROW) // Turn left a unit (CCW)
{
angle = angle + 1.0;
} else if (keyCode == RIGHT_ARROW) // Turn right a unit (CW)
angle = angle - 1.0;
if (key == 'w') eyey = eyey + 10; // UP
if (key == 's') eyey = eyey - 10; // DOWN
if (angle<0) angle = angle + 360.0;
else if (angle > 360.0) angle = angle - 360.0;
dx = bigcos(angle);
cx = dx*20000.0;
dz = bigsin(angle);
cz = dz*20000.0;
//console.log(eyex,eyey,eyez,angle,dx,dz);
if (eyey < 20) eyey = 20.0; // Enforce depth rules.
else if (eyey > 500.0) eyey = 500.0;
if (eyex < 0) eyex = 1;
if (eyex > 1000) eyex = 999;
if (eyez < 0) eyez = 0;
if (eyez > 1000) eyez = 1000;
}
camera(eyex, eyey, eyez, cx, cy, cz, 0, -1, 0);
noStroke();
ambientLight(255);
prism (0, 0, 0, 1000, 500, 1000, p6, p1, p2, p3, s);
drawWall1();
drawWall2();
normalMaterial();
// push();
// translate(0, 0, 0);
// // rotateZ(frameCount * 0.01);
// rotateX(PI/2);
// //rotateY(frameCount * 0.01);
// texture(planeImage);
// plane(300);
// pop();
//
//
// // normalMaterial();
// fill(255);
// push();
// translate(0, -150, 150);
// // rotateZ(frameCount * 0.01);
// // rotateX(PI/2);
// //rotateY(frameCount * 0.01);
// //texture(planeImage);
// fill(230);
// plane(300);
// pop();
//
// push();
// translate(0, -150, -150);
// // rotateZ(frameCount * 0.01);
// // rotateX(PI/2);
// //rotateY(frameCount * 0.01);
// //texture(planeImage);
// fill(230);
// plane(300);
// pop();
//
// push();
// translate(150, -150, 0);
// // rotateZ(frameCount * 0.01);
// rotateY(PI/2);
// //rotateY(frameCount * 0.01);
// //texture(planeImage);
// fill(230);
// plane(300);
// pop();
// push();
// translate(-150, -150, 0);
// // rotateZ(frameCount * 0.01);
// rotateY(PI/2);
// //rotateY(frameCount * 0.01);
// //texture(planeImage);
// fill(230);
// plane(300);
// pop();
}
function drawWall1()
{
push();
// North wall
translate (0, 0, dz);
beginShape();
if (p4 != null) texture(p4);
vertex (200, 0, 500, 0, 1);
vertex (800, 0, 500, 1, 1);
vertex (800, 300, 500, 1, 0);
vertex (200, 300, 500, 0, 0);
endShape();
pop();
}
function drawWall2()
{
push();
// North wall
translate (0, 0, dz);
beginShape();
if (p5 != null) texture(p55);
vertex (200, 0, 501, 0, 1);
vertex (800, 0, 501, 1, 1);
vertex (800, 300, 501, 1, 0);
vertex (200, 300, 501, 0, 0);
endShape();
pop();
}
function prism (x,y,z,dx,dy,dz,north,south,east,west,top)
{
push();
translate (x, y, z);
// North
beginShape();
if (north != null) texture(north);
vertex ( 0, 0, dz, 0, 1);
vertex (dx, 0, dz, 1, 1);
vertex (dx, dy, dz, 1, 0);
vertex ( 0, dy, dz, 0, 0);
endShape();
// South
beginShape();
if (south != null) texture(south);
vertex ( 0, 0, 0, 0, 1);
vertex (dx, 0, 0, 1, 1);
vertex (dx, dy, 0, 1, 0);
vertex ( 0, dy, 0, 0, 0);
endShape();
// East
beginShape();
if (east != null) texture(east);
vertex (dx, 0, 0, 0, 1);
vertex (dx, 0, dz, 1, 1);
vertex (dx, dy, dz, 1, 0);
vertex (dx, dy, 0, 0, 0);
endShape();
// West
beginShape();
if (west != null) texture(west);
vertex (0, 0, 0, 0, 1);
vertex (0, 0, dz, 1, 1);
vertex (0, dy, dz, 1, 0);
vertex (0, dy, 0, 0, 0);
endShape();
// Top
beginShape();
if (top != null) texture(top);
else fill (160, 82, 45); // Sienna
vertex ( 0, dy, 0, 0, 0);
vertex (dx, dy, 0, 1, 0);
vertex (dx, dy, dz, 1, 1);
vertex ( 0, dy, dz, 0, 1);
endShape();
// Bottom
beginShape();
if (planeImage != null) texture(planeImage);
vertex ( 0, 0, 0, 0, 0);
vertex (dx, 0, 0, 1, 0);
vertex (dx, 0, dz, 1, 1);
vertex ( 0, 0, dz, 0, 1);
endShape();
translate (-x, -y, -z);
pop();
}
function bigsin (s)
{
if (s > 360.0) s = s - 360.0;
else if (s < 0.0) s = s + 360.0;
if (s <= 90.0) return sin (s*DEG_TO_RAD);
else if (s<=180.0) return sin ((180.0-s)*DEG_TO_RAD);
else if (s<=270.0) return -sin((s-180.0)*DEG_TO_RAD);
else return -sin((360.0-s)*DEG_TO_RAD);
}
function bigcos (s)
{
if (s> 360.0) s = s - 360.0;
else if (s<0.0) s = s+ 360.0;
if (s <= 90.0) return cos (s*DEG_TO_RAD);
else if (s<=180.0) return -cos ((180.0-s)*DEG_TO_RAD);
else if (s<=270.0) return -cos((s-180.0)*DEG_TO_RAD);
else return cos((360.0-s)*DEG_TO_RAD);
}
Hi guys!There is an error that can’t be solved!Who can help me!
p5.js:55792 Uncaught TypeError: Cannot read property ‘grid’ of undefined
at _main.default.Graphics._main.default._renderEllipse (p5.js:55792)
at _main.default.Graphics._main.default.ellipse (p5.js:55732)
at draw (sketch.js:81)
at p5._main.default.redraw (p5.js:58911)
at _draw (p5.js:51424)