LittleCoder

Ideas 1: Drawing Stuff

Hi! You made it!

Take your shoes off and grab a glass of water, this is going to be sweet.

We're assuming that you've got LittleCoder up and running on your computer. If that's not the case and you're having any kind of trouble, please email me post haste! My email address is hhausman ({at}) gmail.com. I can get you all set up.

LittleCoder is all about experimentation. Just try things, see what happens. Stuff will probably explode, but thats okay! These ideas are here in case you run out. Each one is a complete LittleCoder program. All you have to do is replace the code inside the 'main.rb' file with the code here, save the main.rb file (important) and restart LittleCoder.

Yeah, so, on to the ideas:
Scene.new_tile( "demoblob.png" )
That's it! Thats the simplest possible LittleCoder program. It tells the Scene to create a new_tile out of the image "demoblob.png" and start drawing it... Thats pretty easy.

Easy, yes. But boring. Lets try some more things.
my_tile = Scene.new_tile( "demoblob.png" )
my_tile.set_scale( 2, 2 )
Thats another complete LittleCoder program. If you try it out, you'll see that the blob we created is bigger now. Look at the code and see if you can figure out how. There are two basic steps. First, we create the blob, and give it the name my_tile. Second, we tell my_tile to set_scale to 2, 2... The numbers given to set_scale are multipliers for size in x and y. There are more details in the documentation if you're interested.

Next:
my_tile = Scene.new_tile( "demoblob.png" )
my_tile.set_scale( 0.5, 0.5 )
my_tile.set_color( 0.5, 0.5, 1.0 )
This one shows off another thing that you can do to a tile. We've made it a nice blue color. The three numbers given to set_color are for red/green/blue. Do you see why it's the color it is? Maybe you want to experiment with the numbers and see what kind of cool colors you can make.

More:
left_tile = Scene.new_tile( "demoblob.png" )
left_tile.set_color( 1, 0, 0 )
left_tile.set_pos( -2, 0 )

center_tile = Scene.new_tile( "demoblob.png" )
center_tile.set_color( 0, 1, 0 )
center_tile.set_pos( 0, 0 )

right_tile = Scene.new_tile( "demoblob.png" )
right_tile.set_color( 0, 0, 1 )
right_tile.set_pos( 2, 0 )
So theres quite a bit more code there. Can you tell what it's doing? Run it and see. We've created three tiles, and moved them to various places on the screen. The two numbers given to set_pos are positions in x and y.

All right. Let's get freaky:
1.upto( 5 ) do |x|
the_tile = Scene.new_tile( "demoblob.png" )
the_tile.set_pos( x, 0 )
end
This here uses a thing from the Ruby programming language (the language the LittleCoder scripts are written in)... Can you spot it? It's the 'upto' thing. It can be used to do some counting. The little x in the waterslide there is the numbers that are being counted being thrown down into the code there. (between the 'do' and 'end')

Do you see where x is used in set_pos? The code between the do and end gets run five times. (1, 2, 3, 4, 5)

Same same, but different:
5.downto( -5 ) do |x|
the_tile = Scene.new_tile( "demoblob.png" )
the_tile.set_pos( x, 0 )
end
This time we're using downto instead of upto, but I bet you can guess what it's doing. Drawing them from right to left makes it look better because the tile you add first always gets drawn last. (on top of the other tiles)

Okay. That's it for now. Hopefully these ideas have been interesting/informative. If you've got any questions or comments, I'm all ears. (: