The_Invisible
2006-11-30, 23:45:41
also ich habe irgendwie voll den überblick verloren, wie bringe ich es zusammen das eine linie zwischen punkt a und punkt b gezeichnet wird, PIXELWEISE (aliasing egal)
gegeben sind surface (wo draufgemalt wird, nicht wichtig hier) und dann noch startPos und endPos die ein array darstellen (erstes element ist die x und zweites die y koordinate)
nachfolgend mein missglücktes frickelwerk, bitte nicht schrecken:
def drawLine(surface,startPos,endPos):
print startPos, endPos
if startPos[0] > endPos[0]:
forx = startPos[0]-endPos[0]
else:
forx = endPos[0]-startPos[0]
if startPos[1] > endPos[1]:
fory = startPos[1]-endPos[1]
else:
fory = endPos[1]-startPos[1]
print forx, fory
drawx = round(fory / forx,0)
drawy = round(forx / fory,0)
x = startPos[0]
y = startPos[1]
while x <= endPos[0]:
x += 1
print x,y
while y <= endPos[1]:
y += 1
# Pixel zeichnen
surface.set_at((x,y),(255,0,0))
print x,y
print drawx, drawy
keine ahnung ob der code auch nur im geringsten hinkommt, von mir aus kann er auch total verworfen werden. lösungvorschläge müssen nicht in python kommen, kann ich konvertieren. werde mich natürlich weiter versuchen. (heute aber nicht mehr)
mfg
gegeben sind surface (wo draufgemalt wird, nicht wichtig hier) und dann noch startPos und endPos die ein array darstellen (erstes element ist die x und zweites die y koordinate)
nachfolgend mein missglücktes frickelwerk, bitte nicht schrecken:
def drawLine(surface,startPos,endPos):
print startPos, endPos
if startPos[0] > endPos[0]:
forx = startPos[0]-endPos[0]
else:
forx = endPos[0]-startPos[0]
if startPos[1] > endPos[1]:
fory = startPos[1]-endPos[1]
else:
fory = endPos[1]-startPos[1]
print forx, fory
drawx = round(fory / forx,0)
drawy = round(forx / fory,0)
x = startPos[0]
y = startPos[1]
while x <= endPos[0]:
x += 1
print x,y
while y <= endPos[1]:
y += 1
# Pixel zeichnen
surface.set_at((x,y),(255,0,0))
print x,y
print drawx, drawy
keine ahnung ob der code auch nur im geringsten hinkommt, von mir aus kann er auch total verworfen werden. lösungvorschläge müssen nicht in python kommen, kann ich konvertieren. werde mich natürlich weiter versuchen. (heute aber nicht mehr)
mfg