PreviousUpNext

15.4.1361  src/lib/x-kit/tut/arithmetic-game/splash-images.pkg

## splash-image.pkg

# Compiled by:
#     src/lib/x-kit/tut/arithmetic-game/arithmetic-game-app.lib

stipulate
    package xc =  xclient;                                      # xclient       is from   src/lib/x-kit/xclient/xclient.pkg
    package g2d=  geometry2d;                                   # geometry2d    is from   src/lib/std/2d/geometry2d.pkg
    #
    package wg =  widget;                                       # widget        is from   src/lib/x-kit/widget/old/basic/widget.pkg
    #
    package di =  diver_images;                                 # diver_images  is from   src/lib/x-kit/tut/arithmetic-game/diver-images.pkg
herein

    package splash_images {

        stipulate

            fun bbox []
                    =>
                    { col=>0, row=>0, wide=>0, high=>0 };

                bbox ({ col=>x, row=>y } ! pts)
                    =>
                    bb (x, y, x, y, pts)
                    where
                        fun bb (minx, miny, maxx, maxy,[])
                                => 
                                { col=>minx, row=>miny, wide=>maxx-minx+1, high=>maxy-miny+1 };

                            bb (minx, miny, maxx, maxy, { col=>x, row=>y } ! pts)
                                =>
                                bb ( min (minx, x), min (miny, y),
                                     max (maxx, x), max (maxy, y),
                                     pts
                                   );
                        end;
                    end;
            end;

            # Make a splash by doing a polygon-fill
            # of an appropriate contour:
            #
            fun make_splash_image (root, water_ro_pixmap)
                =
                make_splash_image'
                where
                    screen =  wg::screen_of  root;

                    water_pen
                        =
                        xc::make_pen [ xc::p::FILL_STYLE_STIPPLED, 
                                       xc::p::STIPPLE     water_ro_pixmap,
                                       xc::p::FOREGROUND  xc::rgb8_blue
                                     ];

                    fun make_splash_image' contour
                        =
                        {   (bbox contour) ->  { col, row, wide, high };

                            del_point = { col, row };                   # "del_point" may be "delta_point"...?

                            contour' =  map (\\ p = g2d::point::subtract (p, del_point))
                                           contour;

                            pixmap =  xc::make_readwrite_pixmap  screen  ({ wide, high }, 1);

                            draww  =  xc::drawable_of_rw_pixmap  pixmap;

                            xc::clear_drawable draww;

                            xc::fill_polygon
                                draww
                                water_pen
                                { shape =>  xc::NONCONVEX_SHAPE,
                                  verts =>  contour'
                                };

                            ro_pixmap
                                =
                                xc::make_readonly_pixmap_from_readwrite_pixmap
                                       pixmap;

                            xc::destroy_rw_pixmap  pixmap;

                            { origin => head contour',  data => ro_pixmap }: di::Image;
                        };
                end;


            fun make_point (col, row)
                =
                { col, row => -row };


            little_data
                =
                [ (  0,   0),
                  ( 10,  18),
                  (  6,  15),
                  (  4,  20),
                  (  0,  12),
                  ( -4,  18),
                  ( -7,  15),
                  (-15,  20)
                ];

            medium_data
                =
                [ (  0,   0),
                  ( 20,  30),
                  ( 14,  25),
                  ( 10,  20),
                  (  8,  24),
                  (  5,  21),
                  (  3,  27),
                  (  0,  22), 
                  ( -3,  18),
                  ( -5,  23),
                  ( -7,  25),
                  (-11,  20),
                  (-14,  24),
                  (-18,  21),
                  (-20,  25) 
                ];

            big_data
                =
                [ (  0,   0),
                  ( 30,  35),
                  ( 28,  38),
                  ( 25,  36),
                  ( 23,  32),
                  ( 20,  36),
                  ( 18,  34), 
                  ( 15,  31),
                  ( 13,  37),
                  ( 10,  32),
                  (  8,  34),
                  (  5,  31),
                  (  3,  37),
                  (  0,  32), 
                  ( -3,  28),
                  ( -5,  33),
                  ( -7,  35),
                  (-11,  30),
                  (-14,  34),
                  (-18,  31),
                  (-20,  35),
                  (-21,  30),
                  (-24,  34),
                  (-29,  31),
                  (-32,  37) 
                ];

            splash_list
                =
                map (\\ points = map make_point points) 
                    [ little_data, medium_data, big_data];

        herein

            fun make_splashes arg
                =
                map (make_splash_image arg)
                    splash_list;

        end;                    # stipulate
    };

end;

## COPYRIGHT (c) 1996 AT&T Research.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext