Skip to content

Instantly share code, notes, and snippets.

@falcon8823
Created June 23, 2011 15:53
Show Gist options
  • Save falcon8823/1042829 to your computer and use it in GitHub Desktop.
Save falcon8823/1042829 to your computer and use it in GitHub Desktop.
ClockExample
/* ClockExample - Created by Hayato OKUMOTO - 2011.06.24 */
//定数宣言
//finalを頭につけると1度代入すると,値を変化させる事ができなくなる。
//それによるメリットは・・・
final float SR = 75; //秒針の長さ 75[px]
final float CX = 100; //時計の中心のX座標
final float CY = 100; //時計の中心のY座標
void setup() {
size(200, 200); //画面サイズ
}
void draw() {
//変数宣言
//関数内で"のみ"つかう変数は,その中で宣言すると良い
float st; //秒針の角度
int s; //現在の時刻(秒)
float sx, sy; //秒針の中心座標
background(255); //背景色:白
//現在の時刻(秒のみ)取得
//16時20分14秒だったら,14を返す
s = second(); //単位は秒
//秒針のなす角の計算
st = 2*PI / 60 * s; // ヒント:1周(2*PI)を60秒で回るから・・
//秒針の先の座標計算
sx = SR * cos(st - PI/2) + CX; //針先のx座標
sy = SR * sin(st - PI/2) + CX; //針先のy座標
//秒針を描く
line(CX, CY, sx, sy); //(100, 100)から(x, y)への線分
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment