Oberon Community Platform Forum
November 21, 2019, 08:06:58 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Expansion canvas  (Read 10319 times)
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« on: April 22, 2008, 01:18:59 PM »

I found that absent functions as a circle, ellipse, arch segment, etc.  Angry
Even not MoveTo, LineTo (2 minutes to do ... Sad )
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; 
« Last Edit: April 22, 2008, 01:21:11 PM by BohdanT » Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #1 on: May 29, 2008, 10:02:58 AM »

Added to release (rev. 1231). Thanks!
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #2 on: July 24, 2008, 02:54:42 PM »

I am ashamed  Embarrassed , 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  Huh ).

* circle_and_ellipse.zip (0.88 KB - downloaded 523 times.)
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #3 on: August 18, 2008, 10:20:03 AM »

Removed penwidth parameter in revision 1512. Thanks!
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #4 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  Embarrassed

* WMGraphicsTest.Mod (6.37 KB - downloaded 435 times.)
* WMGraphicsTest.Mod (6.49 KB - downloaded 440 times.)
« Last Edit: February 06, 2009, 04:14:50 PM by BohdanT » Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #5 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?
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #6 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.  Smiley



Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #7 on: February 17, 2009, 03:41:20 PM »

Sorry, ran ...
 Embarrassed

* WMGraphicsTest.Mod (6.67 KB - downloaded 588 times.)
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!