DEV Community

Cover image for Glimmer Clock
Andy Maleh
Andy Maleh

Posted on

Glimmer Clock

Glimmer DSL for SWT 4.20.15.1 (JRuby Desktop Development GUI Framework) shipped with a Glimmer Clock elaborate sample.

Glimmer Clock

Code:

# From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#clock

class Clock
  include Glimmer::UI::CustomShell

  body {
    shell {
      text 'Glimmer Clock'
      minimum_size 400, 430

      canvas {
        initial_time = Time.now
        background :black

        animation {
          every 0.01 # every hundredth of a second to ensure higher accuracy

          frame { |index|
            time = Time.now

            oval(0, 0, 400, 400) {
              background :white
            }
            polygon(-5, -5, 180, 0, -5, 5) {
              background :black

              transform {
                translate 200, 200
                rotate(time.sec*6 - 90)
              }
            }
            polygon(-5, -5, 135, 0, -5, 5) {
              background :dark_gray

              transform {
                translate 200, 200
                rotate(time.min*6 - 90)
              }
            }
            polygon(-5, -5, 90, 0, -5, 5) {
              background :gray

              transform {
                translate 200, 200
                rotate((time.hour - 12)*30 - 90)
              }
            }
          }
        }
      }
    }
  }
end

Clock.launch
Enter fullscreen mode Exit fullscreen mode

Happy Glimmering!

Top comments (0)