trutwnkl.ex

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

as per those that wanted truecolor demo's,
and to show that in a very short amount of time
that *many* programs out there written for other
graphic modes can quickly be converted to
truecolor modes now, with very little conversion
needed, i present TrueTwinkle, based upon MJSabal's
recent (today) post of twinkle.ex... ;) enjoy--Hawke'

-----------------CUT LINE---------------------------------

----------------- TruTwnkl.ex --------------
--TrueTwinkle:
--tweaked and adapted to truecolr by Hawke'
--originally Twinkle by M.J.Sabal
--------------------------------------------

----------------------------VAR's AND DECLARE's
-----------------------------------------------
include truecolr.e

constant MAXSTARS = 75

--TWINKLES should range from 1 to about 10 at most...IMO
--in reality, now, it's actually the "speed of fadeout"
--I like this value myself...
constant TWINKLES = 4

--this was the original map...
--constant STAR_IMAGE  ={ {1,0,1},
--                        {0,1,0},
--                        {1,0,1} }

--this is the direct conversion map, substituting a BGR mix
--constant STAR_IMGMAP ={ {{1,1,1},{0,0,0},{1,1,1}},
--                        {{0,0,0},{1,1,1},{0,0,0}},
--                        {{1,1,1},{0,0,0},{1,1,1}}  }

--this next map gives a really nice effect by color blending
--*each pixel* to it's neighbors, something you can't really
--do in other graphic modes... :)
constant STAR_IMGMAP ={ {{0,1,0},{1,1,1},{0,1,0}},
                        {{1,0,1},{0,1,0},{1,0,1}},
                        {{0,1,0},{1,1,1},{0,1,0}}  }

--this is for speed sake, fast erase
constant CLEAR_IMGMAP={ {{0,0,0},{0,0,0},{0,0,0}},
                        {{0,0,0},{0,0,0},{0,0,0}},
                        {{0,0,0},{0,0,0},{0,0,0}}  }

constant PINDX = 1, --Position Index
         CINDX = 2  --Color    Index

sequence vc, stars, current
atom delay

----------------------------------BEGIN FUNCTIONS
-------------------------------------------------
function MakeColor()
 --easy on the green, it's "brighter" than red or blue
   return { rand(250), rand(175),  rand(250) }
end function

function MakeStar()
   return { rand(SCR_MAX), MakeColor() }
end function

procedure ShowStar(sequence star)
   display_true_image( star[PINDX], star[CINDX]*STAR_IMGMAP )
end procedure

procedure EraseStar(sequence star)
   display_true_image( star[PINDX], CLEAR_IMGMAP )
end procedure

function FadeColor(sequence oldclr)
--rand({2,2,2}) - {1,1,1} is the same as choosing 0 or 1
--so we are subtracting either 0 or 1 from oldclr
   oldclr = oldclr - ( rand({2,2,2}) - {1,1,1} )
   return Max( oldclr,  {50,50,50} )
end function

----------------------MAIN
InitDisplay()

--let the display "settle" from the mode switch
delay = time() + 0.7 --seconds
while time()<delay do
        --some yawning, stretching, scratching... etc...
end while

--fill em up :)
stars = repeat(0,MAXSTARS)
for i = 1 to MAXSTARS do
        stars[i] = MakeStar()
end for

--randomly dim them all a tad, so the first screen isn't a
--flash of a whole buncha really bright stars....
for i = 1 to MAXSTARS do
   current = stars[i]
   for j = 1 to rand(10) do
       current[CINDX] = FadeColor(current[CINDX])
   end for
   stars[i] = current
end for

while get_key() < 1 do
   for a = 1 to TWINKLES do
     for b = 1 to MAXSTARS do
        current = stars[b]
        ShowStar(current)               --show a star, then...
        current[CINDX] =                --fade that star, then...
              FadeColor(current[CINDX])
        stars[b] = current
     end for
   end for
   EraseStar(stars[PINDX])              --erase 1st star, then...
   stars = stars[2..MAXSTARS]           --remove 1st star, and...
   stars = append(stars, MakeStar())    --tag a new star on end
end while

GoodBye() --go back to text mode, end program

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

Search



Quick Links

User menu

Not signed in.

Misc Menu