Processing进阶:从基础到实战与面向对象编程入门
1. Processing基础进阶
在Processing中, loadPixels()
和 updatePixels()
现在可以作为 PImage
的方法使用,例如 imgs[0].loadPixels()
,这与之前的全局函数调用有所不同。
Processing中的事件处理非常简单。在ActionScript中,鼠标按下事件可以通过以下方式处理(使用帧脚本):
// actionscript frame script, mouse down event
stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
function handleMouseDown(me:MouseEvent) {
// do stuff when the mouse is pressed
}
而在Processing中,只需要包含 mousePressed
函数即可:
void mousePressed(){
// do stuff when the mouse is pressed
}
不过,还需要在草图中包含 draw()
函数,否