Skip to content

Instantly share code, notes, and snippets.

@tukachev
Created December 30, 2024 20:35
Show Gist options
  • Save tukachev/96a93fdfeb69a7ef59ce789d2cb8770b to your computer and use it in GitHub Desktop.
Save tukachev/96a93fdfeb69a7ef59ce789d2cb8770b to your computer and use it in GitHub Desktop.
library(ggplot2)
library(ggtext)
set.seed(666)
# Функция для генерации случайных точек внутри треугольника
generate_random_points <- function(n, x_min, x_max, y_min, y_max) {
points <- data.frame(x = numeric(0), y = numeric(0))
while (nrow(points) < n) {
x <- runif(1, x_min, x_max)
y <- runif(1, y_min, y_max)
if (y <= -3 * abs(x - 5) + 15) { # Условие треугольника
points <- rbind(points, data.frame(x = x, y = y))
}
}
points
}
# Координаты треугольника (елочка)
tree <- data.frame(
x = c(0, 10, 5, 0),
y = c(0, 0, 15, 0)
)
# Координаты ствола (прямоугольник)
trunk <- data.frame(
x = c(4, 6, 6, 4, 4),
y = c(0, 0, -3, -3, 0)
)
# Генерация точек для игрушек
toy_points <- generate_random_points(30, 0, 10, 0, 15)
# Эмодзи для игрушек
emojis <- c("🎄", "🎁", "✨", "🎶", "❄️", "🎅", "🔔", "🎉", "🎇", "⭐", "🎆", "🌟", "🎈", "🎊", "🎐", "⛄", "🧣", "🧤", "🧥", "🧦", "🧧", "🍪", "🍺", "🎀", "🎋", "🎍", "🎎", "🎏", "🍰", "🍮", "🍫", "🍬", "🍭", "🍩", "🍷")
toy_points$emoji <- sample(emojis, nrow(toy_points), replace = TRUE)
# Создание графика
ggplot() +
# Елочка
geom_polygon(data = tree, aes(x = x, y = y), fill = "darkgreen", color = "darkgreen") +
# Ствол
geom_polygon(data = trunk, aes(x = x, y = y), fill = "saddlebrown") +
scale_x_continuous(limits = c(-1, 11)) +
scale_y_continuous(limits = c(-5, 17)) +
# Игрушки
geom_text(data = toy_points, aes(x = x, y = y, label = emoji), size = 6) +
# Звезда на верхушке
geom_text(aes(x = 4.1, y = 15.5, label = "⭐"),
size = 10, hjust = 0, vjust = 0
) +
labs(
title = "C НОВЫМ 2025 ГОДОМ!",
caption = "Новогодняя елочка с игрушками-эмодзи 🎄 от ChatGPT"
) +
coord_fixed() +
theme_void() +
theme(
plot.title = element_markdown(size = 16, face = "bold"),
plot.title.position = "plot"
)
ggsave("yolochka.png", bg = "white", dpi = 300, width = 5, height = 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment