Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #59514

Re: chosing "small 2d graphics library" interface

Newsgroups comp.lang.c
Date 2015-04-03 06:04 -0700
References (5 earlier) <mflql6$rh1$1@dont-email.me> <d5d6f0eb-031c-49af-9c6d-5072e3c7e46a@googlegroups.com> <mfls53$pr$1@dont-email.me> <a91f0019-5fe6-4c72-a99a-11b43ca96d22@googlegroups.com> <mfm0vr$i8s$1@dont-email.me>
Message-ID <67e95495-bfaa-404c-9be5-e18768df8fea@googlegroups.com> (permalink)
Subject Re: chosing "small 2d graphics library" interface
From fir <profesor.fir@gmail.com>

Show all headers | View raw


W dniu piątek, 3 kwietnia 2015 14:28:41 UTC+2 użytkownik Bart napisał:
> On 03/04/2015 12:36, fir wrote:
> 
> > thus i need to head to beziers - i had not implemented it yet to much bezier curve is
> > very easy to draw
> 
> > void DrawBezier(float ax, float ay,
> >                  float bx, float by,
> >                  float cx, float cy,
> >                  float dx, float dy,
> >                    unsigned color)
> > {
> >
> >    float step = 1.0/1000.;
> 
> > though i got 2 problems here
> > 1) how to calculate how much pixels do i
> > need to set (the length of the corve?)
> > [here above is hardcoded 1000 pixels, yuck]
> 
> You can use the same method as for the line drawing: work out the 
> extents of the curve and estimate the number of pixels. Although is 
> quite a lot of work and the estimate might still be too low or too high.
> 
> So try a different approach:
> 
> Look at the thread "C-Programming", a post by Ben Bacarisse on 
> 17-12-2014, which gives a recursive way of creating Bezier curves.This 
> way you don't need to calculate how many steps in advance.
> 

I found it it is :
>>>>>


 JohnF wrote: 
> 
>> Tim Rentsch <t...@alumni.caltech.edu> wrote: 
>>> <<snip>> 
>>> As for recursive implementations in C having no practical utility, 
>>> that may be true for factorial, but it certainly is not true for 
>>> other uses.  In particular, for Fibonacci numbers, the fastest 
>>> implementation in C I have seen used a recursive definition (ie, 
>>> the C code was itself recursive). <<snip>> 
>> 
>> Various algorithms, like generating bezier curves and some fractals, 
>> are naturally recursive -- pretty easy to express and code recursively,
>> and will pretty much drive you crazy if you try to think it through 
>> and code it iteratively, regardless of language. 
> 
> Some fractals, I'd agree with. Bezier curves, though? It never even occurred 
> to me to draw these recursively, and I didn't have any particular difficulty 
> with the iterative method. Am I doing something wrong? 

I am sure you are not doing anything wrong, but there are other ways. 

The usual recursive solution comes in two flavours both, based on what's 
called De Casteljau's algorithm.  In one flavour you use this 
numerically, but the prettiest version is a direct geometric realisation 
of it.  To 

  draw_curve(p1, c1, c2, p2); 

(that's the curve from p1 to p2 using c1 and c2 as control points) you 
calculate 6 mid-points and draw two smaller curves: 

  p1c1 = mid(p1, c1); 
  c1c2 = mid(c1, c2); 
  c2p2 = mid(c2, p2); 
  p1c1c1c2 = mid(p1c1, c1c2); 
  c1c2c2p2 = mid(c1c2, c2p2); 
  m = mid(p1c1c1c2, c1c2c2p2); 

  draw_curve(p1, p1c1, p1c1c1c2, m); 
  draw_curve(m, c1c2c2p2, c2p2, p2); 

To see what's happening, draw the lines p1-c1, c1-c2 and c2-p2.  Now 
draw lines between the mid-points of each consecutive pair of these 
lines.  Then do the same between the mid-points of every consecutive 
pair you now have... and so on.  (If you are like me, you need to draw 
it to see what's happening but it's just the high-tech version of the 
art with string and nails that I remember doing at school.) 

The recursion stops (and you draw a line) when some metric becomes small 
enough.  You can use a recursion count, some measure of the distance 
between the end points, or some measure of the "bend" in the curve (or 
some combination of these, of course). 

<<<<<<<<<

do this 
 draw_curve(p1, p1c1, p1c1c1c2, m); 
  draw_curve(m, c1c2c2p2, c2p2, p2); 
recipe is special that it preserves the shape when dividing the curve on two?
(control points are outside of the bezier so
im not sure what mid of some p1 and c1 yields to)

this may be usefull but it is a lot of mid's
calculation on each pair - compared to strightforward multiplies in normal bezier
I will most probably test it but maybe there is some quick aproximation ot the length that will run ok? (could be bit easier) I will try to find something






> 
> > 2) if i will build a closed shape from few
> > such beziers, how do i should fill with a color to be fast?
> 
> Convex or concave shape? Needing to be clipped or not? Crosses itself or 
> not? With 'islands' or not?
> 
> One way is to start with a cleared 1-bit image the same size as the 
> display, draw the closed shape into that, then floodfill the inside (and 
> you work out the extents as you go along). Then use that as a mask to 
> colour/shade the main display.
> 
> But there are many ways of filling a region defining by a border of set 
> pixels (and yet others where the border is approximated by a closed 
> polygon of short vectors).
> 

