/******************************************************************************
* Compilation: javac StdDraw.java
* Execution: java StdDraw
* Dependencies: none
*
* Standard drawing library. This 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, and curves
* in a window on your computer and to save the drawings to a file.
*
* Todo
* ----
* - Add support for gradient fill, etc.
* - Fix setCanvasSize() so that it can only be called once.
* - On some systems, drawing a line (or other shape) that extends way
* beyond canvas (e.g., to infinity) dimensions does not get drawn.
*
* Remarks
* -------
* - don't use AffineTransform for rescaling since it inverts
* images and strings
*
******************************************************************************/
package edu.princeton.cs.algs4;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.TreeSet;
import java.util.NoSuchElementException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
/**
* The {@code 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. Standard drawing also includes
* facilities for text, color, pictures, and animation, along with
* user interaction via the keyboard and mouse.
* <p>
* <b>Getting started.</b>
* To use standard drawing, you must have {@code StdDraw.class} in your
* Java classpath. If you used our autoinstaller, you should be all set.
* Otherwise, download
* <a href = "https://introcs.cs.princeton.edu/java/stdlib/StdDraw.java">StdDraw.java</a>
* and put a copy in your working directory.
* <p>
* Now, type the following short program into your editor:
* <pre>
* public class TestStdDraw {
* public static void main(String[] args) {
* StdDraw.setPenRadius(0.05);
* StdDraw.setPenColor(StdDraw.BLUE);
* StdDraw.point(0.5, 0.5);
* StdDraw.setPenColor(StdDraw.MAGENTA);
* StdDraw.line(0.2, 0.2, 0.8, 0.2);
* }
* }
* </pre>
* If you compile and execute the program, you should see a window
* appear with a thick magenta line and a blue point.
* This program illustrates the two main types of methods in standard
* drawing—methods that draw geometric shapes and methods that
* control drawing parameters.
* The methods {@code StdDraw.line()} and {@code StdDraw.point()}
* draw lines and points; the methods {@code StdDraw.setPenRadius()}
* and {@code StdDraw.setPenColor()} control the line thickness and color.
* <p>
* <b>Points and lines.</b>
* You can draw points and line segments with the following methods:
* <ul>
* <li> {@link #point(double x, double y)}
* <li> {@link #line(double x1, double y1, double x2, double y2)}
* </ul>
* <p>
* The <em>x</em>- and <em>y</em>-coordinates must be in the drawing area
* (between 0 and 1 and by default) or the points and lines will not be visible.
* <p>
* <b>Squares, circles, rectangles, and ellipses.</b>
* You can draw squares, circles, rectangles, and ellipses using
* the following methods:
* <ul>
* <li> {@link #circle(double x, double y, double radius)}
* <li> {@link #ellipse(double x, double y, double semiMajorAxis, double semiMinorAxis)}
* <li> {@link #square(double x, double y, double radius)}
* <li> {@link #rectangle(double x, double y, double halfWidth, double halfHeight)}
* </ul>
* <p>
* All of these methods take as arguments the location and size of the shape.
* The location is always specified by the <em>x</em>- and <em>y</em>-coordinates
* of its <em>center</em>.
* The size of a circle is specified by its radius and the size of an ellipse is
* specified by the lengths of its semi-major and semi-minor axes.
* The size of a square or rectangle is specified by its half-width or half-height.
* The convention for drawing squares and rectangles is parallel to those for
* drawing circles and ellipses, but may be unexpected to the uninitiated.
* <p>
* The methods above trace outlines of the given shapes. The following methods
* draw filled versions:
* <ul>
* <li> {@link #filledCircle(double x, double y, double radius)}
* <li> {@link #filledEllipse(double x, double y, double semiMajorAxis, double semiMinorAxis)}
* <li> {@link #filledSquare(double x, double y, double radius)}
* <li> {@link #filledRectangle(double x, double y, double halfWidth, double halfHeight)}
* </ul>
* <p>
* <b>Circular arcs.</b>
* You can draw circular arcs with the following method:
* <ul>
* <li> {@link #arc(double x, double y, double radius, double angle1, double angle2)}
* </ul>
* <p>
* The arc is from the circle centered at (<em>x</em>, <em>y</em>) of the specified radius.
* The arc extends from angle1 to angle2. By convention, the angles are
* <em>polar</em> (counterclockwise angle from the <em>x</em>-axis)
* and represented in degrees. For example, {@code StdDraw.arc(0.0, 0.0, 1.0, 0, 90)}
* draws the arc of the unit circle from 3 o'clock (0 degrees) to 12 o'clock (90 degrees).
* <p>
* <b>Polygons.</b>
* You can draw polygons with the following methods:
* <ul>
* <li> {@link #polygon(double[] x, double[] y)}
* <li> {@link #filledPolygon(double[] x, double[] y)}
* </ul>
* <p>
* The points in the polygon are ({@code x[i]}, {@code y[i]}).
* For example, the following code fragment draws a filled diamond
* with vertices (0.1, 0.2), (0.2, 0.3), (0.3, 0.2), and (0.2, 0.1):
* <pre>
* double[] x = { 0.1, 0.2, 0.3, 0.2 };
* double[] y = { 0.2, 0.3, 0.2, 0.1 };
* StdDraw.filledPolygon(x, y);
* </pre>
* <p>
* <b>Pen size.</b>
* The pen is circular, so that when you set the pen radius to <em>r</em>
* and draw a point, you get a circle of radius <em>r</em>. Also, lines are
* of thickness 2<em>r</em> and have rounded ends. The default pen radius
* is 0.005 and is not affected by coordinate scaling. This default pen
* radius is about 1/200 the width of the default canvas, so that if
* you draw 100 points equally spaced along a horizontal or vertical line,
* you will be able to see individual circles, but if you draw 200 such
* points, the result will look like a line.
* <ul>
* <li> {@link #setPenRadius(double radius)}
* </ul>
* <p>
* For example, {@code StdDraw.setPenRadius(0.025)} makes
* the thickness of the lines and the size of the points to be five times
* the 0.005 default.
* To draw points with the minimum possible radius (one pixel on typical
* displays), set the pen radius to 0.0.
* <p>
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
读书笔记:数据结构与算法分析java语言描述随书代码学习.zip (282个子文件)
config 263B
FETCH_HEAD 126B
.gitignore 308B
HEAD 130B
HEAD 23B
pack-702783a74880acea9334548141e5b4f16d03b3dc.idx 14KB
index 32KB
StdDraw.java 73KB
Draw.java 47KB
In.java 29KB
AVLTreeST.java 27KB
RedBlackBST.java 26KB
StdIn.java 26KB
StdRandom.java 24KB
PatriciaST.java 20KB
BST.java 20KB
DigraphGenerator.java 19KB
PatriciaSET.java 18KB
StdStats.java 18KB
Picture.java 18KB
IndexBinomialMinPQ.java 17KB
GraphGenerator.java 17KB
StdAudio.java 16KB
HopcroftKarp.java 16KB
BinarySearchST.java 15KB
IndexFibonacciMinPQ.java 15KB
BipartiteMatching.java 14KB
IndexMinPQ.java 14KB
IndexMaxPQ.java 14KB
GaussJordanElimination.java 13KB
LinearProgramming.java 13KB
IndexMultiwayMinPQ.java 13KB
Point2D.java 13KB
BinaryIn.java 13KB
WordLadder.java 12KB
BellmanFordSP.java 12KB
TwoPersonZeroSumGame.java 12KB
GlobalMincut.java 12KB
TrieST.java 12KB
SET.java 12KB
Sort.java 12KB
TST.java 12KB
SegmentTree.java 11KB
GaussianElimination.java 11KB
TopologicalX.java 11KB
FloydWarshall.java 11KB
AssignmentProblem.java 11KB
AvlTree.java 11KB
BinaryOut.java 11KB
BreadthFirstPaths.java 11KB
SuffixArray.java 11KB
BTree.java 11KB
SuffixArrayX.java 11KB
TrieSET.java 11KB
EulerianCycle.java 10KB
FordFulkerson.java 10KB
BinaryStdIn.java 10KB
Polynomial.java 10KB
DijkstraUndirectedSP.java 10KB
MaxPQ.java 10KB
PairingHeap.java 10KB
EulerianPath.java 10KB
EdgeWeightedGraph.java 10KB
EdgeWeightedDigraph.java 10KB
MinPQ.java 10KB
DijkstraSP.java 10KB
LinearProbingHashST.java 10KB
BinomialMinPQ.java 10KB
ST.java 9KB
StdOut.java 9KB
FFT.java 9KB
BinaryStdOut.java 9KB
CollisionSystem.java 9KB
DirectedEulerianCycle.java 9KB
DirectedEulerianPath.java 9KB
CuckooHashTable.java 9KB
Digraph.java 9KB
CuckooHashTableClassic.java 9KB
MultiwayMinPQ.java 9KB
FibonacciMinPQ.java 9KB
SuffixArray.java 9KB
Particle.java 9KB
Complex.java 9KB
Interval1D.java 9KB
UF.java 9KB
FlowEdge.java 9KB
RedBlackTree.java 9KB
Alphabet.java 9KB
Vector.java 9KB
MergeX.java 9KB
SplayTree.java 9KB
BipartiteX.java 9KB
ClosestPair.java 9KB
Out.java 9KB
BreadthFirstDirectedPaths.java 9KB
WeightedQuickUnionUF.java 9KB
CC.java 9KB
SymbolGraph.java 9KB
KosarajuSharirSCC.java 8KB
DepthFirstOrder.java 8KB
共 282 条
- 1
- 2
- 3
资源评论
baidu_16992441
- 粉丝: 311
- 资源: 1041
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功