File size: 1,583 Bytes
d966012
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ae8042
 
d966012
 
 
 
 
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
import gradio as gr
from PIL import Image, ImageDraw
import numpy as np

def draw_lines(x, y):
    # キャンバスのサイズ
    width, height = 1024, 1024
    # 白背景のキャンバスを作成
    image = Image.new("RGB", (width, height), "white")
    draw = ImageDraw.Draw(image)

    # 直線を描画する関数
    def draw_rotated_line(angle):
        rad = np.radians(angle)
        cos_val = np.cos(rad)
        sin_val = np.sin(rad)
        # キャンバスの対角線の長さを計算
        diagonal_length = np.sqrt(width**2 + height**2)
        # 中心から端までの線を計算
        line_length = diagonal_length
        # 線の始点と終点を計算
        start_x = x - line_length * cos_val
        start_y = y - line_length * sin_val
        end_x = x + line_length * cos_val
        end_y = y + line_length * sin_val
        # 線を描画
        draw.line((start_x, start_y, end_x, end_y), fill="blue", width=2)

    # 5度ずつ回転させながら直線を描画
    for angle in range(0, 360, 5):
        draw_rotated_line(angle)

    # PIL Imageをnumpy配列に変換
    return np.array(image)

# Gradioインターフェース
iface = gr.Interface(fn=draw_lines,
                     inputs=[gr.Slider(minimum=0, maximum=1024, default=512, label="X座標"),
                             gr.Slider(minimum=0, maximum=1024, default=512, label="Y座標")],
                     outputs="image",
                     live=True,
                     title="VP preprocess")

iface.launch()