How to make a square topped, round rect bottomed graphic?

Mick Collins mickclns at mac.com
Thu Dec 2 16:13:44 EST 2010


I think I've seen all the previous replies.  If so, here's a different, more mathematical, approach that can be
combined with the gradient and other techniques mentioned before:

The main thing here is a function (pointsOfNorman, Norman because of the resemblance to a Norman window) that returns the points for a polygon graphic, given the starting point (X and Y), width, height, and ANGLE OF ROTATION and the first handler (doTest) is just there to test it with various parameters.  Is this overkill? too slow? or what?  I'd appreciate your comments.

on doTest
   -- before running this test, create a polygon graphic named "NW"
   put 250 into theLeft
   put 250 into theTop
   repeat with i = 1 to 37
      put 6*i - 5 into theWid
      put pi * (i-1)/18 into angRot
      repeat with j = 1 to 80
         put 2*j into theHeight
         -- this is how you use the function
         set the points of grc "NW" to \
                pointsOfNorman(theLeft,theTop,theWid,theHeight,angRot)
         
         wait 0
      end repeat
   end repeat
   
end doTest

function pointsOfNorman L,T,wid,hite,rotAng
   --creates the points for a NormanWindow graphic (polygon)
   --"left", "top" (actually starting point), width, height, angle Of rotation 
   --                     (measured clockwise from rightward)
   --                     use 0*pi for semicircle down
   --                     use 0.5*pi for semicircle left
   --                     use 1*pi for semicircle up
   --                     use 1.5*pi for semicircle right
   --                     use 2*pi for semicircle down
   --                     (interpolate for a rotation other than these)
   
   
   -- first 3 points of rectangle
   put L,T into daPoints
   put round(L+wid*cos(rotAng)),round(T+wid*sin(rotAng)) into line 2 of daPoints
   put round(L+wid*cos(rotAng)-hite*sin(rotAng)),round(T+wid*sin(rotAng)+hite*cos(rotAng)) into line 3 of daPoints
   
   -- center of semiCircle
   put round(L+.5*wid*cos(rotAng)-hite*sin(rotAng)) into xCen
   put round(T+.5*wid*sin(rotAng)+hite*cos(rotAng)) into yCen
   
   put max(8, wid div 3) into numOfAngs -- number of straight lines to make semiCircle
   put wid / 2 into theRadius
   
   put 3 into lineNum 
   put pi / numOfAngs into deltaAng
   repeat with i = 1 to numOfAngs
      -- calculates the coordinates for the i-th point of the semicircle
      put deltaAng * i into theAng 
      add rotAng to theAng
      put xCen +theRadius*cos(theAng) into theX
      put yCen +theRadius*sin(theAng) into theY
      add 1 to lineNum
      put round(theX),round(theY) into line lineNum of daPoints
   end repeat
   
   -- and go back to the starting point
   add 1 to lineNum
   put L,T into line lineNum of daPoints
   
   return daPoints
end pointsOfNorman


Message: 4
Date: Wed, 1 Dec 2010 15:01:05 +0000
From: David Bovill <david at vaudevillecourt.tv>
To: How to use Revolution <use-livecode at lists.runrev.com>
Subject: How to make a square topped, round rect bottomed graphic?
Message-ID:
<AANLkTikQT9evU=ZWwnWXAHB6WS+Kfu-vHAAg=501bdBK at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

What is the most efficient way to make this? I thought I could have a
polygon graphic which was opaque but not joined up and use that to add
square corners to a roundrect graphic background - but it seems that every
time I make it opaque it automatically joins the graphic points.

What I want to be able to do is have a vector graphic which has the option
to have rounded corners on either or both the top and bottom, whcih I can
script. The most efficient way I can thin of doing it at the moment is to
have a background roundrect graphic, on top of which I can place a polygon
line to create square corners, and a white opaque graphic just inside the
square boundary to cover up the round corners?

Is there a better way?





More information about the Use-livecode mailing list