Re: Compilation to Javascript

new topic     » goto parent     » topic index » view thread      » older message » newer message

Shamelessy copied from Pete's entry

 
include euallegro.ew 
 
--adjust these for experimentation 
integer width = 300,  
        height = 300 
 
atom buffer 
object ret 
 
-------------------------------------------------------------- 
--module initialisations 
-------------------------------------------------------------- 
ret = allegro_init() 
ret = install_timer() 
ret = install_keyboard() 
 
set_color_depth(32) 
--ret = set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 1024,768, 0, 0) 
ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED,width, height, 0, 0) 
 
if ret = -1 then 
    --switch to a safe mode instead 
    ret = set_gfx_mode(GFX_SAFE, 640, 480, 0, 0) 
end if 
 
buffer = create_bitmap(width, height) 
clear_bitmap(buffer) 
 
------------------------------------------------------------ 
procedure dot(atom m, atom n, integer color = -1) 
------------------------------------------------------------ 
if color = -1 then 
    color = makecol(255,255,255) 
end if 
 
putpixel(buffer, floor(m), floor(n), color) 
 
end procedure 
 
------------------------------------------------------------ 
sequence plasma 
integer pw = 0, ph = 0 
procedure createPlasma(integer w, h) 
--direct copy 
------------------------------------------------------------ 
    plasma = repeat(repeat(0,w),h) 
    for y=1 to h do 
        for x=1 to w do 
            atom v = sin(x/16) 
            v += sin(y/8) 
            v += sin((x+y)/16) 
            v += sin(sqrt(x*x + y*y)/8) 
            v += 4 -- shift range from -4 .. 4 to 0 .. 8 
            v /= 8 -- bring range down to 0 .. 1 
            plasma[y][x] = v 
        end for 
    end for 
    pw = w 
    ph = h 
end procedure 
 
------------------------------------------------------------ 
atom hueShift = 0 
procedure drawPlasma(integer w, h) 
------------------------------------------------------------ 
    hueShift = remainder(hueShift + 0.02,1) 
    sequence rgb3 = repeat(repeat(0,w*h),3) 
    integer cx = 1 
    for y=1 to h do 
        for x=1 to w do 
            atom hue = hueShift + remainder(plasma[y][x],1) 
            integer i = floor(hue * 6) 
            atom t = 255, 
                 f = (hue * 6 - i)*t, 
                 q = t - f,  
                 r, g, b 
            switch mod(i,6) do 
                case 0: r = t; g = f; b = 0 
                case 1: r = q; g = t; b = 0 
                case 2: r = 0; g = t; b = f 
                case 3: r = 0; g = q; b = t 
                case 4: r = f; g = 0; b = t 
                case 5: r = t; g = 0; b = q 
            end switch 
            rgb3[1][cx] = r 
            rgb3[2][cx] = g 
            rgb3[3][cx] = b 
            cx += 1 
             
            --at this point put the coloured dot in the buffer 
            --would have been easier with a 2 dimensional sequence 
            --although should be actually able to skip rgb sequence 
            dot(x,y, makecol(floor(r),floor(g),floor(b))) 
            --max tension! 
            --blit(buffer, screen,  0, 0, 0, 0, SCREEN_W, SCREEN_H) 
        end for 
    end for 
    --this is the bit that draws to the screen 
    --cdCanvasPutImageRectRGB(cddbuffer, w, h, rgb3, 0, 0, 0, 0, 0, 0, 0, 0)  
     
    --for the impatient 
    blit(buffer, screen,  0, 0, 0, 0, SCREEN_W, SCREEN_H) 
end procedure 
 
 
------------------------------------------------------------ 
procedure main() 
------------------------------------------------------------ 
createPlasma(width, height) 
drawPlasma(width, height) 
 
--press any key to exit  
clear_keybuf() 
while 1 do 
    hueShift += 0.002 
    createPlasma(width, height) 
    drawPlasma(width, height) 
     
    if keypressed() then 
        exit 
    end if 
end while 
 
end procedure 
main() 

Cheers

Chris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu