-- sending this again... first time didn't seem to work...

Hi all,

Here as promised the complete self sufficient TrueColorWheel 1.0 
behaviour, readymade, bugfree.

(it was the Director modulus operator that insists on deFloating all 
values, so we worked our way around that. Many thanks Roymeo, some 
reflection does always come in handy!!!)

Still, any fixes or replacements for these pseudo-math handlers are 
more than welcome...

You're welcome and TIA

Yariv Alter Fin

<snip>

--------- True Lingo Color Wheel 1.0 / alterFin 3.2001 / This Side Up 
/ Handle With Care ---------------

property 
middlepoint,diameter,pborder,circleSpr,borderSpr,dotSpr,briSpr,colorPoint,brightness,saturation
property dif,engage

on getPropertyDescriptionList

   propList = [:]

   addProp propList, #diameter, [\
   #default: 100, \
   #format:  #integer, \
   #comment: "Color Wheel Diameter:"]

   addProp propList, #pBorder, [\
   #default: 15, \
   #format:  #integer, \
   #comment: "Color Wheel Borderwidth:"]

   return propList
end

on getBehaviorDescription
   description = \
   "Place this behaviour on any sprite in the score, then run the 
movie. "&return&\
   "Allow some time to create the members and sprites for the 
TrueColorWheel. "&return&\
   "Note: the behaviour contains a GO TO THE FRAME that can be later 
removed."&return&return&\
"TrueColorWheel 1.0 by Yariv Alter Fin / www.alterFin.com / [EMAIL PROTECTED]"
   return description
end

on beginSprite me
   if pborder>14 then pBorder=14 -- director limit on shape members 
