-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathUFO026.py
More file actions
50 lines (37 loc) · 1.75 KB
/
UFO026.py
File metadata and controls
50 lines (37 loc) · 1.75 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from anime2021.anime import ACanvas, AShape, AStudio, ARectangle, ACircle, RollingPolygon, AImage, test_shape, TrailCircle
import os, IPython, io, requests
from PIL import Image, ImageDraw, ImageFont
from apng import APNG
alien_ufo = 'https://1.bp.blogspot.com/-8vjnbp_AXMM/USSkq9AIKTI/AAAAAAAANV0/PQ6FLf-xUks/s1600/alien_ufo.png'
hawaii_maunakea = 'https://2.bp.blogspot.com/-A0Rk-ZNi4OI/VXOUSDVDoAI/AAAAAAAAuJU/4NngWeOUZW4/s400/hawaii_maunakea.png'
import math
class AUFO(AShape):
color: any
def __init__(self, width=100, height=None, cx=None, cy=None, image=alien_ufo):
AShape.__init__(self, width, height, cx, cy)
if image.startswith('http'):
self.pic = Image.open(io.BytesIO(requests.get(image).content))
else:
self.pic = Image.open(image)
def render(self, canvas: ACanvas, frame: int):
ox, oy, w, h = self.bounds()
pic = self.pic.resize((int(w), int(h)))
canvas.image.paste(pic, (int(ox), int(oy)), pic)
def FlyingUFO(shape, A=100, B=100, a=1, b=1, delta=0):
# スタジオを用意
studio = AStudio(400,300)
# スタジオに背景を追加する
studio.append(AUFO(width=400, height=300, image=hawaii_maunakea))
# スタジオにUFOを追加する
studio.append(shape)
frames = 60
for t in range(frames):
x = 200 + A*math.cos(a*(2*math.pi*t/frames))
y = 150 - B*math.sin(b*(2*math.pi*t/frames) + delta)
# 被写体の中心を移動させる
shape.cx = x
shape.cy = y
# 全ての移動が終わったら、撮影
studio.render()
# 動画を編集して表示する
return studio.create_anime(delay=50)