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)

mandel.yjasl
width      = 78
height      = 80
imax        = 2048
fnum        = 0

screen      = {}
ctab        = {0, 3, 4, 1, 2, 10, 5, 6, 9, 7, 8, 12, 13, 15, 11, 14}

fparams     = {}
fparams[ 0] = {-2.5, 1.5, -1.5, 1.5}
fparams[ 1] = {-0.67, -0.47, 0.56, 0.71}
fparams[ 2] = {-0.748, -0.741, 0.132, 0.137}
fparams[ 3] = {-1.860573964886, -1.860573955145, -0.000000937963, -0.000000930786}
fparams[ 4] = {-0.144886188, -0.142549766, 0.887085252, 0.888842007}
fparams[ 5] = {-1.63742981, -1.61804453, -0.00661551021, 0.00794620067}
fparams[ 6] = {-0.274188704403, -0.274188253684, 0.841196557584, 0.841196897085}
fparams[ 7] = {-0.756142580573, -0.755810462997, 0.063936666834, 0.064188893918}
fparams[ 8] = {0.25545802, 0.255471414, 0.000646917149, 0.000656958669}
fparams[ 9] = {0.0142306089, 0.0910453238, 0.620278612, 0.67793702}
fparams[10] = {0.053016752, 0.0621620696, 0.65284525, 0.659712534}
fparams[11] = {0.0533606429, 0.0538874846, 0.657753872, 0.658148838}
fparams[12] = {-1.86561969, -1.8570414, -0.00343991257, 0.00300228037}
fparams[13] = {-1.98554866, -1.98535072, -0.000073082745, 0.000075308606}
fparams[14] = {-1.40796558, -1.4078986, 0.136930868, 0.136982191}
fparams[15] = {-0.189516153, -0.185453221, 0.649839532, 0.652892154}
fparams[16] = {-1.1414851, -1.14145892, 0.210522372, 0.210542001}
fparams[17] = {0.413359627551, 0.413361299095, 0.349679018431, 0.349680281948}
fparams[18] = {-1.629272209987, -1.629272209811, 0.020688346119, 0.020688346252}
fparams[19] = {0.315711855808, 0.315712001396, 0.029772060555, 0.029772170317}
fparams[20] = {0.3157113057952, 0.3157125563438, 0.029771625714741, 0.029772567058}
fparams[21] = {-0.637915280085, -0.637914271429, 0.388118260435, 0.388119017273}
fparams[22] = {-1.861408968987, -1.861408961972, 0.008042630316, 0.008042635619}
fparams[23] = {-1.861408966082, -1.861408964884, 0.008042632526, 0.008042633433}

global x_min, x_max, y_min, y_max, x_step, y_step

sub iterat();
sub calc_mandel();
sub set(x, y, c);
sub init_screen();

ccpselect(1250)
init_screen()
calc_mandel()
ccpselect(850)

sub calc_mandel()
    local t0, t1, time, min, sec

    cclear()

    x_min   = fparams[fnum][0]
    x_max   = fparams[fnum][1]
    y_min   = fparams[fnum][2]
    y_max   = fparams[fnum][3]

    x_step  = (x_max - x_min) / width
    y_step  = (y_min - y_max) / height

    t0      = timetick()

    iterat()

    t1      = timetick();

    crcolors()

    time    = t1 - t0
    min     = floor(time / 60000)
    sec     = floor((time - min * 60000) / 1000)

    println("\nREADY. Time: "..min..":"..strpadl(sec, 2, "0"))
end

sub iterat()
    local x, y, vx, vy, i, zx, zy, tx, ty, tx1, ty1, col, cnum

    for y = 0, height - 1 do
        vy = y_max + y * y_step
        for x = 0, width - 1 do
            vx = x_min + x * x_step
            i = 0
            zx = 0
            zy = 0

            do
                tx = zx + vx
                ty = zy + vy
                tx1 = tx * tx
                ty1 = ty * ty
                zx = tx1 - ty1
                zy = (tx + tx) * ty
                i = i + 1
            until (i == imax) || ((tx1 + ty1) > 4)

            if i == imax then
                set(x, y, 0)
            else
                set(x, y, ctab[(i / 4) & 15])
            end
        end
    end
end

sub set(x, y, c)
    local y1, n

    screen[x][y] = c

    if y & 1 then
        n = -1
    else
        n = 1
    end

    y1 = y + n

    ccsrpos(x, floor(y / 2))

    if screen[x][y] == screen[x][y1] then
        cbgcolor(c)
        print(" ")
    else
        if n == 1 then
            cfgcolor(screen[x][y])
            cbgcolor(screen[x][y1])
        else
            cfgcolor(screen[x][y1])
            cbgcolor(screen[x][y])
        end
        print(char(223))
    end
end

sub init_screen()
    local x
    screen = array(80)
    for x = 0, 79 do
        screen[x] = array(100, 0)
    end
end

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