“点亮led灯”的版本间的差异
(→设备) |
(→结果) |
||
第82行: | 第82行: | ||
[[File:processingOverLEDON.jpg|600px|center|thumb]] | [[File:processingOverLEDON.jpg|600px|center|thumb]] | ||
鼠标离开或点击灯泡: | 鼠标离开或点击灯泡: | ||
− | [[File: | + | [[File:processingOverLEDOFF.jpg|600px|center|thumb]] |
==视频== | ==视频== |
2014年5月5日 (一) 07:44的版本
点亮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的动画效果是这样的: 鼠标滑过或点击灯泡: 鼠标离开或点击灯泡: 视频 |