PHP код:
* Buttons.
*
* Click on one of the shapes to change
* the background color. This example
* demonstates a class for buttons.
*/
color currentcolor;
RectButton rect1, rect2, rect3, rect4, rect5;
boolean locked = false;
void setup()
{
size(800, 600);
smooth();
color baseColor = color(255, 255, 2552);
currentcolor = baseColor;
color buttoncolor = color(255);
color highlight = color(255, 0,0);
// Define and create rectangle button
buttoncolor = color(255, 0,0);
highlight = color(0, 0, 255);
rect1 = new RectButton(585, 387, 140, 86, buttoncolor, highlight);
// Define and create rectangle button
buttoncolor = color(0, 0, 255);
highlight = color(0);
rect2 = new RectButton(439, 387, 140, 86, buttoncolor, highlight);
// Define and create rectangle button
buttoncolor = color(102);
highlight = color(51);
rect3 = new RectButton(289, 387, 140, 86, buttoncolor, highlight);
// Define and create rectangle button
buttoncolor = color(102);
highlight = color(51);
rect4 = new RectButton(146, 387, 140, 86, buttoncolor, highlight);
// Define and create rectangle button
buttoncolor = color(102);
highlight = color(51);
rect5 = new RectButton(4, 387, 140, 86, buttoncolor, highlight);
}
void draw()
{
background(currentcolor);
stroke(255);
update(mouseX, mouseY);
rect1.display();
rect2.display();
rect3.display();
rect4.display();
rect5.display();
}
void update(int x, int y)
{
if(locked == false) {
rect1.update();
rect2.update();
rect3.update();
rect4.update();
rect5.update();
}
else {
locked = false;
}
if(mousePressed) {
if(rect1.pressed()) {
currentcolor = rect1.basecolor;
}
else if(rect2.pressed()) {
currentcolor = rect2.basecolor;
}
else if(rect3.pressed()) {
currentcolor = rect2.basecolor;
}
else if(rect4.pressed()) {
currentcolor = rect2.basecolor;
}
else if(rect5.pressed()) {
currentcolor = rect2.basecolor;
}
}
}
class Button
{
int x, y;
int w, h;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean pressed = false;
void update()
{
if(over()) {
currentcolor = highlightcolor;
}
else {
currentcolor = basecolor;
}
}
boolean pressed()
{
if(over) {
locked = true;
return true;
}
else {
locked = false;
return false;
}
}
boolean over()
{
return true;
}
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
}
else {
return false;
}
}
}
class RectButton extends Button
{
RectButton(int ix, int iy, int iw, int ih, color icolor, color ihighlight)
{
x = ix;
y = iy;
w = iw;
h = ih;
basecolor = icolor;
highlightcolor = ihighlight;
currentcolor = basecolor;
}
boolean over()
{
if( overRect(x, y, w, h) ) {
over = true;
return true;
}
else {
over = false;
return false;
}
}
void display()
{
stroke(255);
fill(currentcolor);
rect(x, y, w, h);
}
}
В твоем примере в порт шлется одна единица (т.е. вообще говоря - в никуда).