Creating drawings consisting of geometric shapes
Source code name: "stddraw.py"
Programming language: Python
Topic: Graphics/2D
DMelt Version 2.2. Last modified: 10/27/1972. License: Free
http://datamelt.org/code/cache/stddraw_2543.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


# StdDraw class provides a basic capability for creating drawings with your programs. It uses a simple graphics model that allows you to create drawings consisting of points, lines, squares, circles, and other geometric shapes in a window on your computer and to save the drawings to a file.

# You can save the image using "File" and use "*.png" as a file extension.


from edu.princeton.cs.algs4 import StdDraw

StdDraw.square(0.2, 0.8, 0.1)
StdDraw.filledSquare(0.8, 0.8, 0.2)
StdDraw.circle(0.8, 0.2, 0.2)

StdDraw.setPenColor(StdDraw.BOOK_RED)
StdDraw.setPenRadius(0.02)
StdDraw.arc(0.8, 0.2, 0.1, 200, 45)

# draw a blue diamond
StdDraw.setPenRadius()
StdDraw.setPenColor(StdDraw.BOOK_BLUE)
x = [ 0.1, 0.2, 0.3, 0.2 ]
y = [ 0.2, 0.3, 0.2, 0.1 ]
StdDraw.filledPolygon(x, y)

# text
StdDraw.setPenColor(StdDraw.BLACK)
StdDraw.text(0.2, 0.5, "black text")
StdDraw.setPenColor(StdDraw.WHITE)
StdDraw.text(0.8, 0.8, "white text")