楕円形のつぶれかたで記号までついてるわけですね。
E0 から E7 まであるわけですが、E0 がもっとも丸い。E7 がつぶれた形をしている。
こんなのを Java でインタラクティブで動かせたらいいかな、というんで書いてみました。
そのままコンパイルすると動くはずです。です。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
import java.awt.geom.*; | |
public class EllipticalGalaxies | |
{ | |
public static void main(String args[]) | |
{ | |
new EllipticalFrame(); | |
} | |
} | |
class EllipticalFrame extends JFrame implements ActionListener | |
{ | |
EllipticalPanel panel=new EllipticalPanel(); | |
JButton plus=new JButton("+"); | |
JButton minus=new JButton("-"); | |
EllipticalFrame() | |
{ | |
setTitle("Elliptical Gallaxies"); | |
setSize(500,500); | |
setVisible(true); | |
JPanel control=new JPanel(); | |
control.setLayout(new FlowLayout()); | |
control.add(plus); | |
control.add(minus); | |
getContentPane().add(control,BorderLayout.NORTH); | |
getContentPane().add(panel,BorderLayout.CENTER); | |
plus.addActionListener(this); | |
minus.addActionListener(this); | |
} | |
public void actionPerformed(ActionEvent event) | |
{ | |
String cmd=event.getActionCommand(); | |
if(cmd.equals("+")) | |
{ | |
panel.n++; | |
repaint(); | |
} | |
else | |
{ | |
panel.n--; | |
repaint(); | |
} | |
if(7<panel.n) | |
panel.n=7; | |
if(panel.n<0) | |
panel.n=0; | |
} | |
} | |
class EllipticalPanel extends JPanel | |
{ | |
int n=0; | |
public void paint(Graphics graphics) | |
{ | |
Graphics2D g=(Graphics2D)graphics; | |
int w=getWidth(); | |
int h=getHeight(); | |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); | |
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,RenderingHints.VALUE_FRACTIONALMETRICS_ON); | |
g.setColor(Color.black); | |
g.fillRect(0,0,w,h); | |
g.setColor(Color.white); | |
int r=(int)w/8; | |
int x0=r; | |
int y0=r; | |
int d=(int)3*w/4; | |
if (w<h) | |
{ | |
h=(int)w/8; | |
d=(int)3*w/4; | |
} | |
y0=(int)((h-d)*.5); | |
y0=(int)((h-(1-n/10.0)*d)*.5); | |
int dh=(int)(((1-n/10.0)*d)); | |
float dash[]={10.0f}; | |
Stroke stroke=new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); | |
g.setStroke(stroke); | |
g.draw(new Ellipse2D.Double(x0,y0,d,dh)); | |
g.setColor(Color.white); | |
Font font=new Font("Arial",Font.BOLD,30); | |
FontMetrics fm=g.getFontMetrics(font); | |
String label="E"+n; | |
int stringWidth=fm.stringWidth(label); | |
int stringHeight=fm.getHeight(); | |
g.setFont(font); | |
g.drawString(label,(int)((w-stringWidth)*.5),(int)((h+stringHeight*.5)*.5)); | |
} | |
} |