Hi all,
A while ago i posted a support request regarding the formula for the
HSV color model. this is while trying to build a true 'photoshop
like' color wheel in director. i have managed to develop a first
draft, and some basic code is included (it requires director 8 as to
the setPixel method).
The main handler: 'createColorWheelBitmap (radius)' will create the
colorwheel bitmap cast, and the unavoidable bug is very visible
there. try calling it from the message window, using a radius of
30-50 pixels and allow a few seconds for the bitmap to build, and see
the bug/fault for yourself. any suggestions?
By the way, if anybody can replace any of my
mechanical/qwazi-mathematical formulas into real math please do so...
Greetings,
Yariv Alter / Fin
PS. the complete self-contained TrueColorWheel 1.0 behaviour will be
mailed as soon as this bug is found!
---------------------------------------------------------------------------
on createColorWheelBitmap radius
mem=new(#bitmap)
mem.image=the stage.image.crop(rect(0,0,radius*2,radius*2))
mem.name="TCW WheelBitmap "&(radius*2).string
mem.image=image(radius*2, radius*2, 32)
mid=[radius,radius]
repeat with y=1 to radius*2
repeat with x=1 to radius*2
cp=[x,y]
nowradius=distance(cp,mid)
sat=LIM((1.0000*nowradius)/radius,0,1)
deg=angle(cp,mid)
if distance(mid,cp)>radius then col=rgb(255,255,255)
else col=calculateHSV(deg,sat,1)
mem.image.setpixel(x,y,col)
end repeat
end repeat
end
on calculateHSV hue,sat,val --degrees / saturation / value
col=degrees2color(hue)
wcol=rgb(AtoB(255,col.red,sat),AtoB(255,col.green,sat),AtoB(255,col.blue,sat))
return rgb(AtoB(0,wcol.red,val),AtoB(0,wcol.green,val),AtoB(0,wcol.blue,val))
end
on angle loci,mid
diff=loci-mid
difX=diff[1]
difY=diff[2]
if difX<>0 and difY<>0 then
flag=[abs(difX)/difX,abs(difY)/difY]
else
if difX=0 and difY=0 then
flag=[0,0]
else
if difX=0 then
flag=[0,abs(difY)/difY]
else
flag=[abs(difX)/difX,0]
end if
end if
end if
if float(abs(difX))<>0 then
theAngle= atan(float((difY))/float((difX)))
else
theAngle=1.5708
end if
newDeg=radians2degrees(theangle)
if flag[1]=1 or flag=[0,1] then fix=90
if flag[1]=-1 or flag=[0,-1] then fix=270
theDeg=newDeg+fix
if theDeg>=360 then theDeg=theDeg mod 360
return theDeg
end
on degrees2color deg
posval=integer(1.0000*(deg mod 60)/60*255)
negval=integer(1.0000*(60-(deg mod 60))/60*255)
if deg<60 then col=rgb(255,posval,0)
if deg>=60 then col=rgb(negval,255,0)
if deg>=120 then col=rgb(0,255,posval)
if deg>=180 then col=rgb(0,negval,255)
if deg>=240 then col=rgb(posval,0,255)
if deg>=300 then col=rgb(255,0,negval)
return col
end
on radians2degrees theRadians
return theRadians * 57.2957795786
end
on AtoB A,B,part
return (A*(1-part)+B*part)
end
on constrainCircle midpoint,curpoint,radius
newX=curpoint[1]
newY=curpoint[2]
nowrad=distance(curpoint,midpoint)
if nowrad>radius then
difrad=abs((1.0000*radius)/nowrad)
oldX=curpoint[1]-midpoint[1]
oldY=curpoint[2]-midpoint[2]
newX=midpoint[1]+oldX*difrad
newY=midpoint[2]+oldY*difrad
end if
return point(newX,newY)
end
on LIM what,mini,maxi
if what<mini then what=mini
if what>maxi then what=maxi
return what
end
on distance point1,point2
res=sqrt((point1[1]-point2[1])*(point1[1]-point2[1])+(point1[2]-point2[2])*(point1[2]-point2[2]))
return res
end
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]