Skip to content

Getting Started: Your First ConsoleGL App

OkiStuff edited this page Jul 17, 2020 · 4 revisions

Getting Started

Now you have ConsoleGL installed. It's time to make your first ConsoleGL App. Lets Start by importing ConsoleGL

require 'ConsoleGL'

Good Job! Now Lets Start coding..

For your first app we are going to be making a very simple loop that draws 1 green box and 4 red boxes. Sounds simple but its a great way to learn about ConsoleGL

Counters

Lets Start by making a simple counter

require 'ConsoleGL'

counter = 0

while true do
    counter += 1
end

Great! This part is not a part of ConsoleGL but it will be really useful for this app.

Colors

Now Lets Add Some Colors!

require 'ConsoleGL'

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    counter += 1
end

This Won't do anything yet. But that's because we need to call the Console.Draw() Function

Drawing/Rendering

Lets get some graphics into our app

Lets Start with calling the Console.Draw() Function

require 'ConsoleGL'

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    Console.Draw()

    counter += 1
end

If we run this now we will get an error.

This is because we need to specify what to draw to the Console

require 'ConsoleGL'

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    Console.Draw(Console.BigSquareMiddle())

    counter += 1
end

Great! Now we are drawing a Big Square to the console. But we need to add color to it or else it won't work.

require 'ConsoleGL'

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    Console.Draw(Console.BigSquareMiddle(currentColor))

    counter += 1
end

Amazing! But we aren't done yet. Lets add some finishing touches

Finishing Touches

We need to reset the color and create a new line every 4 times the loop gets executed

require 'ConsoleGL'

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    Console.Draw(Console.BigSquareMiddle(currentColor))

    if counter > 4
        counter = 0
        Console.NewLine
    else
        counter += 1
    end
end

We also need to set the title

require 'ConsoleGL'
Console.SetTitle("My First ConsoleGL App")

counter = 0

while true do
    if counter == 0
        currentColor = Color.WHITE
    elsif counter == 1
        currentColor = Color.GREEN
    else
        currentColor = Color.RED
    end

    Console.Draw(Console.BigSquareMiddle(currentColor))

    if counter > 4
        counter = 0
        Console.NewLine
    else
        counter += 1
    end
end

Finished!

Now Try Running it!

Colorful Squares Demo Credit: Dudeguy1 for testing it on his computer and giving this screenshot. Please go follow him on twitter.

Clone this wiki locally