Debian Codegraph @

fltk/test/draw.py

raw symbols SCIP
1 #
2 # "$Id: draw.py 495 2013-03-30 09:39:45Z andreasheld $"
3 #
4 # fl_draw test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 # Courtesy of G. Lielens!
7 #
8 # FLTK copyright 1998-1999 by Bill Spitzak and others.
9 # pyFLTK copyright 2003 by Andreas Held and others.
10 #
11 # This library is free software you can redistribute it and/or
12 # modify it under the terms of the GNU Library General Public
13 # License, version 2.0 as published by the Free Software Foundation.
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 "[email protected]".
26 #
27
28
29 from fltk import *
30 from math import *
31 import sys
32 from array import *
33
34
35 width = 100
36 height = 100
37 image = array('B')
38
39 def make_image():
40 #image = new uchar[4*width*height];
41 #uchar *p = image;
42 p = image
43 index = 0
44
45 y = 0
46 while y < height:
47 dy = float(y)/(height-1)
48 x = 0
49 while x < width:
50 dx = float(x)/(width-1)
51 #print 255*((1.0-dx)*(1.0-dy))
52 p.append(int(255*((1.0-dx)*(1.0-dy))))
53 index = index+1
54 p.append(int(255*((1.0-dx)*dy)))
55 index = index+1
56 p.append(int(255*(dx*dy)))
57 index = index+1
58 dx = dx-0.5
59 dy = dy-0.5
60 alpha = int(255*sqrt(dx*dx+dy*dy))
61 if alpha < 255:
62 p.append(alpha)
63 else:
64 p.append(255)
65 index = index+1
66 dy = dy+0.5
67 x = x+1
68 y = y+1
69 return None
70
71
72
73 class MyWidget(Fl_Widget):
74 def __init__(self,x,y,w,h,image):
75 Fl_Widget.__init__(self, 0, 0, w, h, "canvas")
76 self._image=image
77 def draw(self):
78 w,h=self.w(),self.h()
79 fl_draw_image(self._image,int(w/2-50),int(h/2-50),width,height,4,0)
80
81
82 window = Fl_Window(400,400)
83 window.color(FL_WHITE)
84 make_image()
85 widget=MyWidget(0,0,400,400,image)
86 window.resizable(window)
87 window.end()
88 window.show(len(sys.argv), sys.argv)
89
90 Fl.run()
91