~jtaylor/ubuntu/natty/pyfltk/fix-779340

« back to all changes in this revision

Viewing changes to fltk/test/image_array.py

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2009-03-13 20:47:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090313204700-ra4hgdlhxzrccas3
Tags: upstream-1.1.3
ImportĀ upstreamĀ versionĀ 1.1.3

Show diffs side-by-side

added added

removed removed

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