Apr-11-2019, 06:58 PM
Hey everyone,
I just started coding python. I'm using jython and trying to create voronoi diagrams. For some reason I do not understand, my main loop does not work properly. The points are not placed on my gpanel. At this point I am really frustated, please point to the right direction.
(btw. I am a math teacher, so no homework here, just for me)
I just started coding python. I'm using jython and trying to create voronoi diagrams. For some reason I do not understand, my main loop does not work properly. The points are not placed on my gpanel. At this point I am really frustated, please point to the right direction.
(btw. I am a math teacher, so no homework here, just for me)
from gpanel import * from math import * nodeX=[] #List of the x-coordinates of the nodes nodeY=[] #List of the y-coordinates of the nodes nodeColor=[] #List of the colors of the nodes XX=60 #getScreenWidth() # reduced for testing YY=60 #getScreenHeight() def onMousePressed(xx,yy): nodeX.append(xx) nodeY.append(yy) nodeColor.append(getRandomX11Color()) #defines coordinats and colors of the nodes point(xx,yy) #put a point to mark the node if len(nodeX)>1: #jumps to MakeVoronoi MakeVoronoi() def MakeVoronoi(): for x in range(XX): # Goes through all x-pixels for y in range(YY): # Goes through all y-pixels dmin = math.sqrt(2) # Distance set to maximum possilble l=-1 # Number of the nearest node for r in range(len(nodeX)):# Cycles through nodes for each pixel dist=math.hypot(nodeX[r]-XX/(x+1),nodeY[r]-YY/(y+1)) #distance between the point (x/y) to node[r] if dist<dmin: # if nodr(r) is nearer to the point, the point gets the color of the node dmin=dist l=r setColor(nodeColor[l]) #Color for the point is set point(x+1,y+1) #Point is painted (?) makeGPanel(Size(XX,YY),mousePressed=onMousePressed)