processing显示时间

2015-12-027609
AI 快速预览详细 收起
本文介绍了如何在Processing中实现一个实时显示时间的数字时钟。首先,通过设置帧率为30来控制刷新频率。然后,获取当前的小时、分钟和秒数,并将其显示在屏幕上。通过每秒更新这些值,实现了动态的时钟效果。这个项目非常适合编程初学者,可以帮助他们理解基本的时间处理和图形绘制方法。

  1. int th, tm, ts, oth, otm, ots;
  2. void setup() {
  3.   size (600, 480);
  4.   frameRate(30);
  5.   smooth();
  6.   th=hour();
  7.   tm=minute();
  8.   ts=second();
  9.   oth=th;
  10.   otm=tm;
  11.   ots=ts;
  12. }
  13. void draw() {
  14. background(200);
  15.   th=hour();
  16.   tm=minute();
  17.   ts=second();
  18.    textSize(40);
  19.   fill(0);
  20.      text(":     :", 180, 117);
  21.   fill(200);
  22.   text(oth, 130, 120);
  23.   text(otm, 200, 120);
  24.   text(ots, 270, 120);
  25.   fill(0);
  26.   text(th, 130, 120);
  27.   text(tm, 200, 120);
  28.   text(ts, 270, 120);
  29.   oth=th;
  30.   otm=tm;
  31.   ots=ts;
  32. }
复制代码
效果展示processing显示时间图1

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(0)
- 没有更多了 -