processing 时钟制作

int y,mo,d,h,m,s; //y: mo:月 d:日 h:时 m:分 s:秒
PFont myFont;
void setup(){
size(300,300);
background(204);
}
void draw(){
background(204); //设置颜色,同下
s = second(); // Values from 0 - 59
m = minute(); // Values from 0 - 59
h = hour(); // Values from 0 - 23
d = day(); // Values from 1 - 31
mo = month(); // Values from 1 - 12
y = year(); // 2014, 2015, 2016 etc.
myFont=createFont(“FFScala”,18); //字体和大小
myClockDraw();
}
void myClockDraw(){
translate(width/2,height/2); //移动原点到坐标中心
fill(255); //white
ellipse(0,0,200,200);
//Sets the color used to draw lines and borders around shapes.
stroke(0); //Black
textFont(myFont); //使用定义的字体
fill(0); //Black
text(“12”,-10,-75);//在指定坐标位置显示字符串
text(“3”,78,6);
text(“6”,-7,88);
text(“9”,-88,6);
text(y+"-"+mo+"-"+d,-40,-23); //显示 年-月-日
//绘制表盘
for(int i=1;i<=60;i++){
pushMatrix();
rotate(PI2.0i/60.0); //也可用radians()函数将角度转换为弧度
stroke(0);
if(i%15==0){
strokeWeight(2); //线的宽度为2
line(0,-90,0,-100);
}else if( i%5 ==0){
strokeWeight(2); //线的宽度为2
line(0,-92,0,-100);
}else{
strokeWeight(1); //线的宽度为1
line(0,-95,0,-100);
}
popMatrix();
}
//可用旋转矩阵其功能更强大
pushMatrix();
//把秒数转换为弧度(rotate()范围在0~2PI之间)
//基准线为为下面的line()的方向,顺时针为正方向
rotate(PI2s/60+PI);
stroke(0); //Black
strokeWeight(1); //线的宽度为1
line(0,0,0,90); //秒针
popMatrix();
pushMatrix();
rotate(PI2m/60+PI);
stroke(0);
strokeWeight(3);
line(0,0,0,70); //分针
popMatrix();
pushMatrix();
rotate(PI2h/12+PI);
stroke(0);
strokeWeight(4); //线的宽度为4
line(0,0,0,50); //时针
popMatrix();在这里插入图片描述
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值