Advertisement
Guest User

claudes_lil_art_show

a guest
Mar 19th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.16 KB | None | 0 0
  1. # --- [2025-03-19 18:25:49] ---
  2. # Code executed by Claude:
  3.  
  4. # Ensure plot is displayed in RStudio
  5. if (!("package:ggplot2" %in% search())) {
  6. if (requireNamespace("ggplot2", quietly = TRUE)) {
  7. library(ggplot2)
  8. }
  9. }
  10.  
  11. # Execute the plot code
  12.  
  13. library(ggplot2)
  14. library(dplyr)
  15.  
  16. # Set seed for reproducibility
  17. set.seed(42)
  18.  
  19. # Generate data for 5000 points
  20. n <- 5000
  21. celestial_data <- data.frame(
  22. x = rnorm(n),
  23. y = rnorm(n)
  24. )
  25.  
  26. # Add some flowing patterns
  27. celestial_data <- celestial_data %>%
  28. dplyr::mutate(
  29. size = abs(x*y)/5,
  30. alpha = 1/(1 + exp(-abs(x*y))),
  31. group = sample(1:20, n, replace = TRUE)
  32. )
  33.  
  34. # Create the plot
  35. ggplot(celestial_data, aes(x, y, color = size, alpha = alpha, size = size)) +
  36. geom_point() +
  37. scale_color_gradient(low = "#3A1C71", high = "#FFAF7B") +
  38. theme_void() +
  39. theme(
  40. legend.position = "none",
  41. panel.background = element_rect(fill = "black"),
  42. plot.background = element_rect(fill = "black")
  43. ) +
  44. labs(title = "Celestial Drift")
  45.  
  46.  
  47.  
  48. # --- [2025-03-19 18:25:59] ---
  49. # Code executed by Claude:
  50.  
  51. # Ensure plot is displayed in RStudio
  52. if (!("package:ggplot2" %in% search())) {
  53. if (requireNamespace("ggplot2", quietly = TRUE)) {
  54. library(ggplot2)
  55. }
  56. }
  57.  
  58. # Execute the plot code
  59.  
  60. library(ggplot2)
  61. library(dplyr)
  62.  
  63. # Set seed for reproducibility
  64. set.seed(42)
  65.  
  66. # Generate data for 2000 points
  67. n <- 2000
  68. celestial_data <- data.frame(
  69. x = rnorm(n),
  70. y = rnorm(n)
  71. )
  72.  
  73. # Add some flowing patterns
  74. celestial_data <- celestial_data %>%
  75. dplyr::mutate(
  76. size = abs(x*y)/5,
  77. alpha = 1/(1 + exp(-abs(x*y))),
  78. group = sample(1:20, n, replace = TRUE)
  79. )
  80.  
  81. # Create the plot
  82. ggplot(celestial_data, aes(x, y, color = size, alpha = alpha, size = size)) +
  83. geom_point() +
  84. scale_color_gradient(low = "#3A1C71", high = "#FFAF7B") +
  85. theme_void() +
  86. theme(
  87. legend.position = "none",
  88. panel.background = element_rect(fill = "black"),
  89. plot.background = element_rect(fill = "black")
  90. ) +
  91. coord_fixed() +
  92. labs(title = "Celestial Drift")
  93.  
  94.  
  95.  
  96. # --- [2025-03-19 18:26:11] ---
  97. # Code executed by Claude:
  98.  
  99. # Ensure plot is displayed in RStudio
  100. if (!("package:ggplot2" %in% search())) {
  101. if (requireNamespace("ggplot2", quietly = TRUE)) {
  102. library(ggplot2)
  103. }
  104. }
  105.  
  106. # Execute the plot code
  107.  
  108. library(ggplot2)
  109. library(dplyr)
  110.  
  111. # Set seed for reproducibility
  112. set.seed(42)
  113.  
  114. # Generate data for 800 points
  115. n <- 800
  116. df <- data.frame(
  117. x = rnorm(n),
  118. y = rnorm(n)
  119. )
  120.  
  121. # Add some flowing patterns
  122. df <- df %>%
  123. dplyr::mutate(
  124. size = abs(x*y)/5 + 0.5,
  125. group = sample(1:10, n, replace = TRUE)
  126. )
  127.  
  128. # Create the plot
  129. p <- ggplot(df, aes(x, y, color = size, size = size)) +
  130. geom_point(alpha = 0.7) +
  131. scale_color_gradient(low = "#3A1C71", high = "#FFAF7B") +
  132. theme_void() +
  133. theme(
  134. legend.position = "none",
  135. panel.background = element_rect(fill = "black"),
  136. plot.background = element_rect(fill = "black")
  137. ) +
  138. coord_fixed(ratio = 1)
  139.  
  140. print(p)
  141.  
  142.  
  143.  
  144. # --- [2025-03-19 18:26:25] ---
  145. # Code executed by Claude:
  146.  
  147. # Ensure plot is displayed in RStudio
  148. if (!("package:ggplot2" %in% search())) {
  149. if (requireNamespace("ggplot2", quietly = TRUE)) {
  150. library(ggplot2)
  151. }
  152. }
  153.  
  154. # Execute the plot code
  155.  
  156. library(ggplot2)
  157. library(dplyr)
  158.  
  159. # Set seed for reproducibility
  160. set.seed(123)
  161.  
  162. # Generate spiral data
  163. t <- seq(0, 15, length.out = 2000)
  164. spiral_data <- data.frame(
  165. x = t * cos(t),
  166. y = t * sin(t)
  167. )
  168.  
  169. # Add noise and styling
  170. spiral_data <- spiral_data %>%
  171. dplyr::mutate(
  172. x = x + rnorm(length(x), 0, 0.3 * t),
  173. y = y + rnorm(length(y), 0, 0.3 * t),
  174. color_group = t,
  175. size = 0.8 + rnorm(length(t), 0, 0.2)
  176. )
  177.  
  178. # Create the plot
  179. ggplot(spiral_data, aes(x, y, color = color_group, size = size)) +
  180. geom_point(alpha = 0.7) +
  181. scale_color_gradient2(
  182. low = "#3A1C71",
  183. mid = "#D76D77",
  184. high = "#FFAF7B",
  185. midpoint = median(spiral_data$color_group)
  186. ) +
  187. theme_void() +
  188. theme(
  189. legend.position = "none",
  190. panel.background = element_rect(fill = "black"),
  191. plot.background = element_rect(fill = "black")
  192. ) +
  193. coord_fixed(ratio = 1) +
  194. labs(title = "Celestial Drift - Improved")
  195.  
  196.  
  197.  
  198. # --- [2025-03-19 18:26:36] ---
  199. # Code executed by Claude:
  200.  
  201. # Ensure plot is displayed in RStudio
  202. if (!("package:ggplot2" %in% search())) {
  203. if (requireNamespace("ggplot2", quietly = TRUE)) {
  204. library(ggplot2)
  205. }
  206. }
  207.  
  208. # Execute the plot code
  209.  
  210. library(ggplot2)
  211. library(dplyr)
  212.  
  213. # Set seed for reproducibility
  214. set.seed(123)
  215.  
  216. # Generate spiral data
  217. t <- seq(0, 15, length.out = 500)
  218. spiral_data <- data.frame(
  219. x = t * cos(t),
  220. y = t * sin(t)
  221. )
  222.  
  223. # Add noise and styling
  224. spiral_data <- spiral_data %>%
  225. dplyr::mutate(
  226. x = x + rnorm(length(x), 0, 0.3 * t),
  227. y = y + rnorm(length(y), 0, 0.3 * t),
  228. color_group = t,
  229. size = 0.8 + rnorm(length(t), 0, 0.2)
  230. )
  231.  
  232. # Create the plot
  233. p <- ggplot(spiral_data, aes(x, y, color = color_group, size = size)) +
  234. geom_point(alpha = 0.7) +
  235. scale_color_gradient2(
  236. low = "#3A1C71",
  237. mid = "#D76D77",
  238. high = "#FFAF7B",
  239. midpoint = median(spiral_data$color_group)
  240. ) +
  241. theme_void() +
  242. theme(
  243. legend.position = "none",
  244. panel.background = element_rect(fill = "black"),
  245. plot.background = element_rect(fill = "black")
  246. ) +
  247. coord_fixed(ratio = 1)
  248.  
  249. print(p)
  250.  
  251.  
  252.  
  253. # --- [2025-03-19 18:26:51] ---
  254. # Code executed by Claude:
  255.  
  256. # Ensure plot is displayed in RStudio
  257. if (!("package:ggplot2" %in% search())) {
  258. if (requireNamespace("ggplot2", quietly = TRUE)) {
  259. library(ggplot2)
  260. }
  261. }
  262.  
  263. # Execute the plot code
  264.  
  265. library(ggplot2)
  266. library(dplyr)
  267.  
  268. # Set seed for reproducibility
  269. set.seed(42)
  270.  
  271. # Create triangular grid
  272. n_triangles <- 200
  273. triangles <- data.frame()
  274.  
  275. for(i in 1:n_triangles) {
  276. # Create random triangle
  277. x_center <- runif(1, -10, 10)
  278. y_center <- runif(1, -10, 10)
  279. size <- runif(1, 0.5, 2)
  280. angle <- runif(1, 0, 2*pi)
  281.  
  282. # Triangle vertices
  283. x1 <- x_center + size * cos(angle)
  284. y1 <- y_center + size * sin(angle)
  285. x2 <- x_center + size * cos(angle + 2*pi/3)
  286. y2 <- y_center + size * sin(angle + 2*pi/3)
  287. x3 <- x_center + size * cos(angle + 4*pi/3)
  288. y3 <- y_center + size * sin(angle + 4*pi/3)
  289.  
  290. # Add triangle to dataframe
  291. triangle_df <- data.frame(
  292. id = i,
  293. x = c(x1, x2, x3),
  294. y = c(y1, y2, y3),
  295. group = i,
  296. size = size
  297. )
  298.  
  299. triangles <- rbind(triangles, triangle_df)
  300. }
  301.  
  302. # Create plot
  303. p <- ggplot(triangles, aes(x, y, group = group, fill = size)) +
  304. geom_polygon(color = "white", alpha = 0.6, size = 0.2) +
  305. scale_fill_viridis_c(option = "D") +
  306. theme_void() +
  307. theme(
  308. legend.position = "none",
  309. panel.background = element_rect(fill = "#f0f0f0"),
  310. plot.background = element_rect(fill = "#f0f0f0")
  311. ) +
  312. coord_fixed(ratio = 1)
  313.  
  314. print(p)
  315.  
  316.  
  317.  
  318. # --- [2025-03-19 18:27:08] ---
  319. # Code executed by Claude:
  320.  
  321. # Ensure plot is displayed in RStudio
  322. if (!("package:ggplot2" %in% search())) {
  323. if (requireNamespace("ggplot2", quietly = TRUE)) {
  324. library(ggplot2)
  325. }
  326. }
  327.  
  328. # Execute the plot code
  329.  
  330. library(ggplot2)
  331. library(dplyr)
  332.  
  333. # Set seed for reproducibility
  334. set.seed(123)
  335.  
  336. # Create a grid of points
  337. n <- 15
  338. x <- seq(-10, 10, length.out = n)
  339. y <- seq(-10, 10, length.out = n)
  340. grid <- expand.grid(x = x, y = y)
  341.  
  342. # Add some noise to the grid
  343. grid <- grid %>%
  344. dplyr::mutate(
  345. x = x + rnorm(n^2, 0, 0.5),
  346. y = y + rnorm(n^2, 0, 0.5)
  347. )
  348.  
  349. # Calculate distances between points
  350. connections <- data.frame()
  351. threshold <- 3 # Only connect points that are close enough
  352.  
  353. for(i in 1:(nrow(grid)-1)) {
  354. for(j in (i+1):nrow(grid)) {
  355. dist <- sqrt((grid$x[i] - grid$x[j])^2 + (grid$y[i] - grid$y[j])^2)
  356. if(dist < threshold) {
  357. connections <- rbind(connections, data.frame(
  358. x = grid$x[i],
  359. y = grid$y[i],
  360. xend = grid$x[j],
  361. yend = grid$y[j],
  362. dist = dist
  363. ))
  364. }
  365. }
  366. }
  367.  
  368. # Create plot
  369. p <- ggplot() +
  370. # Add connections
  371. geom_segment(data = connections,
  372. aes(x = x, y = y, xend = xend, yend = yend, alpha = 1/dist, color = dist),
  373. size = 0.8) +
  374. # Add points
  375. geom_point(data = grid, aes(x, y), color = "white", size = 1.5) +
  376. # Styling
  377. scale_color_viridis_c(option = "B", direction = -1) +
  378. theme_void() +
  379. theme(
  380. legend.position = "none",
  381. panel.background = element_rect(fill = "#2D3047"),
  382. plot.background = element_rect(fill = "#2D3047")
  383. ) +
  384. coord_fixed(ratio = 1)
  385.  
  386. print(p)
  387.  
  388.  
  389.  
  390. # --- [2025-03-19 18:27:21] ---
  391. # Code executed by Claude:
  392.  
  393. # Ensure plot is displayed in RStudio
  394. if (!("package:ggplot2" %in% search())) {
  395. if (requireNamespace("ggplot2", quietly = TRUE)) {
  396. library(ggplot2)
  397. }
  398. }
  399.  
  400. # Execute the plot code
  401.  
  402. library(ggplot2)
  403. library(dplyr)
  404.  
  405. # Set seed for reproducibility
  406. set.seed(123)
  407.  
  408. # Create a grid of points (fewer points)
  409. n <- 10
  410. x <- seq(-10, 10, length.out = n)
  411. y <- seq(-10, 10, length.out = n)
  412. grid <- expand.grid(x = x, y = y)
  413.  
  414. # Add some noise to the grid
  415. grid <- grid %>%
  416. dplyr::mutate(
  417. x = x + rnorm(n^2, 0, 0.5),
  418. y = y + rnorm(n^2, 0, 0.5)
  419. )
  420.  
  421. # Calculate distances between points (only connect some random pairs)
  422. connections <- data.frame()
  423. threshold <- 4 # Only connect points that are close enough
  424. max_connections <- 100 # Limit the number of connections
  425.  
  426. counter <- 0
  427. set.seed(456) # Different seed for random selection
  428. random_order <- sample(1:nrow(grid), nrow(grid))
  429.  
  430. for(i in random_order) {
  431. if(counter >= max_connections) break
  432.  
  433. for(j in random_order) {
  434. if(i >= j) next # Skip if i >= j to avoid duplicates
  435. if(counter >= max_connections) break
  436.  
  437. dist <- sqrt((grid$x[i] - grid$x[j])^2 + (grid$y[i] - grid$y[j])^2)
  438. if(dist < threshold) {
  439. connections <- rbind(connections, data.frame(
  440. x = grid$x[i],
  441. y = grid$y[i],
  442. xend = grid$x[j],
  443. yend = grid$y[j],
  444. dist = dist
  445. ))
  446. counter <- counter + 1
  447. }
  448. }
  449. }
  450.  
  451. # Create plot
  452. p <- ggplot() +
  453. # Add connections
  454. geom_segment(data = connections,
  455. aes(x = x, y = y, xend = xend, yend = yend, alpha = 1/dist, color = dist),
  456. size = 0.7) +
  457. # Add points
  458. geom_point(data = grid, aes(x, y), color = "white", size = 1.2) +
  459. # Styling
  460. scale_color_viridis_c(option = "B", direction = -1) +
  461. theme_void() +
  462. theme(
  463. legend.position = "none",
  464. panel.background = element_rect(fill = "#2D3047"),
  465. plot.background = element_rect(fill = "#2D3047")
  466. ) +
  467. coord_fixed(ratio = 1)
  468.  
  469. print(p)
  470.  
  471.  
  472.  
  473. # --- [2025-03-19 18:27:34] ---
  474. # Code executed by Claude:
  475.  
  476. # Ensure plot is displayed in RStudio
  477. if (!("package:ggplot2" %in% search())) {
  478. if (requireNamespace("ggplot2", quietly = TRUE)) {
  479. library(ggplot2)
  480. }
  481. }
  482.  
  483. # Execute the plot code
  484.  
  485. library(ggplot2)
  486. library(dplyr)
  487.  
  488. # Set seed for reproducibility
  489. set.seed(123)
  490.  
  491. # Generate Voronoi-like structure
  492. n_points <- 50
  493. points <- data.frame(
  494. x = runif(n_points, -10, 10),
  495. y = runif(n_points, -10, 10),
  496. size = runif(n_points, 0.5, 2),
  497. group = sample(1:5, n_points, replace = TRUE)
  498. )
  499.  
  500. # Calculate connections
  501. connections <- data.frame()
  502. threshold <- 5
  503.  
  504. for(i in 1:(nrow(points)-1)) {
  505. for(j in (i+1):nrow(points)) {
  506. dist <- sqrt((points$x[i] - points$x[j])^2 + (points$y[i] - points$y[j])^2)
  507. if(dist < threshold) {
  508. connections <- rbind(connections, data.frame(
  509. x = points$x[i],
  510. y = points$y[i],
  511. xend = points$x[j],
  512. yend = points$y[j],
  513. dist = dist,
  514. group = ifelse(points$group[i] == points$group[j],
  515. points$group[i],
  516. sample(1:5, 1))
  517. ))
  518. }
  519. }
  520. }
  521.  
  522. # Create color palette
  523. my_colors <- c("#FF595E", "#FFCA3A", "#8AC926", "#1982C4", "#6A4C93")
  524.  
  525. # Create plot
  526. p <- ggplot() +
  527. # Add connections with group-based coloring
  528. geom_segment(data = connections,
  529. aes(x = x, y = y, xend = xend, yend = yend,
  530. color = factor(group), alpha = 1/dist),
  531. size = 0.8) +
  532. # Add points with group-based coloring
  533. geom_point(data = points,
  534. aes(x, y, size = size, color = factor(group)),
  535. alpha = 0.8) +
  536. # Styling
  537. scale_color_manual(values = my_colors) +
  538. scale_size_continuous(range = c(1, 3)) +
  539. theme_void() +
  540. theme(
  541. legend.position = "none",
  542. panel.background = element_rect(fill = "#F5F5F5"),
  543. plot.background = element_rect(fill = "#F5F5F5")
  544. ) +
  545. coord_fixed(ratio = 1)
  546.  
  547. print(p)
  548.  
  549.  
  550.  
  551. # --- [2025-03-19 18:27:50] ---
  552. # Code executed by Claude:
  553.  
  554. # Ensure plot is displayed in RStudio
  555. if (!("package:ggplot2" %in% search())) {
  556. if (requireNamespace("ggplot2", quietly = TRUE)) {
  557. library(ggplot2)
  558. }
  559. }
  560.  
  561. # Execute the plot code
  562.  
  563. library(ggplot2)
  564. library(dplyr)
  565.  
  566. # Function to generate a modified Sierpinski triangle
  567. generate_sierpinski <- function(depth, initial_points) {
  568. if(depth == 0) {
  569. return(initial_points)
  570. } else {
  571. # Calculate midpoints
  572. new_points <- data.frame()
  573. n_points <- nrow(initial_points)
  574.  
  575. for(i in 1:n_points) {
  576. j <- i %% n_points + 1 # Next point (wrapping around)
  577.  
  578. midpoint <- data.frame(
  579. x = (initial_points$x[i] + initial_points$x[j])/2,
  580. y = (initial_points$y[i] + initial_points$y[j])/2,
  581. depth = initial_points$depth[i] + 1
  582. )
  583.  
  584. new_points <- rbind(new_points, midpoint)
  585. }
  586.  
  587. # Add some controlled randomness for artistic effect
  588. new_points <- new_points %>%
  589. dplyr::mutate(
  590. x = x + rnorm(nrow(new_points), 0, 0.02 * (6-depth)),
  591. y = y + rnorm(nrow(new_points), 0, 0.02 * (6-depth))
  592. )
  593.  
  594. # Combine with existing points
  595. combined_points <- rbind(initial_points, new_points)
  596.  
  597. # Recursive call
  598. return(generate_sierpinski(depth-1, combined_points))
  599. }
  600. }
  601.  
  602. # Create initial triangle
  603. side_length <- 14
  604. height <- side_length * sqrt(3)/2
  605.  
  606. initial_points <- data.frame(
  607. x = c(-side_length/2, side_length/2, 0),
  608. y = c(-height/3, -height/3, 2*height/3),
  609. depth = 1
  610. )
  611.  
  612. # Generate fractal
  613. set.seed(123)
  614. max_depth <- 5
  615. all_points <- generate_sierpinski(max_depth, initial_points)
  616.  
  617. # Create the plot
  618. p <- ggplot(all_points, aes(x, y, color = depth, size = 6-depth)) +
  619. geom_point(alpha = 0.7) +
  620. scale_color_viridis_c(option = "A") +
  621. scale_size_continuous(range = c(0.5, 3)) +
  622. theme_void() +
  623. theme(
  624. legend.position = "none",
  625. panel.background = element_rect(fill = "#282828"),
  626. plot.background = element_rect(fill = "#282828")
  627. ) +
  628. coord_fixed(ratio = 1)
  629.  
  630. print(p)
  631.  
  632.  
  633.  
  634. # --- [2025-03-19 18:28:09] ---
  635. # Code executed by Claude:
  636.  
  637. # Ensure plot is displayed in RStudio
  638. if (!("package:ggplot2" %in% search())) {
  639. if (requireNamespace("ggplot2", quietly = TRUE)) {
  640. library(ggplot2)
  641. }
  642. }
  643.  
  644. # Execute the plot code
  645.  
  646. library(ggplot2)
  647. library(dplyr)
  648.  
  649. # Function to generate points for a Koch snowflake
  650. generate_koch <- function(iterations) {
  651. # Starting with an equilateral triangle
  652. angle <- 2*pi/3
  653. x <- c(0, cos(angle), cos(2*angle))
  654. y <- c(1, sin(angle), sin(2*angle))
  655.  
  656. points <- data.frame(x = x, y = y)
  657.  
  658. for(i in 1:iterations) {
  659. new_points <- data.frame()
  660.  
  661. for(j in 1:nrow(points)) {
  662. x1 <- points$x[j]
  663. y1 <- points$y[j]
  664.  
  665. # Get next point (wrapping around)
  666. if(j == nrow(points)) {
  667. x2 <- points$x[1]
  668. y2 <- points$y[1]
  669. } else {
  670. x2 <- points$x[j+1]
  671. y2 <- points$y[j+1]
  672. }
  673.  
  674. # Calculate 4 new points from the current segment
  675. dx <- (x2 - x1) / 3
  676. dy <- (y2 - y1) / 3
  677.  
  678. # First point (original)
  679. p1 <- c(x1, y1)
  680.  
  681. # Second point (1/3 along the segment)
  682. p2 <- c(x1 + dx, y1 + dy)
  683.  
  684. # Third point (peak of the new triangle)
  685. # Rotate the vector (dx, dy) by 60 degrees
  686. angle <- pi/3
  687. rot_dx <- dx * cos(angle) - dy * sin(angle)
  688. rot_dy <- dx * sin(angle) + dy * cos(angle)
  689. p3 <- c(p2[1] + rot_dx, p2[2] + rot_dy)
  690.  
  691. # Fourth point (2/3 along the segment)
  692. p4 <- c(x1 + 2*dx, y1 + 2*dy)
  693.  
  694. # Add points to new dataframe
  695. new_points <- rbind(new_points,
  696. data.frame(x = c(p1[1], p2[1], p3[1], p4[1]),
  697. y = c(p1[2], p2[2], p3[2], p4[2])))
  698. }
  699.  
  700. points <- new_points
  701. }
  702.  
  703. return(points)
  704. }
  705.  
  706. # Generate the Koch snowflake with 4 iterations
  707. koch_points <- generate_koch(4)
  708.  
  709. # Scale the snowflake to fit the plot
  710. max_dim <- max(abs(koch_points$x), abs(koch_points$y))
  711. koch_points <- koch_points %>%
  712. dplyr::mutate(
  713. x = 10 * x / max_dim,
  714. y = 10 * y / max_dim
  715. )
  716.  
  717. # Add a color gradient based on position
  718. koch_points <- koch_points %>%
  719. dplyr::mutate(
  720. color_val = atan2(y, x) # Angle from origin
  721. )
  722.  
  723. # Create the plot
  724. p <- ggplot(koch_points, aes(x, y, color = color_val)) +
  725. geom_path(size = 1, alpha = 0.7) +
  726. scale_color_viridis_c(option = "A") +
  727. theme_void() +
  728. theme(
  729. legend.position = "none",
  730. panel.background = element_rect(fill = "#282828"),
  731. plot.background = element_rect(fill = "#282828")
  732. ) +
  733. coord_fixed(ratio = 1)
  734.  
  735. print(p)
  736.  
  737.  
  738.  
  739. # --- [2025-03-19 18:28:29] ---
  740. # Code executed by Claude:
  741.  
  742. # Ensure plot is displayed in RStudio
  743. if (!("package:ggplot2" %in% search())) {
  744. if (requireNamespace("ggplot2", quietly = TRUE)) {
  745. library(ggplot2)
  746. }
  747. }
  748.  
  749. # Execute the plot code
  750.  
  751. library(ggplot2)
  752. library(dplyr)
  753.  
  754. # Function to generate a single iteration of Koch curve
  755. koch_iteration <- function(points) {
  756. n <- nrow(points)
  757. new_points <- data.frame()
  758.  
  759. for (i in 1:(n-1)) {
  760. p1 <- c(points$x[i], points$y[i])
  761. p5 <- c(points$x[i+1], points$y[i+1])
  762.  
  763. # Calculate intermediate points
  764. p2 <- p1 + (p5 - p1) / 3
  765. p4 <- p1 + 2 * (p5 - p1) / 3
  766.  
  767. # Calculate the "bump" point p3
  768. # Rotate (p4 - p2) by 60 degrees and add to p2
  769. vec <- p4 - p2
  770. p3 <- p2 + complex(real = vec[1], imaginary = vec[2]) * exp(complex(real = 0, imaginary = pi/3))
  771. p3 <- c(Re(p3), Im(p3))
  772.  
  773. # Add all points
  774. new_points <- rbind(new_points,
  775. data.frame(x = c(p1[1], p2[1], p3[1], p4[1]),
  776. y = c(p1[2], p2[2], p3[2], p4[2])))
  777. }
  778.  
  779. # Add the final point
  780. new_points <- rbind(new_points, points[n, ])
  781.  
  782. return(new_points)
  783. }
  784.  
  785. # Create a complete Koch snowflake
  786. create_koch_snowflake <- function(iterations, size = 10, center = c(0, 0), rotation = 0, id = 1) {
  787. # Create initial triangle
  788. t <- seq(0, 2*pi, length.out = 4)
  789. points <- data.frame(
  790. x = center[1] + size * cos(t + rotation),
  791. y = center[2] + size * sin(t + rotation)
  792. )
  793. points <- points[1:3, ] # Just keep the first 3 points for a triangle
  794. points <- rbind(points, points[1, ]) # Close the triangle
  795.  
  796. # Apply iterations
  797. for(i in 1:iterations) {
  798. points <- koch_iteration(points)
  799. }
  800.  
  801. # Add identifier
  802. points$id <- id
  803.  
  804. return(points)
  805. }
  806.  
  807. # Create multiple snowflakes
  808. snowflakes <- data.frame()
  809.  
  810. # Main large snowflake
  811. main_flake <- create_koch_snowflake(
  812. iterations = 4,
  813. size = 8,
  814. center = c(0, 0),
  815. id = 1
  816. )
  817. snowflakes <- rbind(snowflakes, main_flake)
  818.  
  819. # Smaller snowflakes around
  820. for(i in 1:5) {
  821. angle <- 2*pi * i/5
  822. center_x <- 12 * cos(angle)
  823. center_y <- 12 * sin(angle)
  824.  
  825. flake <- create_koch_snowflake(
  826. iterations = 3,
  827. size = 3,
  828. center = c(center_x, center_y),
  829. rotation = angle,
  830. id = i + 1
  831. )
  832.  
  833. snowflakes <- rbind(snowflakes, flake)
  834. }
  835.  
  836. # Create color palette
  837. snowflakes <- snowflakes %>%
  838. dplyr::mutate(
  839. color_val = id + atan2(y, x)/(2*pi) # Combine ID and angle for coloring
  840. )
  841.  
  842. # Create the plot
  843. p <- ggplot(snowflakes, aes(x, y, group = interaction(id, color_val), color = color_val)) +
  844. geom_path(size = 0.5, alpha = 0.8) +
  845. scale_color_viridis_c(option = "D") +
  846. theme_void() +
  847. theme(
  848. legend.position = "none",
  849. panel.background = element_rect(fill = "#0E0E18"),
  850. plot.background = element_rect(fill = "#0E0E18")
  851. ) +
  852. coord_fixed(ratio = 1)
  853.  
  854. print(p)
  855.  
  856.  
  857.  
  858. # --- [2025-03-19 18:29:27] ---
  859. # Code executed by Claude:
  860.  
  861. # Ensure plot is displayed in RStudio
  862. if (!("package:ggplot2" %in% search())) {
  863. if (requireNamespace("ggplot2", quietly = TRUE)) {
  864. library(ggplot2)
  865. }
  866. }
  867.  
  868. # Execute the plot code
  869.  
  870. library(ggplot2)
  871. library(dplyr)
  872.  
  873. # Let's try a different approach with a Barnsley fern
  874. generate_barnsley_fern <- function(n_points = 50000) {
  875. # Initialize points array
  876. points <- data.frame(x = numeric(n_points), y = numeric(n_points))
  877.  
  878. # Start with (0,0)
  879. x <- 0
  880. y <- 0
  881.  
  882. # Fill the points
  883. for(i in 1:n_points) {
  884. # Store the current point
  885. points$x[i] <- x
  886. points$y[i] <- y
  887.  
  888. # Choose a random transformation
  889. r <- runif(1)
  890.  
  891. if(r < 0.01) {
  892. # Transformation 1 (stem)
  893. x_new <- 0
  894. y_new <- 0.16 * y
  895. } else if(r < 0.86) {
  896. # Transformation 2 (smaller leaflets)
  897. x_new <- 0.85 * x + 0.04 * y
  898. y_new <- -0.04 * x + 0.85 * y + 1.6
  899. } else if(r < 0.93) {
  900. # Transformation 3 (left leaflet)
  901. x_new <- 0.20 * x - 0.26 * y
  902. y_new <- 0.23 * x + 0.22 * y + 1.6
  903. } else {
  904. # Transformation 4 (right leaflet)
  905. x_new <- -0.15 * x + 0.28 * y
  906. y_new <- 0.26 * x + 0.24 * y + 0.44
  907. }
  908.  
  909. # Update for next iteration
  910. x <- x_new
  911. y <- y_new
  912. }
  913.  
  914. # Add a group to color by
  915. points <- points %>%
  916. dplyr::mutate(
  917. group = ceiling(1:n_points / (n_points/7)) # Create 7 groups
  918. )
  919.  
  920. return(points)
  921. }
  922.  
  923. # Generate the fractal
  924. set.seed(42)
  925. fern <- generate_barnsley_fern(50000)
  926.  
  927. # Plot the fern
  928. p <- ggplot(fern, aes(x, y, color = factor(group))) +
  929. geom_point(size = 0.1, alpha = 0.6) +
  930. scale_color_viridis_d(option = "D") +
  931. theme_void() +
  932. theme(
  933. legend.position = "none",
  934. panel.background = element_rect(fill = "#0E0E18"),
  935. plot.background = element_rect(fill = "#0E0E18")
  936. ) +
  937. labs(title = "Fractal Dreams") +
  938. coord_fixed(ratio = 1)
  939.  
  940. print(p)
  941.  
  942.  
  943.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement