All modules are written in Python 3.7. They are not available via PyPi or anything alike, you have to download the python file and import it from your working directory.
This module lets you define a rectangular canvas inside a command line environment, and draw basic shapes in various colors inside it.
import bashdraw as bd
d = bd.Display(25, 25) # Initialize a 25x25 pixels display
d.NewState('MyState') # You need at least 1 state to be able to draw, use any object as identifier
d.SetState('MyState') # Set the working state to 'MyState'
d.Clear('MyState') # This resets the entire 'MyState' canvas to pitch black. Omit the state parameter to use the last set state.
f1 = bd.Point(0, 0, 'white') # Create a Point figure at coordinates 0, 0 and white color
d.DrawFigure(f1) # Draw the point to the display.
d.DrawFigure(f1, 'MyState') # This line and above are identical in this context, if no state parameter is specified, the last set state is used implicitly
d.Draw() # Draw the current state to the terminal.
Here's the output of the above code:
- Point(x, y, color = 'white')
- Rectangle(x0, y0, width, height, fill = False, color = 'white') OR Rectangle.FromPoints(p0, p1, fill = False, color = 'white')
- Line(x0, y0, x1, y1, color = 'white') OR Line.FromPoints(p0, p1, color = 'white')
- Triangle(x0, y0, x1, y1, x2, y2, fill = True, color = 'white') OR Triangle.FromPoints(p0, p1, p2, fill = True, color = 'white')
- Chain(p0, p1, ..., pn, color = 'white') - this draws a serie of connected Lines
- Spline(type, p0, p1, ..., pn, color = 'white') - type can be either Spline.BEZIER or Spline.CATMULL_ROM
x, y
parameters refer to integer x and y position of the display.p0, p1
parameters refer to Point objects.
The following colors are accepted as parameters, but whether or not some of them display properly will depend on your OS and CLI:
- 'white'
- 'red'
- 'green'
- 'blue'
- 'yellow'
- 'magenta'
- 'cyan'
- 'grey'
- 'black'
You can control where the display will be drawn by passing an optional align parameter:
import bashdraw as bd
d = bd.Display(10, 10, bd.LEFT) # This is the default setting
d = bd.Display(10, 10, bd.CENTER)
d = bd.Display(10, 10, bd.RIGHT)
You will need these modules installed with Python 3:
- termcolor
- colorama
- Color_Console
- math
- shlex
- struct
- platform
- subprocess
import bashdraw as bd
d = bd.Display(20, 20, bd.CENTER)
d.NewState(0)
d.SetState(0)
d.DrawFigure(bd.Rectangle(0, 0, 20, 20, 'yellow', True))
d.DrawFigure(bd.Spline(bd.Spline.BEZIER, bd.Point(4, 14), bd.Point(7, 16), bd.Point(13, 15), bd.Point(16, 11), 'red'))
d.DrawFigure(bd.Line(6, 5, 6, 7, 'cyan'))
d.DrawFigure(bd.Line(13, 5, 13, 7, 'cyan'))
d.Draw()
This gives the following output: