java 辐射渐变_Java:绘制渐变的饼图: LinearGradientPaint, RadialGradientPaint

import java.awt.Color;

import java.awt.geom.Arc2D;

import java.awt.geom.Area;

import java.awt.geom.GeneralPath;

import java.awt.geom.Point2D;

class Pie3D {

privateArc2Darc;// 这里的弧并不是圆上的一弧,而是椭圆的一部分.

private Area frontSite;

private Area leftSite;

private Area rightSite;

private Color color;

private Pie3D selectedPie;

private Point2D arcMiddle;

private Point2D labelPosition;

privatedoublevalue;

privateintshadowDepth;

privatedoubleselectedShiftDis;// 被选中的饼图在他的中线上移动的距离

public Pie3D(Arc2D arc, Color color, double value) {

this(arc, color, value, 10, 30);

}

public Pie3D(Arc2D arc, Color color, double value, int shadowDepth, double selectedShiftDis) {

this.arc = arc;

this.color = color;

this.value = value;

this.selectedShiftDis = selectedShiftDis;

this.shadowDepth = shadowDepth;

Arc2D arcBottom = new Arc2D.Double(arc.getX(), arc.getY() + shadowDepth, arc.getWidth(),

arc.getHeight() + 0, arc.getAngleStart(), arc.getAngleExtent(), Arc2D.CHORD);

Point2D[] topPs = getPointsOfArc(arc);

Point2D[] bottomPs = getPointsOfArc(arcBottom);

// Front site

GeneralPath font = new GeneralPath();

font.moveTo(topPs[1].getX(), topPs[1].getY());

font.lineTo(topPs[2].getX(), topPs[2].getY());

font.lineTo(bottomPs[2].getX(), bottomPs[2].getY());

font.lineTo(bottomPs[1].getX(), bottomPs[1].getY());

font.closePath();

this.frontSite = new Area(arcBottom);

this.frontSite.add(new Area(font));

// Left site

GeneralPath left = new GeneralPath();

left.moveTo(topPs[0].getX(), topPs[0].getY());

left.lineTo(topPs[1].getX(), topPs[1].getY());

left.lineTo(bottomPs[1].getX(), bottomPs[1].getY());

left.lineTo(topPs[0].getX(), topPs[0].getY() + 3);

left.closePath();

this.leftSite = new Area(left);

// Right site

GeneralPath right = new GeneralPath();

right.moveTo(topPs[0].getX(), topPs[0].getY());

right.lineTo(topPs[2].getX(), topPs[2].getY());

right.lineTo(bottomPs[2].getX(), bottomPs[2].getY());

right.lineTo(topPs[0].getX(), topPs[0].getY() + 3);

right.closePath();

this.rightSite = new Area(right);

arcMiddle = calculateArcMiddle();

// Label position: 五分之四处

Point2D c = getPieCenter();

// Point2D m = getChordMiddle();

Point2D

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值