Draws a line from (x0,y0) to (x1,y1) in user-chosen color
from math import * from kandinsky import * def draw_line(x0, y0, x1, y1, c=(0,0,0)): # Calculate "deltas" of the line (difference between two ending points) dx = x1 - x0 dy = y1 - y0 if abs(dx)>=abs(dy): step = abs(dx) else: step = abs(dy) dx = dx/step dy = dy/step x = x0 y = y0 i = 1 # Draw the line based on arguments provided while i <= step: # Draw pixel at this location set_pixel(int(x), int(y), c) # Progress the line drawing algorithm parameters x += dx y += dy i += 1 # def line(): fill_rect(0,0,350,240,(0,0,0)) draw_line(0,0,350,240,(0,255,0))