e586. Drawing Simple Shapes

There are two ways to draw basic shapes like circles, ovals, lines, arcs, squares, rectangles, rounded rectangles, and polygons. The first is to use specific drawing methods like Graphics.drawOval(). This example uses these methods. The second is to construct a shape and then use Graphics2D.draw() to draw the shape. See the java.awt.geom package for examples that create shapes.

    // See e575 The Quintessential Drawing Program
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;

        g2d.drawLine(x1, y1, x2, y2);
        g2d.drawOval(x, y, w, h);
        g2d.drawRect(x, y, w, h);

        // A start angle of 0 represents a 3 o‘clock position, 90 represents a 12 o‘clock position,
        // and -90 (or 270) represents a 6 o‘clock position
        int startAngle = 45;
        int arcAngle = -60;
        g2d.drawArc(x, y, w, h, startAngle, arcAngle);

        g2d.drawRoundRect(x, y, w, h, arcWidth, arcHeight);

        Polygon polygon = new Polygon();
        polygon.addPoint(x, y);
        // Add more points...
        g2d.drawPolygon(polygon);
    }
Related Examples

原文地址:https://www.cnblogs.com/borter/p/9596072.html

时间: 2024-10-05 12:31:54

e586. Drawing Simple Shapes的相关文章

LightOj1285 - Drawing Simple Polygon(连接多边形各点)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1285 题意:给你一些点,然后把它们用一条线把它们连起来,构成一个多边形,不能有相交,必须用完所有的点,如果不能构成输出Impossible: 不能构成就是所有的点在一条直线上的时候:先按极角进行排序,然后倒着找到一个不再起点到终点那条线上的点,倒着连接起来: #include <stdio.h> #include <algorithm> #include <cst

e577. Enabling Antialiasing

// See e575 The Quintessential Drawing Program public void paint(Graphics g) { // Retrieve the graphics context; this object is used to paint shapes Graphics2D g2d = (Graphics2D)g; // Determine if antialiasing is enabled RenderingHints rhints = g2d.g

Pygame - Python游戏编程入门(0)

引言 博客刚开,想把最近学习的东西记录下来,算是一种笔记.最近打算开始学习Python,因为我感觉Python是一门很有意思的语言,很早以前就想学了(碍于懒),它的功能很强大,你可以用它来做科学运算,或者数字图像处理,或者任务的自动化,还可以构建动态网站,很多很多听起来就很有意思的实现.关于Python你还可以找到更多的资料,这里不一一赘述. 一说到开始学习一门新的编程语言,很多童鞋可能马上想到,“嗯,哥去买本书啃啃!”,结果买了本大部头,全是枯燥的语法知识,看了后面忘了前面,事倍功半.记得以前

Drawing Shapes Using B&#233;zier Paths

Drawing Shapes Using Bézier Paths In iOS 3.2 and later, you can use the UIBezierPath class to create vector-based paths. The UIBezierPath class is an Objective-C wrapper for the path-related features in the Core Graphics framework. You can use this c

iOS Drawing Concepts[iOS 绘画概念]

iOS Drawing Concepts https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html High-quality graphics are an important part of your app’s user interface. Providin

自定义基本java类-StdDraw.java

1 /************************************************************************* 2 * Compilation: javac StdDraw.java 3 * Execution: java StdDraw 4 * 5 * Standard drawing library. This class provides a basic capability for 6 * creating drawings with your

UIBezierPath 概述

UIBezierPath 概述 UIBezierPath API ReferenceThe UIBezierPath class lets you define a path consisting of straight and curved line segments and render that path in your custom views. You use this class initially to specify just the geometry for your path

Android API Guides---Hardware Acceleration

Hardware Acceleration 在Android 3.0的(API级别11)开始,Android的2D渲染管线支持硬件加速,这意味着那些在View的画布进行的所有绘制操作使用GPU.由于启用硬件加速所需增加的资源,你的应用程序会消耗更多的内存. 硬件加速,默认情况下,如果你的目标API级别为> = 14,但也可以显式启用启用.如果应用程序使用的唯一标准的观点和绘图,将其打开全球范围内应该不会造成任何不利的绘图效果.但是,由于硬件加速不支持所有的2D绘图操作,将其打开,可能会影响你的一

4.1.Android的硬件加速官方文档

参考 https://developer.android.com/guide/topics/graphics/hardware-accel.html 硬件加速背景知识 在手机客户端尤其是Android应用的开发过程中,我们经常会接触到"硬件加速"这个词.由于操作系统对底层软硬件封装非常完善,上层软件开发者往往对硬件加速的底层原理了解很少,也不清楚了解底层原理的意义,因此常会有一些误解,如硬件加速是不是通过特殊算法实现页面渲染加速,或是通过硬件提高CPU/GPU运算速率实现渲染加速. 本