Rename ..Shapes..Data..vector to ..Shapes..Data..array
[shapes.git] / examples / features / png_array.shape
blobd65629c0709cc779ea2d1728de942905b614e4f3
1 /** This file is part of Shapes.
2  **
3  ** Shapes is free software: you can redistribute it and/or modify
4  ** it under the terms of the GNU General Public License as published by
5  ** the Free Software Foundation, either version 3 of the License, or
6  ** any later version.
7  **
8  ** Shapes is distributed in the hope that it will be useful,
9  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  ** GNU General Public License for more details.
12  **
13  ** You should have received a copy of the GNU General Public License
14  ** along with Shapes.  If not, see <http://www.gnu.org/licenses/>.
15  **
16  ** Copyright 2009, 2014, 2015 Henrik Tidefelt
17  **/
19 ##echo To run this example you need to download the PngSuite by Willem van Schaik, and extract the files in the raster_data/PngSuite directory.
21 /**
22  ** The PngSuite can be downloaded from
23  **   http://www.schaik.com/pngsuite/pngsuite.html
24  **/
26 /**
27  ** This example contains some code that is commented out since I didn't want to add too many raster image files to the repository.
28  ** Knowing that they all were loaded fine once upon the time, I think that the remaining selection of examples from the PngSuite
29  ** is large enough to give reasonable coverage.
30  **
31  ** Since Shapes does not support the PNG gamma correction feature, no such examples from the suite are included by this file.
32  ** Similarly, background colors will never be used by Shapes, so these examples are also ignored.
33  **/
35 ##lookin ..Shapes
36 ##lookin ..Shapes..Geometry
37 ##lookin ..Shapes..Layout
39 dx: 5cm
40 dy: 5cm
42 checkers:
44   side: 0.1*dx
45   square: Traits..@nonstroking:[Traits..gray 0.9] | [Graphics..fill [Geometry..rectangle (0m,0m) (side,side)]]
46   ( Traits..@nonstroking:[Traits..gray 0.7] | [Graphics..fill [Geometry..rectangle (0m,0m) (dx,dy)]] )
47   &
48   [[Data..range 0m dx-0.5*side side].foldl
49    \ p x → [[Data..range [if [Numeric..Math..mod x+0.5*side 2*side] < side 0m side] dx-0.5*side 2*side].foldl
50             \ p y → ( p & ( square >> [shift (x,y)] ) )
51             p]
52    Graphics..null]
53 } >> center >> [scale 0.7]
55 colorStrs: [Data..array `-bw´ `´]
56 depthStrs: [Data..array '1 '2 '4 '8 '16]
58 helper: \ img →
60   [Layout..center checkers & [Layout..center img] (0,~1)]
61   & [Layout..center ( Text..newText << ( String..newString << img.space << ` ´ << img.depth ) ) (0,1)]
64 |** IO..•page <<
65 |** [[Data..range '0 colorStrs.size-'1].foldl
66 |**  \ p i →
67 |**    ( p & [[shift (0,~i*dy)] [[Data..range '0 depthStrs.size-'1].foldl
68 |**            \ p j → ( p
69 |**                      & [[shift (j*dx,0)] [helper [Graphics..import_raster (String..newString << `logo´ << [colorStrs i] << [String..sprintf `-%d´ [depthStrs j]] << `.png´ ) resolution:0.2bp]]] )
70 |**            p]] )
71 |**    null]
73 suite_helper: \ filename resolution:2bp →
75   img: [Graphics..import_raster `raster_data/PngSuite/´ + filename + `.png´ resolution:resolution override:false]
76   [Layout..center checkers & [Layout..center img] & (Traits..@dash:[Traits..dashpattern 1mm 1mm] | [Graphics..stroke [Layout..bbox [Layout..center img]]])(0,~1)]
77   & [Layout..center ( Text..newText << ( String..newString << img.space << ` ´ << img.depth << "{n} << filename << "{n} ) ) (0,1)]
80 |** IO..•page << [suite_helper `palette_text_1´ resolution:0.5bp] >> [shift (0*dx,~3*dy)]
81 |** IO..•page << [suite_helper `alpha_text_8´ resolution:0.5bp] >> [shift (1*dx,~3*dy)]
83 IO..•page << [suite_helper `bgai4a08´] >> [shift (0*dx,~4*dy)]
84 IO..•page << [suite_helper `bgai4a16´] >> [shift (1*dx,~4*dy)]
85 IO..•page << [suite_helper `bgan6a08´] >> [shift (2*dx,~4*dy)]
86 IO..•page << [suite_helper `bgan6a16´] >> [shift (3*dx,~4*dy)]
88 IO..•page << [suite_helper `basn0g01´] >> [shift (0*dx,~5*dy)]
89 IO..•page << [suite_helper `basn2c08´] >> [shift (1*dx,~5*dy)]
90 IO..•page << [suite_helper `basn2c16´] >> [shift (2*dx,~5*dy)]
92 IO..•page << [suite_helper `basn0g02´] >> [shift (0*dx,~6*dy)]
93 IO..•page << [suite_helper `basn0g04´] >> [shift (1*dx,~6*dy)]
94 IO..•page << [suite_helper `basn0g08´] >> [shift (2*dx,~6*dy)]
95 IO..•page << [suite_helper `basn0g16´] >> [shift (3*dx,~6*dy)]
97 IO..•page << [suite_helper `basn3p01´] >> [shift (0*dx,~7*dy)]
98 IO..•page << [suite_helper `basn3p02´] >> [shift (1*dx,~7*dy)]
99 IO..•page << [suite_helper `basn3p04´] >> [shift (2*dx,~7*dy)]
100 IO..•page << [suite_helper `basn3p08´] >> [shift (3*dx,~7*dy)]
102 IO..•page << [suite_helper `basn4a08´] >> [shift (0*dx,~8*dy)]
103 IO..•page << [suite_helper `basn4a16´] >> [shift (1*dx,~8*dy)]
104 IO..•page << [suite_helper `basn6a08´] >> [shift (2*dx,~8*dy)]
105 IO..•page << [suite_helper `basn6a16´] >> [shift (3*dx,~8*dy)]
107 IO..•page << [suite_helper `cdfn2c08´] >> [shift (0*dx,~9*dy)]
108 IO..•page << [suite_helper `cdhn2c08´] >> [shift (1*dx,~9*dy)]
109 IO..•page << [suite_helper `cdsn2c08´] >> [shift (2*dx,~9*dy)]
110 IO..•page << [suite_helper `cdun2c08´] >> [shift (3*dx,~9*dy)]