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

Random Picture Generator

Started by Fetchetch, 13 June 2015 - 11:50 PM
Fetchetch #1
Posted 14 June 2015 - 01:50 AM
Random Picture Generator

A useless program

WARNING: DO NOT USE IF YOU HAVE EPILEPSY OR HAVE PROBLEMS WITH RAPID FLASHING IMAGES(BUT I DONT THINK IT IS RAPID)


The Random Picture Generator (RPG for short, thats what I am using…) will simply draw 51 pixels on 19 lines all with random colors in the CC color palette.
It is kinda like a benchmark or just, a very annoying screensaver (if you really want to).

The program was pretty much created in 5 minutes thanks to CTRL+C and CTRL+V.

It is very similar to theTANCO's Random Code Generator but doesnt need args or anything. Just run it.

Just like every other program, type in:
pastebin get eUH0DTbT rpg
and run "rpg" and to end it, CTRL+T for 3 seconds all the way!
This would use Lyte, but its only a file, not a program pack or a os.

Screenshot:
Spoiler
Edited on 13 June 2015 - 11:56 PM
Bomb Bloke #2
Posted 14 June 2015 - 01:58 AM
Hey, you know how instead of putting in fifty-odd "i = i + 1" lines you just use a "for" loop? How do you think you might get rid of all of those yCount = yCount + 1 lines? ;)/>

I'm actually a little surprised to hear that math.random(1,32768) works. I would've thought you'd've needed to use something like 2^math.random(0,15).
Fetchetch #3
Posted 14 June 2015 - 02:06 AM
Hey, you know how instead of putting in fifty-odd "i = i + 1" lines you just use a "for" loop? How do you think you might get rid of all of those yCount = yCount + 1 lines? ;)/>

I'm actually a little surprised to hear that math.random(1,32768) works. I would've thought you'd've needed to use something like 2^math.random(0,15).
Ah, well atleast it works. Like it said, I only built this in around 5 minutes thanks to CTRL+C and CTRL+V. About the 51 for loops, I dont know. I would do something stupid like this though:

paintutils.drawPixel(1,1,math.random(1,32768))
paintutils.drawPixel(1,2,math.random(1,32768))
paintutils.drawPixel(1,3,math.random(1,32768))
You get the point...
But id have to do that for the amount of "pixels" on the terminal for x and y which im too lazy to do :P/>

Yeah, I was surprised that worked too. I was going for a black and white-style static creator, but well hey and if i used math.random(0,32768) it would reboot the CC computer becuase of the window api failing.
Edited on 14 June 2015 - 12:14 AM
KingofGamesYami #4
Posted 14 June 2015 - 03:52 AM
CC automagically rounds up to the nearest color value, if given something that's not a color value but is still in range. I'd assume some colors are favored more than others, given the exponential differences. As in, 2^3 is going to be less popular than 2^4, because 2^2 is closer to 2^3 than 2^5 is to 2^4.
Edited on 14 June 2015 - 01:58 AM
Bomb Bloke #5
Posted 14 June 2015 - 04:27 AM
Good point, that'd explain why it's mostly red - about 50% of values would select it. :)/>
Lyqyd #6
Posted 14 June 2015 - 04:29 AM
It uses the highest true bit, it doesn't "round up".
KingofGamesYami #7
Posted 14 June 2015 - 04:36 AM
It uses the highest true bit, it doesn't "round up".

Well, that's what it looks like it's doing.

2048 is blue, 2049 will be brown, which is 4096
Lyqyd #8
Posted 14 June 2015 - 04:53 AM
Uh, no, it won't be.

Try for yourself!


term.setTextColor(2048)
print(2048)
term.setTextColor(2049)
print(2049)
term.setTextColor(4095)
print(4095)
term.setTextColor(4096)
print(4096)
Bomb Bloke #9
Posted 14 June 2015 - 05:06 AM
… and if it did round up, then most of Fetchetch's image would be black. It effectively rounds down.
KingofGamesYami #10
Posted 14 June 2015 - 05:14 AM
Well, I suppose this is what I get for trusting an emulator… Ugh. The concept was correct, if not the facts.
biggest yikes #11
Posted 14 June 2015 - 11:26 PM
The #1 rule in programming: Don't repeat yourself.
I rewrote the whole 85-line program into just 9 lines using nested for loops, also made it so it'll work on turtles and pocket computers aswell, and made it "more random" instead of 50% of the time using red. http://pastebin.com/mCvsBkdN
Edited on 14 June 2015 - 09:33 PM
Lyqyd #12
Posted 15 June 2015 - 01:24 AM
Your version won't use the color white. You'd want 0-15 for your exponents, not 1-15.
biggest yikes #13
Posted 15 June 2015 - 02:09 PM
Your version won't use the color white. You'd want 0-15 for your exponents, not 1-15.
Fixed, thanks for pointing that out.