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

本文详细介绍了Processing程序的执行过程,包括setup()函数的初始化作用,draw()函数的连续执行,以及如何通过noLoop()、redraw()和loop()控制绘制循环。特别指出,在noLoop()后,屏幕更新与事件处理需借助redraw()或loop()来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 


 

Processing执行过程:

第一步执行setup()

Called once when the program is started. Used to define initial enviroment properties such as screen size, background color, loading images, etc. before the draw() begins executing. Variables declared within setup() are not accessible within other functions, includingdraw(). There can only be one setup() function for each program and it should not be called again after it's initial execution.

 

第二步执行draw()

Called directly after setup() and continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called. The draw()function is called automatically and should never be called explicitly. It should always be controlled with noLoop()redraw() and loop(). After noLoop() stops the code indraw() from executing, redraw() causes the code inside draw() to execute once and loop() will causes the code inside draw() to execute continuously again. The number of times draw() executes in each second may be controlled with the delay()and frameRate() functions. There can only be one draw() function for each sketch and draw() must exist if you want the code to run continuously or to process events such as mousePressed(). Sometimes, you might have an empty call to draw() in your program as shown in the above example.

 

loop()

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

 

noLoop()

Stops Processing from continuously executing the code within draw(). If loop() is called, the code in draw() begin to run continuously again. If using noLoop() insetup(), it should be the last line inside the block. 
When noLoop() is used, it's not possible to manipulate or access 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. This means that when noLoop() has been called, no drawing can happen, and functions like saveFrame() or loadPixels() may not be used. 
Note that if the sketch is resized, redraw() will be called to update the sketch, even after noLoop() has been specified. Otherwise, the sketch would enter an odd state until loop() was called.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值