Re: xplode.ex

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

Hi Everybody,

Last night my tennis match was interrupted again by rain (every bloody
Thursday, four or five weeks in a row!) so I had to resort to Euphoria
to calm my nerves. I played with Chris Cox's conversion from Qbasic -
I hope you don't mind, Chris - and the result is attached. I added a
little bit of random color, gravitational acceleration and timing
loops to make it reasonably independent of the machine speed. The
velocity gradation is also finer to avoid obvious layering. Enjoy.
jiri

-- explode.ex
-- from code by David Calhoun
-- ported from Qbasic to Euphoria by Chris Cox
-- modified by jiri babor 98-10-15

without type_check
include graphics.e      -- pixel() and stuff
include machine.e   -- tick_rate()

object junk
sequence x,y,vx,vy
atom ay,t
integer a,flag

procedure explode(sequence s, integer xo, integer yo)
    sequence pix,pal
    integer len
    -- initialize: write (invisibly) and record non-blank pixels
    x={}
    y={}
    len=8*length(s)             -- length of string in pixels
    clear_screen()
    junk=palette(1,{0,0,0})     -- black, invisible ink
    text_color(1)
    position(1,1)
    puts(1,s)
    for row=0 to 15 do
        pix=get_pixel({0,row,len})
        for i=1 to len do
            if pix[i] then
                x=x & (i-1)
                y=y & row
            end if
        end for
    end for
    x=x+xo                      -- include initial text offset
    y=y+yo                      -- include initial text offset
    len=length(x)               -- pixel total
    vx=.1*(rand(repeat(41,len))-21)    -- horizontal velocity between +-9
    vy=.1*(rand(repeat(41,len))-41)    -- vertical velocity between 0 to 9, up
    ay=0.01*(rand(11)+9)        -- vertical acceleration, 0.1 to 0.2
    -- display string
    junk=palette(15,{0,0,0})    -- start with black, invisible ink
    for i=1 to len do
        pixel(15,{x[i],y[i]})
    end for
    -- fade in
    pal=0.02*(rand({21,21,21})+42)
    for i=1 to 50 do
        t=time()+0.01
        junk=palette(15,floor(i*pal))
        while time()<t do end while -- waste time
    end for
    a=50
    flag=0
    while a do
        t=time()+0.02               -- 50 fps max
        for i=1 to len do
            pixel(1,{x[i],y[i]})
            x[i]=x[i]+vx[i]
            y[i]=y[i]+vy[i]
            vy[i]=vy[i]+ay
            pixel(15,{x[i],y[i]})
        end for
        if flag then
            a=a-1
            junk=palette(15,floor(a*pal))
        end if
        flag=not flag
        while time()<t do end while -- waste time
    end while
end procedure

tick_rate(100)
junk = graphics_mode(18)
while get_key()=-1 do
    explode("VIVA EUPHORIA",50+rand(436),40+rand(200)) -- mode 18 (640x480)
--    explode("VIVA EUPHORIA",20+rand(176),10+rand(120)) -- mode 19 (320x200)
end while
junk = graphics_mode(-1)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu