if-statement - 我的 if 条件不适用于处理语言
问题描述
我正在为我的作业处理语言。这是一部动画。动画对象(一个球)需要从上到下。我已将变量声明为float x,y
. 每当我设置 if 条件以将其大小增加 1 时,但它并没有移动一英寸。
float x;
float y;
size(600, 400)
x = 0.4*width/8;
y = 0.4*height/8;
ellipse( width/2, x, 0.8*width/8, 0.8*width/8);
ellipse( y, height/2, 0.8*height/8, 0.8*height/8);
if(x < height){
x = x+1;
}
if(y < width){
y=y+1;
}
我期待输出 - 位于顶部的球向下移动并停在底部,左侧球向右移动并停在最右边的点。
解决方案
您在“静态模式”下使用处理,这意味着您的代码运行一次然后完成。到达代码末尾后没有任何反应。
要利用 Processing 的 60 FPS 渲染循环,您需要指定setup()
和draw()
函数。像这样的东西:
float circleY;
void setup(){
size(200, 200);
circleY = height/2;
}
void draw(){
background(200);
ellipse(100, circleY, 20, 20);
circleY = circleY + 1;
}
无耻的自我推销:这是Processing中的动画教程。
推荐阅读
- nginx - Nginx 反向代理 - 从另一个站点提供内容
- azure - 能否使用 Azure Key Vault 生成的证书对 Azure IoT 中心设备进行身份验证?
- azure - Azure 批处理 CI 的 Build.SourceVersionMessage 为空
- nginx - auth_basic 和 proxy_pass
- c# - 模板上的预填充/发件人选项卡
- javascript - React native 0.62.0 Build 在 Xcode 13.1 上失败
- javascript - Next.js - 匿名箭头函数导致快速刷新不保留本地组件状态(警告)
- c++ - 使用多个内核时,ESP32 不更新变量
- javascript - 仅console.log [[ promise 结果]] reactjs
- python - os.eventfd_read 不将计数器设置回零