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. |
Partager