mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 21:33:49 +00:00
distribution. (For further information see, <http://www.cairographics.org/>.) The binding is currently fairly complete (enough for the cairo sample and tutorial programs to be work in Mercury). The main things missing are: * scaled fonts * a few operations on patterns (grep for NYI) * support for X, Quartz, or Win32 surfaces * font backends other than the builtin toy one TODO: I'll add README files, Makefiles, update the NEWS file, etc in a separate change. extras/graphics/mercury_cairo/*.m: extras/graphics/mercury_cairo/tutorial/*.m: extras/graphics/mercury_cairo/samples/*.m: extras/graphics/mercury_cairo/samples/data/*.png: Add the Mercury cairo binding.
48 lines
1.5 KiB
Mathematica
48 lines
1.5 KiB
Mathematica
:- module gradient.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%----------------------------------------------------------------------------%
|
|
%----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module cairo.
|
|
:- import_module cairo.image.
|
|
:- import_module cairo.path.
|
|
:- import_module cairo.pattern.
|
|
:- import_module cairo.png.
|
|
|
|
:- import_module float.
|
|
:- import_module math.
|
|
|
|
%----------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
cairo.image.create_surface(format_argb32, 256, 256, Surface, !IO),
|
|
cairo.create_context(Surface, Context, !IO),
|
|
|
|
pattern.create_linear(0.0, 0.0, 0.0, 256.0, LinPat, !IO),
|
|
pattern.add_color_stop_rgba(LinPat, 1.0, 0.0, 0.0, 0.0, 1.0, !IO),
|
|
pattern.add_color_stop_rgba(LinPat, 0.0, 1.0, 1.0, 1.0, 1.0, !IO),
|
|
path.rectangle(Context, 0.0, 0.0, 256.0, 256.0, !IO),
|
|
cairo.set_source(Context, LinPat, !IO),
|
|
cairo.fill(Context, !IO),
|
|
|
|
pattern.create_radial(115.2, 102.4, 25.6, 102.4, 102.4, 128.0,
|
|
RadPat, !IO),
|
|
pattern.add_color_stop_rgba(RadPat, 0.0, 1.0, 1.0, 1.0, 1.0, !IO),
|
|
pattern.add_color_stop_rgba(RadPat, 1.0, 0.0, 0.0, 0.0, 1.0, !IO),
|
|
cairo.set_source(Context, RadPat, !IO),
|
|
path.arc(Context, 128.0, 128.0, 76.8, 0.0, 2.0 * pi, !IO),
|
|
cairo.fill(Context, !IO),
|
|
|
|
write_surface_to_png(Surface, "gradient.png", !IO).
|
|
|
|
%----------------------------------------------------------------------------%
|
|
:- end_module gradient.
|
|
%----------------------------------------------------------------------------%
|