Created
June 23, 2017 04:21
-
-
Save T-Pham/2439c4f5bdd70aa63d272502a7bc650f to your computer and use it in GitHub Desktop.
Roku Disco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub init() | |
n = 50 | |
m.n = n | |
for i = 0 to n * n - 1 | |
c = i mod n + 1 | |
r = Int(i / n) + 1 | |
child = CreateObject("roSGNode", "Rectangle") | |
w = Int(1280 / n) | |
h = Int(720 / n) | |
child.width = w | |
child.height = h | |
red = hex2(i mod 256) | |
blue = hex2(c mod 256) | |
green = hex2(r mod 256) | |
child.color = "#" + red + green + blue | |
child.translation = [(c - 1) * w, (r - 1) * h] | |
m.top.appendChild(child) | |
end for | |
m.t = CreateObject("roSGNode", "Timer") | |
m.t.duration = 0.001 | |
m.t.repeat = true | |
m.t.observeField("fire", "dance") | |
m.t.control = "start" | |
end sub | |
function hex2(n as Integer) as String | |
l = n mod 16 | |
f = Int(n / 16) | |
return hex1(l) + hex1(f) | |
end function | |
function hex1(n as Integer) as String | |
if n < 10 | |
return n.toStr() | |
elseif n = 10 | |
return "A" | |
elseif n = 11 | |
return "B" | |
elseif n = 12 | |
return "C" | |
elseif n = 13 | |
return "D" | |
elseif n = 14 | |
return "E" | |
elseif n = 15 | |
return "F" | |
end if | |
end function | |
sub dance() | |
for i = 1 to rnd(100) | |
danceStep() | |
end for | |
end sub | |
sub danceStep() | |
i1 = m.top.getChild(ri()) | |
i2 = m.top.getChild(ri()) | |
t = i1.translation | |
i1.translation = i2.translation | |
i2.translation = t | |
end sub | |
function ri() as Integer | |
return rnd(m.n) * rnd(m.n) - 1 | |
end function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<component name="Disco" extends="Group"> | |
<script type="text/brightscript" uri="pkg:/components/Disco.brs"/> | |
</component> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment