We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to make an instance of a very simple class draw an ellipse using a.. umm... method? What am I doing wrong?
pointies = []
pnum = 123
def setup():
size (600, 300)
indicator = width/2
"""Pointies = (i for i in range(0,pnum))"""
for i in range (0, pnum):
x = map (i, 0, pnum, 0, width)
y = noise(x,indicator )
pointyinst = Pointy(x,y)
pointies.append(pointyinst)
def draw():
noStroke
fill(100)
for i in pointies:
i.display()
class Pointy:
"""Una clase de puntos"""
def __init__ (self, x, y, z = 0):
self.x = x
self.y = y
self.z = z
def display(self):
#point(self.x, self.y)
ellipse (self.x self.y, 3,3)
Answers
My Python knowledge is in its infancy. And I've never used "Python Mode" before! :-@
At 1st glance, your code seems correct. The only doubt I've got is whether Python got nested classes like Java!
The point is, whether class Pointy can directly access PApplet's members like ellipse() for example.
Would it need the main sketch's reference in order to call ellipse() and other Processing's API? :-S
I've also read somewhere that "Python Mode" is based on the old Python 2 instead of the latest 3! :-&
Perhaps we'd need to use the explicit class declaration format:
class Pointy(object):
rather than its shorter modern version:
class Pointy:
P.S.: This thread had "Python Mode" problems too:
http://forum.processing.org/two/discussion/6346/controlp5-and-python-mode
I found the main error: I was missing a comma:
ellipse (self.x**,** self.y, 3,3)
:)
Yes, that's actually a very good idea.
As far as Python 2 vs. 3: The Python mode's underlying technology, jython, is based on Python 2. I'm not aware of anything like jython for Python 3. The last mention of Python 3 on the jython roadmap is over four years old.