0
大家好希望你一切安好如何随机的xhouse
我有问题,我不知道如何使用随机的,这样我每次创建的房子里,我刷新页面X位置变化,使房子出现在不同的X中。
谢谢
这是我的代码;
var floorPos_y;
var xhouse;
var yhouse;
function setup() {
createCanvas(1000, 755);
floorPos_y = height * 3/4; //NB. we are now using a variable for the floor position
xhouse = 0;
yhouse = 0;
var xhouse = random(100, width);
}
function draw() {
background(100, 155, 255); //fill the sky blue
// House Code
//xhouse = 30;
yhouse = 366;
noStroke();
fill(255);
text("house", 100, height * 0.6);
fill(255, 0, 0);
rect(xhouse, yhouse, 180, 200);//main body of the house
fill(165, 42, 42);
triangle(xhouse, yhouse, xhouse + 90, yhouse - 116, xhouse + 180, yhouse);// tope of the house
fill(255, 255, 220);
rect(xhouse + 5, yhouse + 24, 55, 60);
rect(xhouse + 110, yhouse + 24, 55, 60);
fill(0, 0, 230);
rect(xhouse + 60, yhouse + 114, 50, 80);
fill(255, 255, 30);
ellipse(xhouse + 100, yhouse + 164, 13, 13);
}
function mousePressed() {
xposition = mouseX
yposition = mouseY
}
当你运行这段代码时会发生什么? –
我刚刚发现这是我的错误,谢谢。 –