木曜日, 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: 定数を扱う

プロジェクトごとの定数を扱うクラス Config\Constants の紹介です。 <?php namespace Config; class Constants {     public const DB_USER = "linguist...