| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
from fltk import * |
| 25 |
import sys |
| 26 |
|
| 27 |
width = 75 |
| 28 |
height = 75 |
| 29 |
image = [] |
| 30 |
|
| 31 |
def make_image(): |
| 32 |
global image |
| 33 |
for y in range(0, height, 1): |
| 34 |
Y = (1.0 *y)/(height-1) |
| 35 |
for x in range(0, width, 1): |
| 36 |
X = (1.0 * x)/(width-1) |
| 37 |
image.append(int((255*((1-X)*(1-Y))))) |
| 38 |
image.append(int((255*((1-X)*Y)))) |
| 39 |
image.append(int((255*(X*Y)))) |
| 40 |
|
| 41 |
class Pens(Fl_Box): |
| 42 |
def __init__(self, X, Y, W, H, L): |
| 43 |
Fl_Box.__init__(self, X,Y,W,H,L) |
| 44 |
|
| 45 |
def draw(self): |
| 46 |
|
| 47 |
i = 0 |
| 48 |
while i < 3*8: |
| 49 |
fl_color(FL_GRAY_RAMP+i) |
| 50 |
fl_line(self.x()+i, self.y(), self.x()+i, self.y()+self.h()) |
| 51 |
i += 1 |
| 52 |
|
| 53 |
c = FL_GRAY |
| 54 |
fullcolor_cell = FL_FREE_COLOR |
| 55 |
|
| 56 |
def cb1(ptr, box): |
| 57 |
global c |
| 58 |
c = fl_show_colormap(c) |
| 59 |
box.color(c) |
| 60 |
parent = box.parent() |
| 61 |
parent.redraw() |
| 62 |
|
| 63 |
def cb2(ptr, box): |
| 64 |
global c |
| 65 |
r = 0 |
| 66 |
g = 0 |
| 67 |
b = 0 |
| 68 |
(r, g, b) = Fl.get_color(c) |
| 69 |
(status, r, g, b) = fl_color_chooser("New color:", r,g,b) |
| 70 |
if status == 0: |
| 71 |
return None |
| 72 |
c = fullcolor_cell |
| 73 |
Fl.set_color(fullcolor_cell, r, g, b) |
| 74 |
box.color(fullcolor_cell) |
| 75 |
parent = box.parent() |
| 76 |
parent.redraw() |
| 77 |
|
| 78 |
|
| 79 |
Fl.set_color(fullcolor_cell,145,159,170) |
| 80 |
window = Fl_Window(400,400) |
| 81 |
|
| 82 |
box = Fl_Box(50,50,300,300) |
| 83 |
box.box(FL_THIN_DOWN_BOX) |
| 84 |
c = fullcolor_cell |
| 85 |
box.color(c) |
| 86 |
|
| 87 |
b1 = Fl_Button(130,120,140,30,"fl_show_colormap") |
| 88 |
b1.callback(cb1, box) |
| 89 |
|
| 90 |
b2 = Fl_Button(130,160,140,30,"fl_choose_color") |
| 91 |
b2.callback(cb2,box) |
| 92 |
|
| 93 |
image_box = Fl_Box(140,200,120,120,"") |
| 94 |
make_image() |
| 95 |
|
| 96 |
|
| 97 |
i = Fl_RGB_Image(image, width, height) |
| 98 |
i.label(image_box) |
| 99 |
|
| 100 |
b = Fl_Box(140,335,120,0,"Example of fl_draw_image()") |
| 101 |
|
| 102 |
p = Pens(80,200,3*8,120,"lines") |
| 103 |
p.align(FL_ALIGN_TOP) |
| 104 |
p.redraw() |
| 105 |
|
| 106 |
window.end() |
| 107 |
window.show(len(sys.argv), sys.argv) |
| 108 |
Fl.run() |
| 109 |
|