Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
%!PS-Adobe EPSF-3.0
%%DocumentData: Clean8Bit
%%BoundingBox: 0 163 595 679
%%DocumentNeededResources:
%%Pages: 0
%%EndComments
%%BeginProlog
%%EndProlog
%%BeginSetup
%%EndSetup
%%BeginPageSetup
gsave % first save
matrix currentmatrix % pushCTM()
setmatrix % restore CTM
matrix currentmatrix % pushCTM()
[ 0.827538 0.0 0.0 -0.827538 0.0 678.974965 ] concat
%%EndPageSetup
gsave
583.9428 312.0 moveto
583.9428 435.95633 483.45633 536.4428 359.5 536.4428 curveto
235.54366 536.4428 135.05719 435.95633 135.05719 312.0 curveto
135.05719 188.04366 235.54366 87.55719 359.5 87.55719 curveto
483.45633 87.55719 583.9428 188.04366 583.9428 312.0 curveto
closepath
% clip
% writeRadialGradient()
<<
/ShadingType 3
/ColorSpace [ /DeviceRGB ]
/Coords [247.271652 199.771652 224.4567 247.271652 199.771652 0.00]
/Extend [ false false ]
/AntiAlias true
/Function <<
/FunctionType 2
/Domain [ 0 1 ]
/C0 [ 0.9411765 0.0 0.0]
/C1 [ 1.0 1.0 1.0]
/N 1.00
>>
>>
shfill
grestore
1.0 setlinewidth
0.0 0.0 0.0 setrgbcolor
% draw
583.95667 312.0 moveto
583.95667 435.96402 483.46402 536.45667 359.5 536.45667 curveto
235.536 536.45667 135.0433 435.96402 135.0433 312.0 curveto
135.0433 188.036 235.536 87.543304 359.5 87.543304 curveto
483.46402 87.543304 583.95667 188.036 583.95667 312.0 curveto
closepath
stroke
showpage
grestore
%%EOF
%!PS-Adobe EPSF-3.0
%%DocumentData: Clean8Bit
%%BoundingBox: 0 163 595 679
%%DocumentNeededResources:
%%Pages: 0
%%EndComments
%%BeginProlog
%%EndProlog
%%BeginSetup
%%EndSetup
%%BeginPageSetup
gsave % first save
matrix currentmatrix % pushCTM()
setmatrix % restore CTM
matrix currentmatrix % pushCTM()
[ 0.827538 0.0 0.0 -0.827538 0.0 678.974965 ] concat
%%EndPageSetup
gsave
583.9428 312.0 moveto
583.9428 435.95633 483.45633 536.4428 359.5 536.4428 curveto
235.54366 536.4428 135.05719 435.95633 135.05719 312.0 curveto
135.05719 188.04366 235.54366 87.55719 359.5 87.55719 curveto
483.45633 87.55719 583.9428 188.04366 583.9428 312.0 curveto
closepath
clip
% writeRadialGradient()
<<
/ShadingType 3
/ColorSpace [ /DeviceRGB ]
/Coords [247.271652 199.771652 224.4567 247.271652 199.771652 0.00]
/Extend [ false false ]
/AntiAlias true
/Function <<
/FunctionType 2
/Domain [ 0 1 ]
/C0 [ 0.9411765 0.0 0.0]
/C1 [ 1.0 1.0 1.0]
/N 1.00
>>
>>
shfill
grestore
1.0 setlinewidth
0.0 0.0 0.0 setrgbcolor
% draw
583.95667 312.0 moveto
583.95667 435.96402 483.46402 536.45667 359.5 536.45667 curveto
235.536 536.45667 135.0433 435.96402 135.0433 312.0 curveto
135.0433 188.036 235.536 87.543304 359.5 87.543304 curveto
483.46402 87.543304 583.95667 188.036 583.95667 312.0 curveto
closepath
stroke
showpage
grestore
%%EOF
%!PS-Adobe EPSF-3.0
%%DocumentData: Clean8Bit
%%BoundingBox: 0 163 595 679
%%DocumentNeededResources:
%%Pages: 0
%%EndComments
%%BeginProlog
%%EndProlog
%%BeginSetup
%%EndSetup
%%BeginPageSetup
gsave % first save
matrix currentmatrix % pushCTM()
setmatrix % restore CTM
matrix currentmatrix % pushCTM()
[ 0.827538 0.0 0.0 -0.827538 0.0 678.974965 ] concat
%%EndPageSetup
gsave
583.9428 312.0 moveto
583.9428 435.95633 483.45633 536.4428 359.5 536.4428 curveto
235.54366 536.4428 135.05719 435.95633 135.05719 312.0 curveto
135.05719 188.04366 235.54366 87.55719 359.5 87.55719 curveto
483.45633 87.55719 583.9428 188.04366 583.9428 312.0 curveto
closepath
clip
% writeRadialGradient()
<<
/ShadingType 3
/ColorSpace [ /DeviceRGB ]
/Coords [247.271652 199.771652 224.4567 247.271652 199.771652 0.00]
/Extend [ true true ]
/AntiAlias true
/Function <<
/FunctionType 2
/Domain [ 0 1 ]
/C0 [ 0.9411765 0.0 0.0]
/C1 [ 1.0 1.0 1.0]
/N 1.00
>>
>>
shfill
grestore
1.0 setlinewidth
0.0 0.0 0.0 setrgbcolor
% draw
583.95667 312.0 moveto
583.95667 435.96402 483.46402 536.45667 359.5 536.45667 curveto
235.536 536.45667 135.0433 435.96402 135.0433 312.0 curveto
135.0433 188.036 235.536 87.543304 359.5 87.543304 curveto
483.46402 87.543304 583.95667 188.036 583.95667 312.0 curveto
closepath
stroke
showpage
grestore
%%EOF
import javax.swing.*;
import java.awt.*;
import java.awt.geom.Ellipse2D;
/**
* A frame containing a panel that shows how to draw a circle with a shading gradient color.
* <a href="http://docs.oracle.com/javase/7/docs/api/java/awt/RadialGradientPaint.html">RadialGradientPaint doc in English</a>
* <a href="http://download.oracle.com/technetwork/java/javase/6/docs/zh/api/java/awt/RadialGradientPaint.html">RadialGradientPaint doc in Chinese</a>
*/
public class RadialShadingPanel extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
float x = 250;
float y = 250;
float radius = 150;
Color customizedColor1 = Color.WHITE;
Color customizedColor2 = new Color(240, 0, 0);
Paint customizedPaint = new RadialGradientPaint(
x - radius * 0.5F, y - radius * 0.5F,
radius,
x - radius * 0.5F, y - radius * 0.5F,
new float[]{0F, 1F},
new Color[]{customizedColor1, customizedColor2},
MultipleGradientPaint.CycleMethod.NO_CYCLE);
((Graphics2D) g).setPaint(customizedPaint);
((Graphics2D) g).fill(new Ellipse2D.Float(x - radius, y - radius, radius * 2, radius * 2));
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setSize(500, 500);
f.setTitle("Circle with a shading gradient color");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new RadialShadingPanel());
f.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment