木曜日, 3月 26, 2009

Java: Drawing Lines of Various Width

Line drawing in Java with Graphics2D, is simple and straight foward except that the line width matters in coordinating the figures you would like to draw. Setting stroke, any line width can be set as follows:


int lineWidth=3;
BasicStroke stroke=new BasicStroke((float)lineWidth);
g2D.setStroke(stroke);


The next step is, however, rather counter-intuitive. The line will be drawn half the pixels left from the coordinate that you specify.


int d=(int)((double)(lineWidth-1)/2.0);


The drawing command will draw line that fills the area (x0,y0) to (x1,y1).


g2D.drawLine(x0+d,y0+d,x1-(lineWidth-d),y1-(lineWidth-d));

PHP: Composer の使い方

PHP には Composer という優れたパッケージ管理ツールがあります。最近、PHP サイトを Composer を使って再構築する作業を行いましたので、方法を書いておきたいと思います。 Composerとは? ComposerはPHPのパッケージ管理ツールです。Py...