【问题标题】:when i run my code, why does the ellipse/circle not show up当我运行我的代码时,为什么椭圆/圆没有出现
【发布时间】:2021-05-04 01:18:57
【问题描述】:
from math import sin
from processing import *

X = 30
Y = 30
delay = 16
radius = 30

def setup():
    strokeWeight(10)
    frameRate(20)
    size(500,500)

def sircle():
    global X, Y, radius
    background(100)
    fill(0,121,184)
    stroke(255)
    fc = environment.frameCount

    X += (mouse.x-X)/delay;
    Y += (mouse.y-Y)/delay;

    radius = radius + sin(fc / 4)

draw = sircle
run()

出于某种原因run() 只创建背景。 有人知道如何调用sircle() 的函数吗?

【问题讨论】:

  • 你忘了括号 draw = sircle() 吗?
  • 在这段代码中真正调用的唯一函数是run(),我们不知道它做了什么......
  • 您希望在这段代码中的哪个位置绘制椭圆/圆?我看到的变量可能是圆的中心点和半径,但实际上你从来没有对它们做任何事情。
  • 它应该从鼠标所在的位置开始,圆圈应该跟随鼠标移动到任何地方

标签: python processing


【解决方案1】:

我认为 OP 指的是this code

draw 被赋予函数变量sircle 似乎是正确的。此外,它不像sircle() 正在返回任何可以分配给draw 的东西

查看我上面分享的链接中的示例代码,你需要这样一行

ellipse(X,Y,radius,radius)

sircle 函数的末尾

【讨论】:

    【解决方案2】:

    您需要使用括号运行sircle()setup()

    这些是函数而不是变量,它们需要括号。在您的代码中,draw 变量存储了sircle() 函数的内存地址。

    【讨论】:

    • 当我这样做时它只会给我一个 TypeError
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 2011-01-31
    • 1970-01-01
    相关资源
    最近更新 更多