Ciao 访客, welcome back to old school! :p
boolean shutter;void setup() { size(500, 500); background(255); smooth(); rectMode(CENTER);}void draw() { if (mouseX > width/2-50 && mouseX < width/2+50 && mouseY > height/2-25 && mouseY < height/2+25) { fill(255, 0, 255); } else { fill(255,0,255); } if (shutter) { fill(255, 255, 0); } rect(width/2, height/2, 100, 50);}void mousePressed() { if (mouseX > width/2-50 && mouseX < width/2+50 && mouseY > height/2-25 && mouseY < height/2+25) { shutter = !shutter; }}
我思路不清楚 一碰到boolean 就不知道怎么弄了 还是贴下吧
void draw() { if (shutter) { fill(255, 255, 0); }else{ fill(255, 0, 255); } rect(width/2, height/2, 100, 50);}
int x;int y;boolean shutter;void setup() { size(640, 360); frameRate(30); smooth(); shutter = false;}void draw() { background(#AFC14C); for (int i = 0; i < 3; i = i+1) { x=100+i*100+i*20; y=100+i*20; float d = dist(0, 180, mouseX, mouseY); noStroke(); if (shutter) { fill(#D30D2B); } else { fill(52+d, 103, 31); } ellipse(x+100, y-5, 90+i*10, 90+i*10); stroke(#4D2D05); strokeWeight(2); line(x+100, y-30, x+100, y+100); line(x+90, y-20, x+100, y-10); line(x+75, y+5, x+100, y+30); line(x+100, y+10, x+115, y-5); noStroke(); fill(#D30D2B); rectMode(CENTER); rect(100, 270, 40, 20); }}void mousePressed() { if ((mouseX>80)&&(mouseX<120)) { if ((mouseY>260)&&(mouseY<280)) { shutter = !shutter; } }}
int p;void setup(){ size(500,500,P3D); background(0); lights();}void draw(){ //draw Button fill(150,150,0); rect(40,40,50,50); fill(0,150,0); rect(40,100,50,50); fill(150,100,240); rect(40,160,50,50); if(mousePressed == true) { if(mouseX>40 && mouseX<90){ if(mouseY>40 && mouseY<90){ p = 1; println(p); } else if(mouseY>100 && mouseY<150){ p = 2; println(p); }else if(mouseY>160 && mouseY<210){ p = 3; println(p); } } } if(p==1){ fill(0); rect(150,40,350,350); fill(150,150,0); pushMatrix(); translate(250,250,0); sphere(100); popMatrix(); } if(p==2){ fill(0); rect(150,40,350,350); fill(0,150,0); pushMatrix(); translate(250,250,0); sphere(100); popMatrix(); } if(p==3){ fill(0); rect(150,40,350,350); fill(150,100,240); pushMatrix(); translate(250,250,0); sphere(100); popMatrix(); }}
@钱 卓 韵一个if()内的条件可以有多个&&或是||。所以你的mousePressed() 内的判断可以直接写成if ((mouseX>80)&&(mouseX<120)&&(mouseY>260)&&(mouseY<280)) {}另外你可以用DAY3 教的内容来自己定义一个drawTree() 的函数。
int x;int y;boolean shutter;void setup() { size(640, 360); frameRate(30); smooth(); shutter = false;}void draw() { background(#AFC14C); float d = dist(0, 180, mouseX, mouseY); noStroke(); if (shutter) { fill(#D30D2B); } else { fill(52+d, 103, 31); } drawTree(100, 100, 1); drawTree(170, 200, 4); drawTree(350, 150, 2); noStroke(); fill(#D30D2B); rectMode(CENTER); rect(610, 340, 40, 20);}void drawTree(float x_, float y_, int i) { noStroke(); ellipse(x_+100, y_-5, 90+i*10, 90+i*10); stroke(#4D2D05); strokeWeight(2); line(x_+100, y_-30, x_+100, y_+100); line(x_+90, y_-20, x_+100, y_-10); line(x_+75, y_+5, x_+100, y_+30); line(x_+100, y_+10, x_+115, y_-5);}void mousePressed() { if ((mouseX>590)&&(mouseX<630)&&(mouseY>330)&&(mouseY<350)) { shutter = !shutter; }}