Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_rotate_oval.py
- from Tkinter import *
- root = Tk()
- root.title("Tk Rotate Oval")
- ### root.withdraw() # vs root.deiconify()')
- xm,ym=600,600
- canvas = Canvas(root, width=xm, height=ym)
- canvas.grid()
- from PIL import ImageDraw, ImageTk, Image, ImageGrab
- from random import randrange
- import time
- class Cv(): pass
- cv=Cv()
- 0
- RGB_BLACK=(0,0,0)
- RGB_WHITE=(255,255,255)
- RGB_GRAY=(180,180,180)
- RGB_GRAYLIGHT=(236,236,236)
- RGB_GRAYDARK=(169,169,169)
- RGB_RED=(255,0,0)
- RGB_ORANGE=(255,165,0)
- RGB_YELLOW=(255,255,0)
- RGB_GREEN=(0,128,0)
- RGB_BLUE=(0,0,255)
- RGB_CYAN=(0,255,255)
- RGB_PURPLE=(128,0,128)
- RGB_DARKBLUE=(0,0,139)
- RGB_DARKGREEN=(0,100,0)
- RGB_DEEPPINK=(255,20,147)
- RGB_INDIGO=(75,0,130)
- RGB_LIGHTPURPLE=(204,153,255)
- RGB_LIGHTBLUE=(173,216,230)
- RGB_LIGHTGREEN=(178,255,102)
- RGB_LIGHTYELLOW=(255,255,102)
- RGB_LIME=(0,255,0)
- RGB_OLIVE=(107,142,35)
- RGB_BROWN=(139,69,19)
- RGB_GOLD=(255,215,0)
- RGB_SILVER=(192,192,192)
- RGB_ROYALBLUE=(65,105,225)
- 0
- img = Image.new('RGB', (xm,ym))
- # random.seed(1)
- from math import sin, cos, pi
- def rotate_oval( x1, y1, x2, y2, rotate=0, vertex_count=-1):
- rotate=rotate%180
- if vertex_count == -1:
- vertex_count = int((abs(x1 - x2) + abs(y1 - y2)) * 0.07)
- vertex_count = max(18,vertex_count)
- vertex_count = max(3,vertex_count)
- (x1, x2) = (min(x1, x2), max(x1, x2))
- (y1, y2) = (min(y1, y2), max(y1, y2))
- a = (x2 - x1) / 2
- b = (y2 - y1) / 2
- VERTEX = [ (a * cos(i * 2 * pi / vertex_count), \
- b * sin(i * 2 * pi / vertex_count)) \
- for i in range(vertex_count) ]
- ## rotation
- VERTEX = [( x*cos(pi/180*rotate) + y*sin(pi/180*rotate), y*cos(pi/180*rotate) - x*sin(pi/180*rotate) )
- for (x,y) in VERTEX ]
- ## move center
- VERTEX = [( x + ( x1 + x2 ) / 2, y + ( y1 + y2 ) / 2 )
- for (x,y) in VERTEX ]
- return VERTEX
- if __name__ == '__main__':
- min_x = 20
- min_y = 20
- max_x = 580
- max_y = 580
- for i in range(1000):
- canvas.delete('all')
- '''
- (x1, y1) = (randrange(start=min_x, stop=max_x),
- randrange(start=min_y, stop=max_y))
- (x2, y2) = (randrange(start=min_x, stop=max_x),
- randrange(start=min_y, stop=max_y))
- '''
- x1, y1, x2, y2 = 200, 0, 400, 600
- roto = rotate_oval(x1, y1, x2, y2, i)
- canvas.create_polygon(roto)
- root.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement