An example of changed text. + a question.
I set statevar in a namespace and undefined integer to ulong for rgb()
But the new define is not contained inside the namespace, it seems permanent.
I suppose there is a reason for this, but I can't quite think of it.
Example:
Code: Select all
namespace state
#undef integer
#define integer ulong
type statevar
private:
as integer initflag
as string present_string,last_string
as integer present_integer,last_integer
as integer Sstart,Istart
declare function _string_value() byref as string
declare function _int_value() byref as integer
declare function ischanged() as boolean
'==============
public:
as boolean is_changed
declare operator let(as string)
declare operator let(as integer)
declare operator cast() as string
declare operator cast() as integer
end type
function statevar._string_value() byref as string
function=present_string
last_string=present_string
end function
function statevar._int_value() byref as integer
function=present_integer
last_integer=present_integer
end function
operator statevar.let(s as string)
initflag=2
_string_value()=s
if Sstart<2 then Sstart+=1
is_changed=ischanged
end operator
operator statevar.let(s as integer)
initflag=1
_int_value()=s
if Istart<2 then Istart+=1
is_changed=ischanged
end operator
function statevar.ischanged() as boolean
if initflag=2 then function = iif(Sstart>1,last_string<>present_string,0)
if initflag=1 then function = iif(Istart>1,last_integer<>present_integer,0)
if initflag=0 then function= 0
end function
operator statevar.cast() as string
if initflag=2 then operator= present_string
if initflag=1 then operator= str(present_integer)
end operator
operator StateVar.Cast() As Integer
operator= present_integer
End Operator
end namespace
'===================================================
''QUESTION
dim as integer i
#print typeof(i)
function contrast(c as ulong) as ulong
#define Intrange(f,l) int(Rnd*((l+1)-(f))+(f))
'get the rgb values
dim as ubyte r=Cptr(Ubyte Ptr,@c)[2],g=Cptr(Ubyte Ptr,@c)[1],b=Cptr(Ubyte Ptr,@c)[0],r2,g2,b2
do
r2=Intrange(0,255):g2=IntRange(0,255):b2=IntRange(0,255)
'get at least 120 byte difference
loop until abs(r-r2)>120 andalso abs(g-g2)>120 andalso abs(b-b2)>120
return rgb(r2,g2,b2)
end function
screenres 300,50,32
width 300\8,50\16
windowtitle "Every Five Seconds"
dim as state.statevar t
dim as state.statevar background,foreground
foreground=rgb(255,255,255)
randomize
do
t=time
if t.is_changed then draw string(115,15),string(8,chr(219)),background:draw string(115,15),t,foreground : t+=1
if t=5 then
foreground=rgb(rnd*255,rnd*255,rnd*255)
background=contrast(foreground)
t=0
end if
sleep 100,1
loop until len(inkey)