Ciao 访客, welcome back to old school! :p
原来是这么用的噢boolean shutterCircle;boolean shutterRect;float circleX = 360;float circleY = 200;float diametersA = 100;float circleRadius = diametersA/2;float changdu = 200;float kuandu = 100;//全局变量设置 void setup(){ size(500,500); smooth();}void draw(){ background(255); noStroke(); fill(31,218,41,55); ellipse(circleX,circleY,diametersA,diametersA);//圆按钮的位置 fill(100,168,210); rect(100,300,changdu,kuandu); //长方形按钮的位置 if(shutterCircle) { background(#484DDE);//设置按后的背景色 } if(shutterRect) { stroke(22,135,38); strokeWeight(10); fill(255,123,21); ellipse(100,100,50,50); } }void mousePressed(){ if(dist(mouseX,mouseY,circleX,circleY)<circleRadius){ shutterCircle = !shutterCircle; } if(100 <= mouseX && mouseX <= 100+changdu && 300 <= mouseY && mouseY <= 300+kuandu){ shutterRect = !shutterRect; }}
//定义圆形按钮的属性float circleX, circleY;float circleRadius = 50;color circleColor = color(31, 218, 41);//定义矩形按钮的属性float rectX, rectY;float rectWidth = 100;float rectHeight= 80;color rectColor = color(100, 168, 210);color bgColor;void setup() { size(500, 500); background(0); smooth(); ellipseMode(RADIUS); rectMode(CENTER); circleX = width/3; circleY = height/2; rectX = width/3*2; rectY = height/2; //绘制按钮 stroke(255); strokeWeight(3); fill(circleColor); ellipse(circleX, circleY, circleRadius, circleRadius); fill(rectColor); rect(rectX, rectY, rectWidth, rectHeight);}void draw() {}void mousePressed() { if (dist(mouseX, mouseY, circleX, circleY)<circleRadius) { bgColor = color(random(255), random(255), random(255));//随机生成背景颜色 background(bgColor);//填充背景颜色 //绘制按钮 stroke(255); strokeWeight(3); fill(circleColor); ellipse(circleX, circleY, circleRadius, circleRadius); fill(rectColor); rect(rectX, rectY, rectWidth, rectHeight); } if (rectX-rectWidth/2 <= mouseX && mouseX <= rectX+rectWidth/2 && rectY-rectHeight/2 <= mouseY && mouseY <= rectY+rectHeight/2) { //随机添加白色圆点 noStroke(); fill(255); ellipse(random(width),random(height),10,10); }}