fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.08s 52556KB
stdin
import random
from math import sin, cos, pi
import tkinter as tk

# 画布参数
CANVAS_WIDTH = 640   # 画布的宽
CANVAS_HEIGHT = 480  # 画布的高
CANVAS_CENTER_X = CANVAS_WIDTH / 2   # 画布中心的X轴坐标
CANVAS_CENTER_Y = CANVAS_HEIGHT / 2  # 画布中心的Y轴坐标
IMAGE_ENLARGE = 15   # 放大比例
HEART_COLOR = "pink" # 心的颜色

def heart_function(t, shrink_ratio: float = IMAGE_ENLARGE):
    """爱心函数生成器"""
    # 基础函数
    x = 16 * sin(t) ** 3
    y = -(13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t))
    # 放大
    x *= shrink_ratio
    y *= shrink_ratio
    # 移到画布中央
    x += CANVAS_CENTER_X
    y += CANVAS_CENTER_Y
    return int(x), int(y)

# 创建窗口和画布
root = tk.Tk()
canvas = tk.Canvas(root, width=CANVAS_WIDTH, height=CANVAS_HEIGHT, bg="black")
canvas.pack()

# 绘制爱心(通过大量点来构成爱心形状)
for _ in range(1000):
    t = random.uniform(0, 2*pi)
    x, y = heart_function(t)
    canvas.create_point(x, y, fill=HEART_COLOR, width=1)

# 启动窗口主循环
root.mainloop()
stdout
Standard output is empty