木曜日, 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));

RP2040 Zero で MicroPython を使う

  埋め込み用マイコンでも Python を動かせる MicroPython というものがあります。 リアルタイムでコマンドラインからマイコンを動かせる画期的なシステムなので、ちょっとした感動が味わえます。 使い方としては、まずファームウエアをアップロードしてドライブとして認識さ...