Yjasl Examples

Introduction :: Reference Manual :: Internals :: Yjasl Examples :: Programming Guidelines :: Download/sf.net :: About/Contact

snake.yjasl :: A snake game (console)
mandel.yjasl :: Mandelbrot (console)
gali.yjasl :: Game Of Life using 1D arrays (console)
gali2.yjasl :: Game Of Life using 2D arrays (console)
graph_mandel.yjasl :: Mandelbrot (GDI bindings 640x480)
graph_plasma.yjasl :: Plasma (GDI bindings 640x480)

gali.yjasl
/* Game of life: A really old 'life-simulator'
  This version (w) by René 'Neotec' Jeschke
  Version uses plain arrays
  Uses: Jasl v2.00 */

width   = 60
height  = 40

width2  = width - 1
height2 = height - 1
fsize   = width * height
fsize2  = fsize - 1

field  = array(fsize)
tfield = array(fsize, 0)

cclear()

for x = 0, fsize2 do
    field[x] = rand(0, 2)
end

function getcell(x, y)
    if x < 0 then
        x = width + x
    elseif x > width2 then
        x = x - width
    end

    if y < 0 then
        y = height + y
    elseif y > height2 then
        y = y - height
    end

    return field[x + y * width]
end

while isnull(getkey()) do
    t0 = timetick()
    o = 0
    for y = 0, height2 do
        for x = 0, width2 do
            c = 0
            for x1 = -1, 1 do
                for y1 = -1, 1 do
                    if !(x1 || y1) then
                        continue
                    end
                    if getcell(x + x1, y + y1) then
                        c = c + 1
                    end
                end
            end
            switch c do
                case 2:
                    tfield[o] = field[o]
                    break
                case 3:
                    tfield[o] = 1
                    break
                default:
                    tfield[o] = 0
            end
            o = o + 1
        end
    end

    chome()

    o = 0
    for y = 0, height2 do
        for x = 0, width2 do
            if tfield[o] then
                print("+")
            else
                print(" ")
            end
            field[o] = tfield[o]
            o = o + 1
        end
        println()
    end
    t1 = timetick()
    println((t1 - t0).." ms   ")
end

© by René 'Neotec' Jeschke in 2006, 2007
Last updated: 14 JUN 2007 (under construction)
SourceForge.net Logo