linesize...?????

   rad=diameter/2
   r=the stage.rect
   middlepoint=point((r[3]-r[1])/2,(r[4]-r[2])/2)

   spr=sprite(me.spritenum)
   if member("TCW bgMember").membernum=-1 then
     mem=new(#shape)
     mem.shapeType=#oval
     mem.filled=1
     mem.name="TCW bgMember"
   end if
   spr.member=member("TCW bgMember")

   spr=sprite(me.spritenum)
   rad=diameter/2
   spr.linesize=pBorder
   spr.height=diameter+spr.linesize*2-2
   spr.width=diameter+spr.linesize*2-2
   spr.loc=middlepoint-[rad+spr.linesize-1,rad+spr.linesize-1]
   spr.color=rgb(0,0,0)

   -- circle sprite

   repeat with i=me.spritenum+1 to the lastchannel
     if sprite(i).membernum=0 then
       curspr=i
       exit repeat
     end if
   end repeat

   spr=sprite(curspr)
   puppetsprite(curspr,true)
   circleSpr=spr

   if member("TCW WheelBitmap "&diameter.string).membernum=-1 then
     m=new(#bitmap)
     m.image=the stage.image.crop(rect(0,0,diameter,diameter))
     createColorWheelBitmap(diameter/2,m)
     m.name="TCW WheelBitmap "&diameter.string
   end if

   circleSpr.member=member("TCW WheelBitmap "&diameter.string)
   circleSpr.width=diameter
   circleSpr.height=diameter
   circleSpr.loc=middlepoint
   circleSpr.ink=8
   circleSpr.forecolor=255

   -- borderSprite

   repeat with i=me.spritenum+1 to the lastchannel
     if sprite(i).membernum=0 then
       curspr=i
       exit repeat
     end if
   end repeat

   spr=sprite(curspr)
   puppetsprite(curspr,true)

   rad=diameter/2

   if member("TCW borderMember").membernum=-1 then
     mem=new(#shape)
     mem.shapeType=#oval
     mem.filled=0
     mem.name="TCW borderMember"
   end if
   spr.member=member("TCW borderMember")
   spr.linesize=pBorder
   spr.height=diameter+spr.linesize*2-2
   spr.width=diameter+spr.linesize*2-2
   spr.loc=circleSpr.loc-[rad+spr.linesize-1,rad+spr.linesize-1]
   spr.color=rgb(255,255,255)
   borderSpr=spr

   -- dotSpr - saturation

   repeat with i=me.spritenum+1 to the lastchannel
     if sprite(i).membernum=0 then
       curspr=i
       exit repeat
     end if
   end repeat
   spr=sprite(curspr)
   puppetsprite(curspr,true)
   dotSpr=spr

   if member("TCW handleMember").membernum=-1 then
     mem=new(#shape)
     mem.shapeType=#oval
     mem.filled=0
     mem.name="TCW handleMember"
   end if
   spr.member=member("TCW handleMember")
   dotSpr.width=max(pBorder,4)
   dotSpr.height=max(pBorder,4)
   dotspr.linesize=2
   dotSpr.ink=2
   dotspr.loc=middlePoint-[dotspr.width/2,dotspr.height/2]


   -- briSpr - value

   repeat with i=me.spritenum+1 to the lastchannel
     if sprite(i).membernum=0 then
       curspr=i
       exit repeat
     end if
   end repeat
   spr=sprite(curspr)
   puppetsprite(curspr,true)
   briSpr=spr
   spr.member=member("TCW handleMember")
   briSpr.width=max(pBorder,4)
   briSpr.height=max(pBorder,4)
   briSpr.linesize=2
 
briSpr.loc=middlePoint-[dotspr.width/2,dotspr.height/2+diameter/2+borderSpr.linesize/2]
   briSpr.ink=2

   ----

   brightness=1
   engage=#off

   colorPoint=middlePoint+[diameter/2,diameter/2]
   qwe=me
end

on exitframe me
   moc=the mouseloc
   mid=middlePoint
   rad=diameter/2

   deg=angle(colorPoint,mid)
   newcol=calculateHSV(deg,saturation,brightness)

   if the mousedown then
     if engage=#off then
       case the rollover of
         (CircleSpr.spritenum),(BorderSpr.spritenum):
 
dotSpr.loc=constrainCircle(mid,moc,rad)-[dotSpr.width/2,dotSpr.height/2]
           engage=#circle
         (dotSpr.spritenum):
           dif=moc-dotSpr.loc
           engage=#dot
         (briSpr.spritenum):
           dif=moc-briSpr.loc
           engage=#brightness
       end case
     end if
   else
     engage=#off
   end if

   case engage of:
     #circle:
       colorPoint=constrainCircle(mid,moc,rad)
       nowrad=distance(colorpoint,mid)
       saturation=min([max([(1.0000*nowrad)/rad,0]),1])
       dotSpr.loc=colorPoint-[dotSpr.width/2,dotSpr.height/2]
     #dot:
       newDotLoc=moc-dif
 
colorPoint=constrainCircle(mid,newDotLoc+[dotSpr.width/2,dotSpr.height/2],rad)
       nowrad=distance(colorpoint,mid)
       saturation=min([max([(1.0000*nowrad)/rad,0]),1])
       dotSpr.loc=colorPoint-[dotSpr.width/2,dotSpr.height/2]
     #brightness:
       newBriLoc=moc-dif
       briPoint=constrainCircleBorder(mid,newBriLoc,rad+borderSpr.linesize/2)
       briSpr.loc=briPoint-[briSpr.width/2,briSpr.height/2]
       brightness=1.0000*abs(180-angle(briPoint,middlePoint))/180
       circleSpr.blend=brightness*100
   end case

   if engage<>#off then borderSpr.color=newcol
   go to the frame
end

----- my pseudo math handlers... --------------------------------

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=theangle * 57.2957795786

   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 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 constrainCircleBorder midpoint,curpoint,radius
   nowrad=distance(midpoint,curpoint)
   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
   return point(newX,newY)
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

on createColorWheelBitmap radius,mem
   mid=[radius,radius]
   repeat with y=0 to radius*2
     repeat with x=0 to radius*2
       cp=[x,y]
       nowradius=distance(cp,mid)
       sat= min([max([(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 degrees2color deg
   mymod=1.0000*((10000*deg) mod (10000*60))/10000 -- special thanx to 
Roy Crisman for the feedback...
   posval=integer(1.0000*(mymod)/60*255)
   negval=integer(1.0000*(60-(mymod))/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

---------------------------------------------------


[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!]

Reply via email to