アイソメトリックな表現のための手習い 2008/05/10



アイソメトリックな表現のための実験です。

package d;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test2 {

public static void main(String[] args) {

final Image image = rec(0);
final Image image2 = rec(1);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new JPanel() {
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Point P = new Point(300, 100);
for (int j = 0; j < 10; j++) {

Point point = new Point(P.x, P.y);

for (int i = 0; i < 10; i++) {
int cx = point.x;
int cy = point.y;
point = point(-60, point.x, point.y, 10);
// g2d.drawString("" + i, point.x, point.y);
g2d.drawImage(i == 9 ? image : image2, cx, cy, null);

}
int px = P.x;
int py = P.y;
P = point(60, P.x, P.y, 50);
g2d.drawLine(px, py, P.x, P.y);
}

}
});
frame.setSize(500, 500);
frame.setVisible(true);
}

static BufferedImage rec(int pos) {

BufferedImage b = new BufferedImage(30, 50, BufferedImage.TYPE_INT_ARGB);

Graphics2D g2d = b.createGraphics();
g2d.setColor(pos == 0 ? Color.WHITE : Color.LIGHT_GRAY);
g2d.fillRect(0, 0, 30, 50);
g2d.setColor(Color.BLUE);
g2d.drawRect(0, 0, 29, 49);

final AffineTransform affineTransform = new AffineTransform();
affineTransform.shear(0, Math.toRadians(30));
affineTransform.scale(.82602, 1);

final AffineTransformOp op = new AffineTransformOp(affineTransform,
AffineTransformOp.TYPE_BICUBIC);

return op.filter(b, null);
}

static public Point point(double degree, int cx, int cy, int R) {

int x = (int) (cx + (R * Math.sin(Math.toRadians(degree))));
int y = (int) (cy + (R * Math.cos(Math.toRadians(degree))));
return new Point(x, y);
}
}

: