Debian Codegraph @

fltk/test/image_array.py

raw symbols SCIP
1 #
2 # "$Id: image_array.py 247 2006-08-22 05:54:01Z andreasheld $"
3 #
4 # Image test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 #
7 # FLTK copyright 1998-1999 by Bill Spitzak and others.
8 # pyFLTK copyright 2003 by Andreas Held and others.
9 #
10 # This library is free software you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License, version 2.0 as published by the Free Software Foundation.
13 #
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Library General Public License for more details.
18 #
19 # You should have received a copy of the GNU Library General Public
20 # License along with this library if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 # USA.
23 #
24 # Please report all bugs and problems to "[email protected]".
25 #
26
27 from fltk import *
28 from math import *
29 import sys
30 from array import *
31
32
33 width = 100
34 height = 100
35 image = array('B')
36
37 def make_image():
38 #image = new uchar[4*width*height];
39 #uchar *p = image;
40 p = image
41 index = 0
42
43 y = 0
44 while y < height:
45 dy = float(y)/(height-1)
46 x = 0
47 while x < width:
48 dx = float(x)/(width-1)
49 #print 255*((1.0-dx)*(1.0-dy))
50 p.append(int(255*((1.0-dx)*(1.0-dy))))
51 index = index+1
52 p.append(int(255*((1.0-dx)*dy)))
53 index = index+1
54 p.append(int(255*(dx*dy)))
55 index = index+1
56 dx = dx-0.5
57 dy = dy-0.5
58 alpha = int(255*sqrt(dx*dx+dy*dy))
59 if alpha < 255:
60 p.append(alpha)
61 else:
62 p.append(255)
63 index = index+1
64 dy = dy+0.5
65 x = x+1
66 y = y+1
67 return None
68
69
70 #globals
71 leftb = None
72 rightb = None
73 topb = None
74 bottomb = None
75 insideb = None
76 overb = None
77 inactb = None
78 b = None
79 w = None
80
81 def button_cb(ptr):
82 i = 0
83 if leftb.value():
84 i = i + FL_ALIGN_LEFT
85 if rightb.value():
86 i = i + FL_ALIGN_RIGHT
87 if topb.value():
88 i = i + FL_ALIGN_TOP
89 if bottomb.value():
90 i = i + FL_ALIGN_BOTTOM
91 if insideb.value():
92 i = i + FL_ALIGN_INSIDE
93 if overb.value():
94 i = i + FL_ALIGN_TEXT_OVER_IMAGE
95 b.align(i)
96 if inactb.value():
97 b.deactivate()
98 else:
99 b.activate()
100 w.redraw()
101
102
103
104 window = Fl_Window(400,400)
105 w = window
106 window.color(FL_WHITE)
107 b = Fl_Button(140,160,120,120,"Image w/Alpha")
108
109 rgb = None
110 dergb = None
111
112 make_image()
113 rgb = Fl_RGB_Image(image, width, height,4)
114 dergb = rgb.copy()
115 dergb.inactive()
116
117 b.image(rgb)
118 b.deimage(dergb)
119
120 leftb = Fl_Toggle_Button(25,50,50,25,"left")
121 leftb.callback(button_cb)
122
123 rightb = Fl_Toggle_Button(75,50,50,25,"right")
124 rightb.callback(button_cb)
125
126 topb = Fl_Toggle_Button(125,50,50,25,"top")
127 topb.callback(button_cb)
128
129 bottomb = Fl_Toggle_Button(175,50,50,25,"bottom");
130 bottomb.callback(button_cb)
131
132 insideb = Fl_Toggle_Button(225,50,50,25,"inside")
133 insideb.callback(button_cb)
134
135 overb = Fl_Toggle_Button(25,75,100,25,"text over")
136 overb.callback(button_cb)
137
138 inactb = Fl_Toggle_Button(125,75,100,25,"inactive")
139 inactb.callback(button_cb)
140
141 window.resizable(window)
142 window.end()
143 window.show(len(sys.argv), sys.argv)
144
145 Fl.run()