MCPcopy Create free account
hub / github.com/ActiveState/code / drawLine

Method drawLine

recipes/Python/577674_Bitmap_Maker/recipe-577674.py:292–374  ·  view source on GitHub ↗
( self, x1, y1, x2, y2, type=LINE_SOLID )

Source from the content-addressed store, hash-verified

290 self._drawLine( x1, y1, x2, y2 )
291
292 def drawLine( self, x1, y1, x2, y2, type=LINE_SOLID ):
293 if type == BitMap.LINE_SOLID:
294 self._drawLine( x1, y1, x2, y2 )
295 elif type == BitMap.LINE_DASHED:
296 # how many segs?
297 len = hypot( x2-x1, y2-y1 )
298 numsegs = len / BitMap._DASH_LEN
299 dx = ( x2 - x1 ) / numsegs
300 dy = ( y2 - y1 ) / numsegs
301 dx2 = dx / 2.0
302 dy2 = dy / 2.0
303 if ( x2 < x1 ):
304 x1,x2 = x2,x1
305 y1,y2 = y2,y1
306 segs = []
307 curx = x1
308 cury = y1
309 for i in range( int(numsegs) ):
310 segs.append( ( curx, cury, curx + dx2, cury + dy2 ) )
311 curx += dx
312 cury += dy
313 if curx + dx2 > x2:
314 segs.append( ( curx, cury, x2, y2 ) )
315 else:
316 segs.append( ( curx, cury, curx + dx2, cury + dy2 ) )
317 self._drawLines( segs )
318 elif type == BitMap.LINE_DOTTED:
319 len = hypot( x2-x1, y2-y1 )
320 numsegs = len / BitMap._DOT_LEN
321 dx = ( x2 - x1 ) / numsegs
322 dy = ( y2 - y1 ) / numsegs
323 dx2 = dx / 2.0
324 dy2 = dy / 2.0
325 if ( x2 < x1 ):
326 x1,x2 = x2,x1
327 y1,y2 = y2,y1
328 segs = []
329 curx = x1
330 cury = y1
331 for i in range( int(numsegs) ):
332 segs.append( ( curx, cury, curx + dx2, cury + dy2 ) )
333 curx += dx
334 cury += dy
335 if curx + dx2 > x2:
336 segs.append( ( curx, cury, x2, y2 ) )
337 else:
338 segs.append( ( curx, cury, curx + dx2, cury + dy2 ) )
339 self._drawLines( segs )
340 elif type == BitMap.LINE_DOT_DASH:
341 len = hypot( x2-x1, y2-y1 )
342 numsegs = len / BitMap._DOT_DASH_LEN
343 dx = ( x2 - x1 ) / numsegs
344 dy = ( y2 - y1 ) / numsegs
345 dx3 = dx / 3.0
346 dy3 = dy / 3.0
347 dx23 = 0.62*dx
348 dy23 = 0.62*dy
349 dx56 = 0.78*dx

Callers 7

drawRectMethod · 0.95
drawCircleMethod · 0.95
recipe-580806.pyFile · 0.80
drawSines.pyFile · 0.80
recipe-580810.pyFile · 0.80
paintEventMethod · 0.80
paintMethod · 0.80

Calls 4

_drawLineMethod · 0.95
_drawLinesMethod · 0.95
rangeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected