Rae graphics hello

Long time no post.

Well, to put it short: things happened, decided to switch fields from video editing and colour grading into my wonderful hobby: programming, I got an internship at a programming company, got my first real programming job, lost that job, got my second programming job in less than a month after that, and I’ve been happily programming ever since.

Enough about me. What I really want to talk about is the Rae programming language. And a small graphics hello.

Last year I actually already got a working opengl window working with some cubes written mostly in Rae, with some glue code in C++. Here’s the link. (But that example is very old, and so is the Rae compiler in Github…)

Today I read the first pages of Peter Shirley’s (possibly small) ebook Ray Tracing in One Weekend. I haven’t bought it yet, but just bumped on it in reddit (and actually the Ray Tracing: The Next Week, which was free today…)

Anyway, it had a nice piece of graphics helloworld code which I wanted to try out in Rae. So, here’s the Rae code for Shirley’s graphics helloworld:

func main
    int nx = 1000
    int ny = 500
    log_s("P3\n", nx, " ", ny, "\n255\n")
    loop (int j = ny-1; j >= 0; --j)
        loop (int i = 0; i < nx; ++i)
            float r = cast[float](i) / cast[float](nx)
            float g = cast[float](j) / cast[float](ny)
            float b = 0.2f
            int ir = cast[int](255.99f * r)
            int ig = cast[int](255.99f * g)
            int ib = cast[int](255.99f * b)
            log(ir, " ", ig, " ", ib)

And here’s what that code results in after I transpile it with raec and then compile the resulting C++ with GCC. And I also needed to pipe the output to a file in the command line: ./graphics_ppm > graphics_hello.ppm


Let’s see if I can get this version pushed to Github at some point.