Gradients (was "Re: Table field")

Jan Schenkel janschenkel at yahoo.com
Tue Jun 26 16:57:52 EDT 2012


Hi Peter,

You can do it all from code if you like. Create a new stack, drop a button onto it, and set its script to:

##
on mouseUp
   CreateTwoColorGraphic "Peter", "10,50,110,85", "255,0,0", "0,0,255"
   answer"Created:"&& theresult
end mouseUp

private command CreateTwoColorGraphic pName, pRectangle, pTopColor, pBottomColor
   --> prepare the fillGradient array
   local tFillGradientA
   put "linear" into tFillGradientA["type"]
   put (item 1 of pRectangle),(item 2 of pRectangle) into tFillGradientA["from"]
   put (item 1 of pRectangle),(item 4 of pRectangle) into tFillGradientA["to"]
   put (item 3 of pRectangle),(item 2 of pRectangle) into tFillGradientA["via"]
   put   0.00000,pTopColor & return & \
         0.49999,pTopColor & return & \
         0.50000,pBottomColor & return & \
         1.00000,pBottomColor \
         into tFillGradientA["ramp"]
   --> now create the graphic
   local tGraphicLongId
   resetthetemplateGraphic
   settherectangleofthetemplateGraphictopRectangle
   settheopaqueofthetemplateGraphictotrue
   setthefillGradientofthetemplateGraphictotFillGradientA
   create graphic pName
   put it into tGraphicLongId
   --> and cleanup before returning the long id of the graphic
   resetthetemplateGraphic
   return tGraphicLongId
end CreateTwoColorGraphic
##

Then click the button, and you'll get a graphic named "Peter" in the specified rectangle, with the two colors each taking up half of the height of the graphic, even when you resize it.

HTH,

Jan Schenkel.
 
=====
Quartam Reports & PDF Library for LiveCode
www.quartam.com


=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


----- Original Message -----
From: Peter Haworth <pete at lcsql.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Cc: 
Sent: Tuesday, June 26, 2012 10:08 PM
Subject: Re: Gradients (was "Re: Table field")

Thanks Scott.  As usual, a very useful learning tool.

Here's what I can't figure out though.  Your stack fades in the colors from
top to bottom. How can I get the graphic to contain two separate colors,
one that fills the top half of the graphic and another that fills in the
bottom half, with no fading just a clean horizontal break between them.

Maybe gradients are not the way to do this, although Bern'ds table stack
uses them for the graphic involved in coloring alternate lines - I just
can't figure out all the values for the different gradient array keys.

Pete
lcSQL Software <http://www.lcsql.com>





More information about the Use-livecode mailing list