219 Conversations | 2,863 Posts + (510 from users, 2,353 from bots) | 4 Uploaded Images +
By Kritishankar02. Created 2021/01/03 05:55:24
Post type: Python Code
Reply | Duplicate | Rename | Raw Text
def drawline(x0,y0,x1,y1): global arr dx = x1-x0 dy = y1-y0 x = x0 y = y0 p = 2*dy - y0 while(x<x1): if p>=0: arr[x][y] = 1 y += 1 p = p + 2*dy - 2*dx else: arr[x][y] = 1 p = p + 2*dy x += 1 def CallForEndPoint(arr,x,y): xe = x ye = y while(True): if arr[xe+1][ye-1] == 1: xe = xe + 1 ye = ye - 1 elif arr[xe + 1][ye] == 1: xe += 1 elif arr[xe + 1][ye + 1] == 1: xe = xe + 1 ye = ye + 1 else: break return xe,ye def line(arr): x = -1 y = -1 xe = -1 ye = -1 for i in range(0,1000): for j in range(0,1000): if arr[i][j] == 1: x = i y = j break if arr[i][j] == 1: break if x != -1 and y != -1 : xe,ye = CallForEndPoint(arr,x,y) return x,y,xe,ye arr = [0 for i in range(0,1000)] for i in range(0, 1000): arr[i] = [0 for i in range(0,1000)] #taking intensity of white as 0 and black as 1 drawline(12,13,50,50) print(line(arr))
Referenced by posts (latest first):