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(); }