| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
from fltk import * |
| 36 |
import sys |
| 37 |
import math |
| 38 |
|
| 39 |
w01 = None |
| 40 |
w1 = None |
| 41 |
slider0 = None |
| 42 |
|
| 43 |
|
| 44 |
def star(w, h, n): |
| 45 |
fl_push_matrix() |
| 46 |
fl_translate(w/2, h/2) |
| 47 |
fl_scale(w/2, h/2) |
| 48 |
|
| 49 |
for i in range(n): |
| 50 |
val_i = 2*math.pi*i/n+.1 |
| 51 |
j = i+1 |
| 52 |
while j < n: |
| 53 |
val_j = 2*math.pi*j/n+.1 |
| 54 |
fl_begin_line(); |
| 55 |
fl_vertex(math.cos(val_i), math.sin(val_i)) |
| 56 |
fl_vertex(math.cos(val_j), math.sin(val_j)) |
| 57 |
fl_end_line() |
| 58 |
j = j+1 |
| 59 |
|
| 60 |
fl_pop_matrix() |
| 61 |
|
| 62 |
|
| 63 |
sides = [20,20] |
| 64 |
|
| 65 |
def slider_cb(slider, v): |
| 66 |
sides[v] = int(slider.value()) |
| 67 |
|
| 68 |
slider.parent().child(0).redraw() |
| 69 |
|
| 70 |
|
| 71 |
def bad_draw(w,h,which): |
| 72 |
fl_color(FL_BLACK) |
| 73 |
fl_rectf(0,0,w,h) |
| 74 |
fl_color(FL_WHITE) |
| 75 |
star(w,h,sides[which]); |
| 76 |
|
| 77 |
|
| 78 |
class single_blink_window(Fl_Single_Window): |
| 79 |
def __init__(self, x, y, w, h, l): |
| 80 |
Fl_Single_Window.__init__(self, x, y, w, h, l) |
| 81 |
self.resizable(self) |
| 82 |
|
| 83 |
def draw(self): |
| 84 |
bad_draw(self.w(), self.h(), 0) |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
class double_blink_window(Fl_Double_Window): |
| 91 |
def __init__(self, x, y, w, h, l): |
| 92 |
Fl_Double_Window.__init__(self, x, y, w, h, l) |
| 93 |
self.resizable(self) |
| 94 |
|
| 95 |
def draw(self): |
| 96 |
bad_draw(self.w(), self.h(), 1) |
| 97 |
|
| 98 |
|
| 99 |
if __name__ == '__main__': |
| 100 |
if Fl.visual(FL_DOUBLE) == 0: |
| 101 |
print("Xdbe not supported, faking double buffer with pixmaps.") |
| 102 |
|
| 103 |
w01 = Fl_Window(420,465,"Fl_Single_Window") |
| 104 |
w01.box(FL_FLAT_BOX) |
| 105 |
w01.thiswon = 0 |
| 106 |
w1 = single_blink_window(10,10,400,400,"Fl_Single_Window") |
| 107 |
w1.box(FL_FLAT_BOX) |
| 108 |
w1.color(FL_BLACK) |
| 109 |
w1.end() |
| 110 |
slider0 = Fl_Hor_Slider(30,420,360,25) |
| 111 |
slider0.range(2,30) |
| 112 |
slider0.step(1) |
| 113 |
slider0.value(sides[0]) |
| 114 |
slider0.callback(slider_cb, 0) |
| 115 |
w01.end() |
| 116 |
|
| 117 |
w02 = Fl_Window(420,465,"Fl_Double_Window") |
| 118 |
w02.box(FL_FLAT_BOX) |
| 119 |
w2 = double_blink_window(10,10,400,400,"Fl_Double_Window") |
| 120 |
w2.box(FL_FLAT_BOX) |
| 121 |
w2.color(FL_BLACK) |
| 122 |
w2.end() |
| 123 |
slider1 = Fl_Hor_Slider(30,420,360,25) |
| 124 |
slider1.range(2,30) |
| 125 |
slider1.step(1) |
| 126 |
slider1.value(sides[0]) |
| 127 |
slider1.callback(slider_cb, 1) |
| 128 |
w02.end() |
| 129 |
|
| 130 |
w01.show(len(sys.argv), sys.argv) |
| 131 |
w02.show() |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
Fl.run() |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|