You can change the size of the canvas with the following method: The canvas does not include the window title or window border. You can use this method with one of these predefined colors in standard drawing:īOOK_BLUE, BOOK_LIGHT_BLUE, BOOK_RED, andįor example, tPenColor(StdDraw.MAGENTA) sets theīy default, all drawing takes places in a 512-by-512 canvas. The second method allows you to specify colors using theĬolor data type that is discussed in Chapter 3. Is a convenient way to find a desired color. The first method allows you to specify colors using the RGB color system.
To draw points with the minimum possible radius (one pixel on typicalĪll geometric shapes (such as points, lines, and circles) are drawn using The thickness of the lines and the size of the points to be five times Points, the result will look like a line.įor example, tPenRadius(0.025) makes You will be able to see individual circles, but if you draw 200 such You draw 100 points equally spaced along a horizontal or vertical line, Radius is about 1/200 the width of the default canvas, so that if Is 0.005 and is not affected by coordinate scaling. The pen is circular, so that when you set the pen radius to rĪnd draw a point, you get a circle of radius r.
Circle of life gif code#
The points in the polygon are ( x, y).įor example, the following code fragment draws a filled diamond You can draw polygons with the following methods: For example, StdDraw.arc(0.0, 0.0, 1.0, 0, 90)ĭraws the arc of the unit circle from 3 o'clock (0 degrees) to 12 o'clock (90 degrees). Polar (counterclockwise angle from the x-axis)Īnd represented in degrees. The arc is from the circle centered at ( x, y) of the specified radius.
The methods StdDraw.line() and StdDraw.point()ĭraw lines and points the methods tPenRadius()Īnd tPenColor() control the line thickness and color.
This program illustrates the two main types of methods in standardĭrawing-methods that draw geometric shapes and methods that If you compile and execute the program, you should see a windowĪppear with a thick magenta line and a blue point. Now, type the following short program into your editor: If you used our autoinstaller, you should be all set.Īnd add to your Java classpath or downloadĪnd put a copy in your working directory. To use this class, you must have StdDraw.class in your User interaction via the keyboard and mouse. Standard drawing also includesįacilities for text, color, pictures, and animation, along with It uses a simple graphics model thatĪllows you to create drawings consisting of points, lines, squares,Ĭircles, and other geometric shapes in a window on your computer and The StdDraw class provides a basic capability forĬreating drawings with your programs.