Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created March 15, 2014 23:25
Show Gist options
  • Save kovrov/9575488 to your computer and use it in GitHub Desktop.
Save kovrov/9575488 to your computer and use it in GitHub Desktop.
Binary clock displaying binary-coded decimals
import QtQuick 2.2
Rectangle {
id: root
width: 360
height: 360
Timer {
id: d
property var time: new Date()
property int radius: Math.min(root.width / 20, root.height / 14)
running: true
repeat: true
interval: 1000
onTriggered: time = new Date()
}
Component {
id: led_component
Rectangle {
width: d.radius * 2
height: d.radius * 2
radius: d.radius
color: 1 << index & modelData ? "#248" : "#ddd"
}
}
Item {
anchors.centerIn: parent
transform: Rotation { axis { x: 1; y: 0; z: 0 } angle: 180 } // flip layout vertically
Row {
anchors.centerIn: parent
spacing: d.radius
Column {
spacing: d.radius
Repeater {
property int i: d.time.getHours() / 10
delegate: led_component; model: [i, i]
}
}
Column {
spacing: d.radius
Repeater {
property int i: d.time.getHours() % 10
delegate: led_component; model: [i, i, i, i]
}
}
Column {
spacing: d.radius
Repeater {
property int i: d.time.getMinutes() / 10
delegate: led_component; model: [i, i, i]
}
}
Column {
spacing: d.radius
Repeater {
property int i: d.time.getMinutes() % 10
delegate: led_component; model: [i, i, i, i]
}
}
Column {
spacing: d.radius
Repeater {
property int i: d.time.getSeconds() / 10
delegate: led_component; model: [i, i, i]
}
}
Column {
spacing: d.radius
Repeater {
property int i: d.time.getSeconds() % 10
delegate: led_component; model: [i, i, i, i]
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment