This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kingdaro's profile picture

Rainbows!

Started by Kingdaro, 09 May 2013 - 11:49 AM
Kingdaro #1
Posted 09 May 2013 - 01:49 PM
To pass the time in my IT class, I scripted this nice rainbow animation. Here's the code: http://pastebin.com/YL5rEicS

I wrote the program in moonscript, then converted it to lua for CC. I would consider it a bit more readable, so if you're curious, here's the moonscript:
Spoiler

local *

time = 0
period = 0.05
updateTimer = os.startTimer period

local rainbow
with colors
  rainbow = {
    .black
    .red
    .orange
    .yellow
    .green
    .blue
    .purple
    .black
  }

draw = ->
  with term
    w,h = term.getSize!
    for x=1, w
      for i=1, #rainbow
        .setBackgroundColor rainbow[i]
        for y=i*3 - 2, i*3
          y += math.sin(x / 15 + time) * 3
          .setCursorPos x, y
          .write ' '

while true
  _, timer = os.pullEvent 'timer'
  if timer == updateTimer
    draw!

    time += 0.5
    updateTimer = os.startTimer period
Goof #2
Posted 09 May 2013 - 01:50 PM
the code is broke.. you are missing the rest of it :D/>
Kingdaro #3
Posted 09 May 2013 - 01:56 PM
the code is broke.. you are missing the rest of it :D/>
Yeah, it is pretty short, haha.
Dlcruz129 #4
Posted 09 May 2013 - 08:54 PM
term.getSize!
Da faq?
Kingdaro #5
Posted 09 May 2013 - 09:01 PM
In moonscript, you can use an exclamation mark in place of parentheses. I'll just edit the OP with a link to the moonscript docs if anyone else has any questions about the code.
Inumel #6
Posted 09 May 2013 - 09:23 PM
I edited this program a bit, changing the colors to light blue, blue, and the rest cyan

I then built a room out of monitors running thsse with a sand floor, put a stair inside and pretended like it was a chair

So I can sit in that room and pretend I am on a tiny island with a crazy storm going on, thanks for this amazing program! haha
TheOddByte #7
Posted 10 May 2013 - 11:04 AM
Uhmm do you think you can upload some screenshots?
I'm quite interested to check this out since… RAINBOWS! :3
Kingdaro #8
Posted 10 May 2013 - 03:59 PM
Yeah, I'll upload screenshots when I can.