Challenge: Faking 3D extrusion of a polygon

Michael Kristensen michael-kristensen at dsa-net.dk
Sat May 28 15:36:54 EDT 2011


Challenge: Faking 3D extrusion of a polygon

Hi 
This is a challenge of making a fake 3D extrusion of a random shaped polygon. 

In very simple cases you can just copy the polygon, put it behind with a little offset and shade it a little darker than the front polygon.

But if the offset gets a little larger then one can see that the two polygons doesn't form one object.

This is a far as I have come:

Make a random polygon and name it P1
Make the color fx light green and set the lineSize to 0

Make two copies of P1 and send them behind P1
Name the two copies P2 and P3
Color them both the same darker shade of the green color.

Now make a Button with this script:

on mouseUp
   lock screen
   put points of grc P1 into points1
   
   set points of grc P2 to points1
   move grc P2 relative 25,0
   put points of grc P2 into points2
   
   put line 1 of points1 & return after newPoints
   put line 1 of points2 & return after newPoints
   
   repeat with i = 2 to number of lines of points1-1
      if not within(grc P2,line i of points1) then put line i of points1 & return after newPoints
      if not within(grc P1,line i of points2) then put line i of points2 & return after newPoints
      
      if within(grc P1,line i of points2) and within(grc P2,line i of points1) then put line i of points2 & return after newPoints
   end repeat
   
   put line 1 of points1 & return after newPoints2
   put line 1 of points2 & return after newPoints2
   
   repeat with i = 2 to number of lines of points1-1
      if not within(grc P1,line i of points2) then put line i of points2 & return after newPoints2
      if not within(grc P2,line i of points1) then put line i of points1 & return after newPoints2
      
      if within(grc P1,line i of points2) and within(grc P2,line i of points1) then put line i of points2 & return after newPoints2
   end repeat
   
   set points of grc P2 to newpoints
   set points of grc P3 to newpoints2
end mouseUp

Clicking the Button should give you an extruded looking object.

BUT…..
Both P2 and P3 are faulty.
Only together on top of each other they look right.

Can you make it better?
Can you make the extruded look with only one extra object (apart from the original)?

Mic



More information about the use-livecode mailing list