p5 icon indicating copy to clipboard operation
p5 copied to clipboard

Having problems with from p5 import * NameError

Open derekwong9 opened this issue 6 years ago • 1 comments

Running the Hue Example

# Hue
#
# Hue is the color reflected from or transmitted through an object.
# and is typically referred to as the name of the color (red, blue,
# yellow, etc). Move the cursor vertically over each bar to alter its
# hue.
#

from p5 import *

bar_width = 20
last_bar = None

def setup():
    size(640, 360)
    title("Hue")
    color_mode('HSB', height, height, height)
    no_stroke()
    background(0)

def draw():
    global last_bar
    which_bar = mouse_x // bar_width
    if which_bar is not last_bar:
        bar_x = which_bar * bar_width
        fill(mouse_y, height, height)
        rect((bar_x, 0), bar_width, height)
        last_bar = which_bar

if __name__ == '__main__':
    run()
Traceback (most recent call last):
  File "p5.py", line 32, in <module>
    run()
NameError: name 'run' is not defined

I am not sure why this is the case, i assume that the from p5 import * is not bringing it into the namespace. Although doing import p5 then placing it infront of everything doesnt help either.

derekwong9 avatar Jan 10 '19 05:01 derekwong9

I suspect this is related to #85 .

abhikpal avatar Mar 26 '19 08:03 abhikpal