IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Free Pascal Discussion :

Dessiner un disque [Free Pascal]


Sujet :

Free Pascal

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 130
    Billets dans le blog
    9
    Par défaut Dessiner un disque
    Bonjour !

    J'aimerais faire une interface graphique pour un Puissance 4, et je cherche le moyen de dessiner de beaux disques. Vos exemples seraient les bienvenus.

    Pour commencer, je suis allé regarder du côté de la librairie AggPas. Les exemples sont impressionnants, mais un peu compliqués je trouve. J'ai fait un extrait de l'exemple alpha_gradient. (Il y a peut-être des choses en trop dans le code, notamment dans la liste des unités.)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
     
    // AggPas 2.3 RM1
     
    program alpha_gradient2;
     
    uses
      agg_basics,
      agg_platform_support,
      agg_color,
      agg_pixfmt,
      agg_pixfmt_rgb,
      agg_ctrl,
      agg_spline_ctrl,
      agg_renderer_base,
      agg_renderer_scanline,
      agg_rasterizer_scanline_aa,
      agg_scanline,
      agg_scanline_u,
      agg_render_scanlines,
      agg_array,
      agg_ellipse,
      agg_vcgen_stroke,
      agg_trans_affine,
      agg_math;
     
    {$I agg_mode.inc}
     
    const
      flip_y = true;
     
    type
      the_application = object(platform_support)
        m_x, m_y: array[0..2] of double;
        m_dx, m_dy: double;
        m_idx: int;
        m_alpha: spline_ctrl;
        constructor Construct(format_: pix_format_e; flip_y_: boolean);
        destructor Destruct;
        procedure fill_color_array(array_: pod_auto_array_ptr; begin_, middle_, end_: aggclr_ptr);
        procedure on_draw; virtual;
      end;
     
    constructor the_application.Construct;
    begin
      inherited Construct(format_, flip_y_);
      m_alpha.Construct(2, 2, 200, 30, 6, not flip_y_);
      m_idx:= -1;
      m_x[0 ]:= 257;
      m_y[0 ]:= 60;
      m_x[1 ]:= 369;
      m_y[1 ]:= 170;
      m_x[2 ]:= 143;
      m_y[2 ]:= 310;
      m_alpha.point_(0, 0.0, 0.0);
      m_alpha.point_(1, 1.0/5.0, 1.0-4.0/5.0);
      m_alpha.point_(2, 2.0/5.0, 1.0-3.0/5.0);
      m_alpha.point_(3, 3.0/5.0, 1.0-2.0/5.0);
      m_alpha.point_(4, 4.0/5.0, 1.0-1.0/5.0);
      m_alpha.point_(5, 1.0, 1.0);
      m_alpha.update_spline;
      add_ctrl(@m_alpha);
    end;
     
    destructor the_application.Destruct;
    begin
      inherited Destruct;
      m_alpha.Destruct;
    end;
     
    procedure the_application.fill_color_array;
    var
      i: unsigned;
    begin
      i:= 0;
      while i < 128 do
      begin
        aggclr_ptr(array_.array_operator(i))^:= begin_.gradient(middle_, i/128.0);
        inc(i);
      end;
      while i < 256 do
      begin
        aggclr_ptr(array_.array_operator(i))^:= middle_.gradient(end_, (i-128)/128.0);
        inc(i);
      end;
    end;
     
    procedure the_application.on_draw;
    var
      pf: pixel_formats;
      rgba, rgbb, rgbc: aggclr;
      ren_base: renderer_base;
      ren_solid: renderer_scanline_aa_solid;
      sl: scanline_u8;
      ras: rasterizer_scanline_aa;
      ell: ellipse;
      i,w,h: unsigned;
    begin
      pixfmt_bgr24(pf, rbuf_window);
      ren_base.Construct(@pf);
      ren_solid.Construct(@ren_base);
      rgba.ConstrDbl(1, 1, 1);
      ren_base.clear(@rgba);
      sl.Construct;
      ras.Construct;
      ell.Construct;
      RandSeed := 1234;
      w := trunc(_width);
      h := trunc(_height);
      for i := 0 to 99 do
      begin
        ell.init(
          Random($7fff) mod w,
          Random($7fff) mod h,
          Random($7fff) mod 60 + 5,
          Random($7fff) mod 60 + 5,
          50
        );
        rgba.ConstrDbl(
          Random($7fff)/$7fff,
          Random($7fff)/$7fff,
          Random($7fff)/$7fff,
          Random($7fff)/$7fff/2.0
        );
        ren_solid.color_(@rgba);
        ras.add_path(@ell);
        render_scanlines(@ras, @sl, @ren_solid);
      end;
      sl.Destruct;
      ras.Destruct;
    end;
     
    var
      app: the_application;
     
    begin
      app.Construct(pix_format_bgr24,flip_y);
      app.caption_('AGG Example');
      if app.init(400, 320, window_resize) then
        app.run;
      app.Destruct;
    end.
    Images attachées Images attachées  

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Dessiner un cercle (disque)
    Par magicvinni dans le forum Général Python
    Réponses: 2
    Dernier message: 23/01/2015, 10h47
  2. dessin d'un disque
    Par Archimède dans le forum Débuter
    Réponses: 14
    Dernier message: 26/09/2010, 12h22
  3. Dessiner un cercle et non un disque.
    Par macRiaz dans le forum Android
    Réponses: 3
    Dernier message: 19/03/2010, 17h23
  4. [Débutant] Dessiner un disque sur une image
    Par chevalvapeur dans le forum Images
    Réponses: 5
    Dernier message: 07/12/2009, 15h40
  5. Réponses: 3
    Dernier message: 26/01/2009, 14h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo