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.04s 23128KB
stdin
import turtle
import random

# 屏幕设置
screen = turtle.Screen()
screen.setup(width=375, height=700)
screen.title("Merry Christmas")
screen.bgcolor("midnight blue")

# 画笔初始化
pen = turtle.Turtle()
pen.speed("fastest")
pen.hideturtle()

# 绘制圣诞树函数
def draw_tree(depth, length):
    if depth == 0:
        return
    pen.forward(length)
    pen.left(30)
    draw_tree(depth - 1, length * 0.75)
    pen.right(60)
    draw_tree(depth - 1, length * 0.75)
    pen.left(30)
    pen.backward(length)

# 绘制装饰球
def draw_ornament(x, y, color):
    ornament = turtle.Turtle()
    ornament.hideturtle()
    ornament.speed("fastest")
    ornament.penup()
    ornament.goto(x, y)
    ornament.color(color)
    ornament.begin_fill()
    ornament.circle(5)
    ornament.end_fill()

# 主程序
pen.penup()
pen.goto(0, -200)
pen.pendown()
pen.color("dark green")
draw_tree(10, 100)

# 随机添加装饰球
colors = ["red", "yellow", "blue", "orange", "white", "purple"]
for _ in range(20):
    x = random.randint(-150, 150)
    y = random.randint(-100, 100)
    color = random.choice(colors)
    draw_ornament(x, y, color)

turtle.done()
stdout
Standard output is empty