Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fill(n): #n - count of points
- global smooth
- global height
- global width
- clear()
- print("FILL")
- color = [1.0, 1.0, 1.0]
- global points
- #step1 - outline rasterization
- for i in range(n):
- k = (i + n - 1) % n
- j = (i + 1) % n
- x1 = points[i][0]
- y1 = points[i][1]
- x2 = points[j][0]
- y2 = points[j][1]
- ex = (y1 >= y2) ^ (y1 <= points[k][1])
- dx = abs(x2 - x1)
- dy = abs(y2 - y1)
- sx = sign(x2 - x1)
- sy = sign(y2 - y1)
- er = dx - dy
- back = [0.0, 0.0, 0.0]
- tooglePixel(x2, y2, color, back)
- if not ex:
- tooglePixel(x1, y1, color, back)
- while x1 != x2 or y1 != y2:
- er2 = er * 2
- if er2 > -dy:
- er -= dy
- x1 += sx
- if er2 < dx:
- er += dx
- y1 += sy
- tooglePixel(x1, y1, color, back)
- #step2 - filling shape
- for j in range(height):
- flag = False
- for i in range(width):
- if getPixel(i, j) == color:
- flag = not flag
- if flag:
- setPixel(i, j, color)
- #step3 - drawing outline
- drawShape(smooth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement