Processing学习笔记 之 Processing简要执行过程

来源:互联网 发布:宋承宪刘亦菲分手知乎 编辑:程序博客网 时间:2024/05/20 06:41

参考文献:http://processing.org/reference/

 


 

Processing执行过程:

第一步执行setup()

Called once when theprogram is started. Used to define initial enviromentproperties such as screen size, background color, loading images, etc. beforethe draw() begins executing. Variables declared within setup() arenot accessible within other functions, includingdraw(). There can onlybe one setup() function for each program and it should not becalled again after it's initial execution.

 

第二步执行draw()

Called directlyafter setup() and continuously executes the lines of code containedinside its block until the program is stopped or noLoop() iscalled. The draw()functionis called automatically and should never be called explicitly. It should always be controlled with noLoop()redraw() and loop().After noLoop() stops the code indraw() fromexecuting, redraw() causes the code inside draw() toexecute once and loop() will causes the code inside draw() toexecute continuously again. The number of times draw() executesin each second may be controlled with the delay()and frameRate() functions. There canonly be one draw() function for each sketch and draw() mustexist if you want the code to run continuously or to process events suchas mousePressed(). Sometimes, you might have an empty call to draw() inyour program as shown in the above example.

 

loop()

Causes Processing to continuously executethe code within draw(). If noLoop() is called, thecode in draw() stops executing.

 

noLoop()

Stops Processing from continuouslyexecuting the code within draw(). If loop() iscalled, the code in draw() begin to run continuously again. Ifusing noLoop() insetup(), it should be the last lineinside the block. 
When noLoop() is used, it's not possible to manipulate oraccess the screen inside event handling functions such as mousePressed() or keyPressed().Instead, use those functions to call redraw() or loop(),which will run draw(), which can update the screen properly. Thismeans that when noLoop() has been called, no drawing can happen, and functionslike saveFrame() or loadPixels() may not be used. 
Note that if the sketch is resized, redraw() willbe called to update the sketch, even after noLoop() has beenspecified. Otherwise, the sketch would enter an odd state until loop() wascalled.

原创粉丝点击