]> gitweb.factorcode.org Git - factor.git/blob - extra/cap/cap.factor
Solution to Project Euler problem 65
[factor.git] / extra / cap / cap.factor
1 ! Copyright (C) 2008 Doug Coleman, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays byte-arrays kernel math namespaces
4 opengl.gl sequences math.vectors ui images images.normalization
5 images.viewer models ui.gadgets.worlds ui.gadgets fry alien.syntax ;
6 IN: cap
7
8 : screenshot-array ( world -- byte-array )
9     dim>> [ first 4 * ] [ second ] bi * <byte-array> ;
10
11 : gl-screenshot ( gadget -- byte-array )
12     [
13         [
14             GL_BACK glReadBuffer
15             GL_PACK_ALIGNMENT 4 glPixelStorei
16             0 0
17         ] dip
18         dim>> first2 GL_RGBA GL_UNSIGNED_BYTE
19     ]
20     [ screenshot-array ] bi
21     [ glReadPixels ] keep ;
22
23 : screenshot ( window -- bitmap )
24     [ <image> ] dip
25     [ gl-screenshot >>bitmap ] [ dim>> >>dim ] bi
26     RGBA >>component-order
27     t >>upside-down?
28     normalize-image ;
29
30 : screenshot. ( window -- )
31     [ screenshot <image-gadget> ] [ title>> ] bi open-window ;