#------------------------------------------------------------ # TEST PROGRAM FOR GRAPHICS LIBRARY # # Copyright (C) December 1, 2019 -- Dr. William T. Verts #------------------------------------------------------------ from Graphics import * #------------------------------------------------------------ # Build the canvas and define variables for later use. #------------------------------------------------------------ Canvas = makeEmptyPicture(641, 481, cyan) XMid = getWidth(Canvas) // 2 YMid = getHeight(Canvas) // 2 Radius = 150 #------------------------------------------------------------ # Draw horizontal green lines from screen left to screen # right for the first 40 lines of the image. #------------------------------------------------------------ for Y in range(40): HorizontalLine(Canvas, 0, getWidth(Canvas)-1, Y, green) #------------------------------------------------------------ # Draw horizontal blue lines from screen left to screen # right, starting at line 40 and stepping down 10 rows at # a time. #------------------------------------------------------------ for Y in range(40, getHeight(Canvas), 10): HorizontalLine(Canvas, 0, getWidth(Canvas)-1, Y, blue) #------------------------------------------------------------ # Draw vertical blue lines from line 40 to screen bottom, # starting at screen left and stepping right 10 columns at # a time. #------------------------------------------------------------ for X in range(0, getWidth(Canvas), 10): VerticalLine(Canvas, X, 40, getHeight(Canvas)-1, blue) #------------------------------------------------------------ # Draw a big yellow filled circle at screen center, with # a bunch of red circle outlines starting at radius 10 and # stepping by 5 per circle. Finally, draw a red spot at # the center, and draw a black outline. #------------------------------------------------------------ BresenhamFilledCircle(Canvas, XMid, YMid, Radius, yellow) for R in range(10, Radius, 5): BresenhamCircle(Canvas, XMid, YMid, R, red) BresenhamFilledCircle(Canvas, XMid, YMid, 5, red) BresenhamCircle(Canvas, XMid, YMid, Radius, black) #------------------------------------------------------------ # Draw my signature in the green area. #------------------------------------------------------------ addLine(Canvas, 10, 10, 20, 30) # V addLine(Canvas, 20, 30, 30, 10) addLine(Canvas, 40, 10, 30, 30) # E addLine(Canvas, 40, 10, 60, 10) addLine(Canvas, 35, 20, 45, 20) addLine(Canvas, 30, 30, 50, 30) addLine(Canvas, 70, 10, 60, 30) # R addLine(Canvas, 70, 10, 80, 10) addLine(Canvas, 65, 20, 75, 20) addLine(Canvas, 80, 10, 85, 15) addLine(Canvas, 85, 15, 75, 20) addLine(Canvas, 75, 20, 80, 30) addLine(Canvas, 90, 10,110, 10) # T addLine(Canvas,100, 10, 90, 30) addLine(Canvas,120, 10,130, 10) # S addLine(Canvas,130, 10,132, 12) addLine(Canvas,120, 10,115, 15) addLine(Canvas,115, 15,120, 20) addLine(Canvas,120, 20,125, 20) addLine(Canvas,125, 20,128, 25) addLine(Canvas,128, 25,125, 30) addLine(Canvas,125, 30,115, 30) addLine(Canvas,115, 30,112, 25) #------------------------------------------------------------ # Save the image to file. #------------------------------------------------------------ print ("Pixels in Canvas = ", getWidth(Canvas)*getHeight(Canvas)) print ("Items in Canvas = ",len(Canvas)) WriteBMP('TestGraphics.bmp', Canvas) print ("All Done")