this flodd fill i remember form C64 is dead slow think, I think i may only consider not cliped, closed, no-holes version (made from one long curve of n beziers) but it could be both convex-and concave

maybe i just need store x points in lines
then if sgot such result

line[17] is  20  56  59 104 189 234
i konw i need to draw 3 
x-scanlines: 20-56 59-104 189-234
but this will fail if given x point is
both move up move down place (and is 0-pixel
long scanline for itself) how to resolve this
?


> -- 
> Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-28 18:43 -0700
  Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-29 02:59 -0700
    Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 03:51 -0700
      Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-03-29 12:03 +0100
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 05:00 -0700
          Re: chosing "small 2d graphics library"  interface gof@somewhere.invalid (Gof) - 2015-04-01 08:02 +0000
            Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-01 09:40 +0100
              Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-01 04:04 -0700
      Re: chosing "small 2d graphics library"  interface Nobody <nobody@nowhere.invalid> - 2015-03-29 12:50 +0100
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 05:08 -0700
    Re: chosing "small 2d graphics library"  interface Jeff Higgins <jeff@invalid.invalid> - 2015-03-29 09:33 -0400
      Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 07:00 -0700
        Re: chosing "small 2d graphics library"  interface Jeff Higgins <jeff@invalid.invalid> - 2015-03-29 10:38 -0400
          Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 07:43 -0700
      Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 07:24 -0700
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 07:32 -0700
      Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-01 05:00 -0700
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-01 07:25 -0700
    Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 07:36 -0700
      Re: chosing "small 2d graphics library"  interface Jeff Higgins <jeff@invalid.invalid> - 2015-03-29 14:33 -0400
        Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-29 12:36 -0700
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-03-29 13:01 -0700
  chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-02 04:12 -0700
    Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 04:56 -0700
      Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 05:10 -0700
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 05:31 -0700
        Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 09:40 -0700
    Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 13:32 +0100
      Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 05:50 -0700
        Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 14:01 +0100
          Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 06:37 -0700
            Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 14:58 +0100
              Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-02 15:11 +0100
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 15:18 +0100
                Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-02 09:21 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 09:34 -0700
                Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-02 09:47 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 09:45 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 09:57 -0700
                Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-02 10:15 -0700
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 18:34 +0100
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 18:35 +0100
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 17:45 +0100
                Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-02 10:12 -0700
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 18:28 +0100
                Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-03 01:06 +0100
                Re: chosing "small 2d graphics library"  interface luser droog <luser.droog@gmail.com> - 2015-04-02 17:05 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 07:51 -0700
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 15:56 +0100
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 08:14 -0700
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 16:25 +0100
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 08:45 -0700
                Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 17:00 +0100
                Re: chosing "small 2d graphics library"  interface Keith Thompson <kst-u@mib.org> - 2015-04-02 13:03 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-05 14:25 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 09:06 -0700
                Re: chosing "small 2d graphics library"  interface Rosario19 <Ros@invalid.invalid> - 2015-04-02 18:22 +0200
                Re: chosing "small 2d graphics library"  interface Rosario19 <Ros@invalid.invalid> - 2015-04-02 18:40 +0200
                Re: chosing "small 2d graphics library"  interface Robert Wessel <robertwessel2@yahoo.com> - 2015-04-03 00:20 -0500
                Re: chosing "small 2d graphics library"  interface Rosario19 <Ros@invalid.invalid> - 2015-04-04 10:35 +0200
                Re: chosing "small 2d graphics library"  interface CHIN Dihedral <dihedral88888@gmail.com> - 2015-04-04 09:53 -0700
                Re: chosing "small 2d graphics library" interface Noob <root@127.0.0.1> - 2015-04-03 14:27 +0200
                Re: chosing "small 2d graphics library" interface fir <profesor.fir@gmail.com> - 2015-04-03 05:38 -0700
              Re: chosing "small 2d graphics library"  interface Jeff Higgins <jeff@invalid.invalid> - 2015-04-02 19:23 -0400
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-02 23:46 -0700
      Re: chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-02 08:03 -0700
        Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-02 16:14 +0100
          Re: chosing "small 2d graphics library"  interface Keith Thompson <kst-u@mib.org> - 2015-04-02 12:42 -0700
          Re: chosing "small 2d graphics library"  interface CHIN Dihedral <dihedral88888@gmail.com> - 2015-04-03 14:27 -0700
            Re: chosing "small 2d graphics library"  interface Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-03 14:50 -0700
      Re: chosing "small 2d graphics library"  interface Keith Thompson <kst-u@mib.org> - 2015-04-02 10:47 -0700
      Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-02 20:09 +0100
        Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-03 06:02 +0100
          Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-03 11:40 +0100
            Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-03 03:52 -0700
              Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-03 12:05 +0100
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-03 04:36 -0700
                Re: chosing "small 2d graphics library"  interface Bartc <bc@freeuk.com> - 2015-04-03 13:28 +0100
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-03 06:04 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-03 07:28 -0700
                Re: chosing "small 2d graphics library"  interface fir <profesor.fir@gmail.com> - 2015-04-03 12:43 -0700
            Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-03 12:57 +0100
      Re: chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-03 22:25 -0700
        Re: chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-03 22:34 -0700
          Re: chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-03 23:09 -0700
            Re: chosing "small 2d graphics library"  interface Richard Heathfield <rjh@cpax.org.uk> - 2015-04-04 09:23 +0100
    chosing "small 2d graphics library"  interface asetofsymbols@gmail.com - 2015-04-02 07:26 -0700

csiph-web