# animated line drawing

Is it possible to draw a line in sagemath as like javascript?

A Demo: http://jsfiddle.net/m1erickson/7faRQ/

animated line drawing

Is it possible to draw a line in sagemath as like javascript?

A Demo: http://jsfiddle.net/m1erickson/7faRQ/

add a comment

1

For sure, see the animated plots documentation.

EDIT: here is a possible solution:

```
def drawlines(lines, ns, **options):
r"""
Input:
- ``lines``: a list of lines, each line being defined
by its endpoints as ``[(x1,y1), (x2,y2)]``
- ``ns``: the number of division of each line for the
animation
- ``**options``: any option to pass to the graphic
command ``line``, like ``color`` or ``thickness``
"""
resu = []
preceeding = Graphics()
for li in lines:
x1, y1 = li[0]
x2, y2 = li[1]
dx = float(x2 - x1)/float(ns)
dy = float(y2 - y1)/float(ns)
for i in range(ns):
xx = x1 + (i+1)*dx
yy = y1 + (i+1)*dy
resu.append(preceeding + line([(x1,y1), (xx,yy)], **options))
preceeding = resu[-1]
return resu
anim = animate(drawlines([[(1,2), (3,4)],
[(3,4), (3,0)],
[(3,0), (1,2)]], 10, color='red', thickness=2),
xmin=0, xmax=4, ymin=0, ymax=5)
anim.show(delay=5)
```

You can see it at work on SageMathCell.

Asked: **
2017-11-23 18:29:45 -0500
**

Seen: **179 times**

Last updated: **Nov 25 '17**

Basic vector functions in Sage

Solid lines in plot and grid lines

Given a direction vector and a point, how to draw a 3d line?

Elegant solution to 'thin out' array and plot line

sage.plot.plot3d.shapes2.Line() does not work in the cloud

How to control layouts of individual plots within a graphics_array?

ATAN2 AssertionError while plotting complex squareroot function

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.