Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,58 @@
|
|||
def line(self, x0, y0, x1, y1):
|
||||
"Bresenham's line algorithm"
|
||||
dx = abs(x1 - x0)
|
||||
dy = abs(y1 - y0)
|
||||
x, y = x0, y0
|
||||
sx = -1 if x0 > x1 else 1
|
||||
sy = -1 if y0 > y1 else 1
|
||||
if dx > dy:
|
||||
err = dx / 2.0
|
||||
while x != x1:
|
||||
self.set(x, y)
|
||||
err -= dy
|
||||
if err < 0:
|
||||
y += sy
|
||||
err += dx
|
||||
x += sx
|
||||
else:
|
||||
err = dy / 2.0
|
||||
while y != y1:
|
||||
self.set(x, y)
|
||||
err -= dx
|
||||
if err < 0:
|
||||
x += sx
|
||||
err += dy
|
||||
y += sy
|
||||
self.set(x, y)
|
||||
Bitmap.line = line
|
||||
|
||||
bitmap = Bitmap(17,17)
|
||||
for points in ((1,8,8,16),(8,16,16,8),(16,8,8,1),(8,1,1,8)):
|
||||
bitmap.line(*points)
|
||||
bitmap.chardisplay()
|
||||
|
||||
'''
|
||||
The origin, 0,0; is the lower left, with x increasing to the right,
|
||||
and Y increasing upwards.
|
||||
|
||||
The chardisplay above produces the following output :
|
||||
+-----------------+
|
||||
| @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @|
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @@ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ @ |
|
||||
| @ |
|
||||
| |
|
||||
+-----------------+
|
||||
'''
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
from fractions import Fraction
|
||||
|
||||
def line(self, x0, y0, x1, y1):
|
||||
rev = reversed
|
||||
if abs(y1 - y0) <= abs(x1 - x0):
|
||||
x0, y0, x1, y1 = y0, x0, y1, x1
|
||||
rev = lambda x: x
|
||||
if x1 < x0:
|
||||
x0, y0, x1, y1 = x1, y1, x0, y0
|
||||
leny = abs(y1 - y0)
|
||||
for i in range(leny + 1):
|
||||
self.set(*rev((round(Fraction(i, leny) * (x1 - x0)) + x0, (1 if y1 > y0 else -1) * i + y0)))
|
||||
|
||||
Bitmap.line = line
|
||||
|
||||
# see test code above
|
||||
Loading…
Add table
Add a link
Reference in a new issue