Oberon Community Platform Forum

Development => Merge Requests => Topic started by: BohdanT on April 22, 2008, 01:18:59 PM



Title: Expansion canvas
Post by: BohdanT on April 22, 2008, 01:18:59 PM
I found that absent functions as a circle, ellipse, arch segment, etc.  >:(
Even not MoveTo, LineTo (2 minutes to do ... :( )
absent linesStyle and width ... (not two minutes but the same can be done ...)
I upload Circle and Ellipse.
I hope that someone will done do PenWidth and PenStyles (styles just do with use  LineMask and shift to the right, but perhaps you need    
taking into according the width)
Code:
PROCEDURE Circle*(CONST c:Canvas;CX, CY, R,penwidth : LONGINT);

VAR  X, Y             : LONGINT;
        XChange, YChange : LONGINT;
        RadiusError      : LONGINT;
BEGIN       
   X := R;
   Y := 0;
   XChange :=  1- 2*R;
   YChange := 1;
   RadiusError := 0;
  WHILE ( X>= Y ) DO
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY+Y,CX+X+1,CY+Y+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY+Y,CX-X+1, CY+Y+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY-Y,CX-X+1, CY-Y+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY-Y,CX+X+1, CY-Y+1),c.color,1);

   c.Fill(WMGraphics.MakeRectangle(CX+Y, CY+X,CX+Y+1,CY+X+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX-Y, CY+X,CX-Y+1, CY+X+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX-Y, CY-X,CX-Y+1, CY-X+1),c.color,1);
   c.Fill(WMGraphics.MakeRectangle(CX+Y, CY-X,CX+Y+1, CY-X+1),c.color,1);

         INC(Y);
         INC(RadiusError, YChange);
         INC(YChange,2);
         IF ( 2*RadiusError + XChange > 0 ) THEN
               DEC(X);
               INC(RadiusError, XChange);
               INC(XChange,2);
        END;
      END;
END  Circle;

(* Bresenham Type Algorithm For Drawing Ellipses*)
PROCEDURE Ellipse*(CONST c:Canvas;CX, CY, XRadius, YRadius,penwidth : LONGINT);
VAR
  X, Y                   : LONGINT;
        XChange, YChange       : LONGINT;
        EllipseError           : LONGINT;
        TwoASquare, TwoBSquare : LONGINT;
        StoppingX, StoppingY   : LONGINT;
BEGIN
   TwoASquare := 2*XRadius*XRadius;
   TwoBSquare := 2*YRadius*YRadius;
   X := XRadius;
   Y := 0;
   XChange :=  YRadius*YRadius*(1-2*XRadius);
   YChange :=  XRadius*XRadius;
   EllipseError := 0;
   StoppingX := TwoBSquare*XRadius;
   StoppingY := 0;
   WHILE ( StoppingX>= StoppingY ) DO     (*1st set of points, y> 1*)
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY+Y-pen1,CX+X+1,CY+Y+1),c.color,1);(*point in quadrant 1*)
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY+Y-pen1,CX-X+1, CY+Y+1),c.color,1);(*point in quadrant 2*)
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY-Y-pen1,CX-X+1, CY-Y+1),c.color,1);(*point in quadrant 3*)
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY-Y-pen1,CX+X+1, CY-Y+1),c.color,1);(*point in quadrant 4*)
         INC(Y);
         INC(StoppingY, TwoASquare);
         INC(EllipseError, YChange);
         INC(YChange,TwoASquare);
         IF ((2*EllipseError + XChange) > 0 ) THEN
           DEC(X);
           DEC(StoppingX, TwoBSquare);
           INC(EllipseError, XChange);
           INC(XChange,TwoBSquare)
         END
      END;
   (* 1st point set is done; start the 2nd set of points *)
   X := 0;
   Y := YRadius;
   XChange := YRadius*YRadius;
   YChange := XRadius*XRadius*(1-2*YRadius);
   EllipseError := 0;
   StoppingX := 0;
   StoppingY := TwoASquare*YRadius;
   WHILE ( StoppingX<= StoppingY ) DO  (*2nd set of points, y < 1*)
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY+Y,CX+X+1,CY+Y+1),c.color,1);(*point in quadrant 1*)
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY+Y,CX-X+1, CY+Y+1),c.color,1);(*point in quadrant 2*)
   c.Fill(WMGraphics.MakeRectangle(CX-X, CY-Y,CX-X+1, CY-Y+1),c.color,1);(*point in quadrant 3*)
   c.Fill(WMGraphics.MakeRectangle(CX+X, CY-Y,CX+X+1, CY-Y+1),c.color,1);(*point in quadrant 4*)
         INC(X);
         INC(StoppingX, TwoBSquare);
         INC(EllipseError, XChange);
         INC(XChange,TwoBSquare);
         IF ((2*EllipseError + YChange) > 0 ) THEN
               DEC(Y);
               DEC(StoppingY, TwoASquare);
               INC(EllipseError, YChange);
               INC(YChange,TwoASquare)
         END;
   END;
END Ellipse; 


Title: Re: Expansion canvas
Post by: staubesv on May 29, 2008, 10:02:58 AM
Added to release (rev. 1231). Thanks!


Title: Re: Expansion canvas
Post by: BohdanT on July 24, 2008, 02:54:42 PM
I am ashamed  :-[ , when I post code, not completely removed the parameter penwidth.
We need to remove and replace it on value 1, or use attached code (penwidth work, but not quite correctly, but I do not know how to do correctly  ??? ).


Title: Re: Expansion canvas
Post by: staubesv on August 18, 2008, 10:20:03 AM
Removed penwidth parameter in revision 1512. Thanks!


Title: Re: Expansion canvas
Post by: BohdanT on February 06, 2009, 02:36:22 PM
I tried realize PenWidth and PenStyles
I am uncertain that I did the right.
If anyone understands it, help please.

PS: Sorry, forgot to make a correction on the PenWidth when calling DrawImage  :-[


Title: Re: Expansion canvas
Post by: staubesv on February 16, 2009, 11:48:48 AM
Cool! I'm just not sure where to put the Line procedure... This way of drawing (using an image as pen) could actually be used for all kind of geometric shapes (circles, rectangles,...) so it seems quite different from what WMGraphicUtilities does.

Help: I never came into touch with the Gfx library, but assuming that a graphics library is capable of drawing lines of arbitrary thickness and styles, you should find some "alternative" solution there...  Since the SVG decoder seems to make extensive use of this library and works quite well, it is certainly worth having a look at it.

What do you think?


Title: Re: Expansion canvas
Post by: BohdanT on February 16, 2009, 02:25:37 PM
Quote
be used for all kind of geometric shapes
Yes indeed it is very easy to realize any graphical shape.
But I am not an expert in computer graphics and I do not know how it is right?
But like a good result.

Quote
Since the SVG decoder seems to make extensive use of this library and works quite well, it is certainly worth having a look at it.
I saw it. SVG library is very good.
If you do image editing, this is what you need.
   
To me, for example, just need to draw diagrams.   
Make port SVG library - complicated. Library use other types of data. He has a lot of dependencies.
It is easier to make self, than to make port from this library.  :)





Title: Re: Expansion canvas
Post by: BohdanT on February 17, 2009, 03:41:20 PM
Sorry, ran ...
 :-[