“点亮led灯”的版本间的差异
(→结果) |
(→程序) |
||
第31行: | 第31行: | ||
LEDButtonByClick | LEDButtonByClick | ||
+ | 注意:代码里包含图片请不要丢掉 | ||
==调试== | ==调试== |
2014年5月5日 (一) 08:36的版本
点亮LED灯
目的本教程将教大家如何用Processing来点亮LED灯。 设备
原理图
程序见 LEDButtonByOver LEDButtonByClick 注意:代码里包含图片请不要丢掉 调试步骤一:解释一下代码: // Declaring two variable of type PImage, a class available to us from the Processing core library. PImage LEDON, LEDOFF; //load two img LEDON = loadImage("LEDON.png"); LEDOFF = loadImage("LEDOFF.png"); Mouse over: // When the mouse is moved, the state of the button is toggled. void mouseMoved() { if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) { button = true; } else { button = false; } } Mouse Click: // When the mouse is pressed, the state of the button is toggled. void mousePressed() { if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) { button = !button; } }
结果鼠标滑过灯泡上方,灯泡会亮起,离开会熄灭,Processing的动画效果是这样的: 鼠标滑过或点击灯泡: 鼠标离开或点击灯泡: 视频 |