Simple Binary Clock

Simple Binary Clock preview image

1 collaborator

Marcus_snell Marcus Snell (Author)

Tags

binary 

Tagged by Marcus Snell over 6 years ago

clock 

Tagged by Marcus Snell over 6 years ago

mechanical 

Tagged by Marcus Snell over 6 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3.1 • Viewed 158 times • Downloaded 17 times • Run 0 times
Download the 'Simple Binary Clock' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [cubes cube]

globals[
  realtime
  time
  h1
  h2
  m1
  m2
  s1
  s2
  time0
  group0
  group1
  group2
  group3
  wigcount
  wigcheck
  wigtrip
  hc0
  hc1
  mc0
  mc1
  sc0
  sc1
  ]

patches-own[]

to setup
  ca
  set-default-shape cubes "cylinder"
  set group2 patches with [pycor = 0 or pycor = 1]
  set group1 patches with [pycor = 2 or pycor = 3]
  set group0 patches with [pycor = 4 or pycor = 5]
  set time0 [0 0 0]
  set hc1 [0 0 0 0 0 0]
  set mc1 [0 0 0 0 0 0]
  set sc1 [0 0 0 0 0 0]
  ask group0 with [pycor = 4][sprout-cubes 1 [set color 105]]
  ask group1 with [pycor = 2][sprout-cubes 1 [set color 65]]
  ask group2 with [pycor = 0][sprout-cubes 1 [set color 15]]
  clock
  keeptime
end 

to clock
  set realtime date-and-time
  set h1 read-from-string item 0 realtime
  set h2 read-from-string item 1 realtime
  let hh h1 * 10 + h2
  set m1 read-from-string item 3 realtime
  set m2 read-from-string item 4 realtime
  let mm m1 * 10 + m2
  set s1 read-from-string item 6 realtime
  set s2 read-from-string item 7 realtime
  let ss s1 * 10 + s2
  set time (list hh mm ss)
end 

to go
  set time0 time
  clock
  if time0 != time[keeptime]
end 

to keeptime
  hourcheck
  mincheck
  seccheck
  show time
end 

to hourcheck
  if item 0 time0 != item 0 time[
    set hc0 hc1
    let a1 floor((item 0 time) / 2 ^ 5)
    let a2 (item 0 time) mod 2 ^ 5
    let b1 floor(a2 / 2 ^ 4)
    let b2 a2 mod 2 ^ 4
    let c1 floor(b2 / 2 ^ 3)
    let c2 b2 mod 2 ^ 3
    let d1 floor(c2 / 2 ^ 2)
    let d2 c2 mod 2 ^ 2
    let e1 floor(d2 / 2)
    let e2 d2 mod 2
    set hc1 (list a1 b1 c1 d1 e1 e2)

    (foreach hc1 hc0 [0 1 2 3 4 5]
      [ if (?1 != ?2) [ask group0 with [pxcor = ?3][
            ifelse count cubes-here = 0
            [sprout-cubes 1 [set color 105]]
            [ask cubes-here[die]]
            ]
      ]])
    ]
end 

to mincheck
  if item 1 time0 != item 1 time[
    set mc0 mc1
    let a1 floor((item 1 time) / 2 ^ 5)
    let a2 (item 1 time) mod 2 ^ 5
    let b1 floor(a2 / 2 ^ 4)
    let b2 a2 mod 2 ^ 4
    let c1 floor(b2 / 2 ^ 3)
    let c2 b2 mod 2 ^ 3
    let d1 floor(c2 / 2 ^ 2)
    let d2 c2 mod 2 ^ 2
    let e1 floor(d2 / 2)
    let e2 d2 mod 2
    set mc1 (list a1 b1 c1 d1 e1 e2)

    (foreach mc1 mc0 [0 1 2 3 4 5]
      [ if (?1 != ?2) [ask group1 with [pxcor = ?3][
            ifelse count cubes-here = 0
            [sprout-cubes 1 [set color 65]]
            [ask cubes-here[die]]
            ]
      ]])
    ]
end 

to seccheck
  if item 2 time0 != item 2 time[
    set sc0 sc1
    let a1 floor((item 2 time) / 2 ^ 5)
    let a2 (item 2 time) mod 2 ^ 5
    let b1 floor(a2 / 2 ^ 4)
    let b2 a2 mod 2 ^ 4
    let c1 floor(b2 / 2 ^ 3)
    let c2 b2 mod 2 ^ 3
    let d1 floor(c2 / 2 ^ 2)
    let d2 c2 mod 2 ^ 2
    let e1 floor(d2 / 2)
    let e2 d2 mod 2
    set sc1 (list a1 b1 c1 d1 e1 e2)

    (foreach sc1 sc0 [0 1 2 3 4 5]
      [ if (?1 != ?2) [ask group2 with [pxcor = ?3][
            ifelse count cubes-here = 0
            [sprout-cubes 1 [set color 15]]
            [ask cubes-here[die]]
            ]
      ]])
    ]
end 

There is only one version of this model, created over 6 years ago by Marcus Snell.

Attached files

File Type Description Last updated
Simple Binary Clock.png preview Preview for 'Simple Binary Clock' over 6 years ago, by Marcus Snell Download

This model does not have any ancestors.

This model does not have any descendants.