• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión63e30f22681ad7c0e878b9a6acc3578230c8ccdb (tree)
Tiempo2023-03-02 01:59:18
AutorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added a new script to generate 2D attractors.

Cambiar Resumen

Diferencia incremental

diff -r fc2d45bec5d5 -r 63e30f22681a R-codes/gen_attractors.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R-codes/gen_attractors.R Wed Mar 01 17:59:18 2023 +0100
@@ -0,0 +1,84 @@
1+rm(list=ls())
2+
3+library(Rcpp)
4+library(tidyverse)
5+
6+
7+cppFunction('DataFrame createTrajectory(int n, double x0, double y0,
8+ double a1, double a2, double a3, double a4, double a5,
9+ double a6, double a7, double a8, double a9, double a10,
10+ double a11, double a12, double a13, double a14) {
11+ // create the columns
12+ NumericVector x(n);
13+ NumericVector y(n);
14+ x[0]=x0;
15+ y[0]=y0;
16+ for(int i = 1; i < n; ++i) {
17+ x[i] = a1+a2*x[i-1]+ a3*y[i-1]+ a4*pow(fabs(x[i-1]), a5)+ a6*pow(fabs(y[i-1]), a7);
18+ y[i] = a8+a9*x[i-1]+ a10*y[i-1]+ a11*pow(fabs(x[i-1]), a12)+ a13*pow(fabs(y[i-1]), a14);
19+ }
20+ // return a new data frame
21+ return DataFrame::create(_["x"]= x, _["y"]= y);
22+ }
23+ ')
24+## a1 <- -0.8
25+## a2 <- 0.4
26+## a3 <- -1.1
27+## a4 <- 0.5
28+## a5 <- -0.6
29+## a6 <- -0.1
30+## a7 <- -0.5
31+## a8 <- 0.8
32+## a9 <- 1.0
33+## a10 <- -0.3
34+## a11 <- -0.6
35+## a12 <- -0.3
36+## a13 <- -1.2
37+## a14 <- -0.3
38+
39+opt <- theme(legend.position = "none",
40+ panel.background = element_rect(fill="white", color="black"),
41+ plot.background = element_rect(fill="white"),
42+ axis.ticks = element_blank(),
43+ panel.grid = element_blank(),
44+ axis.title = element_blank(),
45+ axis.text = element_blank())
46+
47+
48+a1 <- -0.7
49+a2 <- 0.4
50+a3 <- -1.1
51+a4 <- 0.4
52+a5 <- -0.6
53+a6 <- -0.1
54+a7 <- -0.5
55+a8 <- 0.8
56+a9 <- 0.96
57+a10 <- -0.3
58+a11 <- -0.55
59+a12 <- -0.2
60+a13 <- -1.1
61+a14 <- -0.5
62+
63+
64+
65+df <- createTrajectory(10000000, 1, 1, a1, a2, a3, a4, a5, a6,
66+ a7, a8, a9, a10, a11, a12, a13, a14)
67+
68+mx <- quantile(df$x, probs = 0.05)
69+Mx <- quantile(df$x, probs = 0.95)
70+my <- quantile(df$y, probs = 0.05)
71+My <- quantile(df$y, probs = 0.95)
72+
73+df %>% filter(x > mx, x < Mx, y > my, y < My) -> df
74+
75+plot <- ggplot(df) +
76+ geom_point(aes(x, y), shape=46, alpha=0.01, size=0, color="black") +
77+ scale_x_continuous(expand = c(0,0))+
78+ scale_y_continuous(expand = c(0,0))+
79+ coord_fixed() +
80+ opt
81+
82+ggsave("strange.png", plot, height = 4, width = 4, units = 'in', dpi = 1200)
83+
84+print("So far so good")