一种可分形的圆曲线

线代码如下:
//绕圆环的圆线(平面 ) by Looky
m = 1 //绕大圆环数(整数)
n = 6 //绕小圆环数(整数)
R = 6 //甜甜圈环半径
//r不可设置 //甜甜圈切面半径
vertices = 3600
t = linspace(0, (2*PI), vertices)
r = 2*PI*R * m / n /4
scale = r
rNum = m*R*t/r
xZhi = rNum % 4 //xZhi周期循环
yZhi = pow(1*1- pow(xZhi – (xZhi<2?1:3), 2), 0.5) * (xZhi<2?1:-1)
//xZhi *= scale
yZhi *= scale
Rji = R + yZhi
x = Rji*cos(m*t)
y = Rji*sin(m*t)
z = 0
估计还可以生成花朵:
分形图片:
分形代码:
//圆弧分形 by Looky
deep = 4 //分形深度
m = 1 //绕大圆环数(整数)
n = 5 //绕小圆环数(整数)
R = 1 //甜甜圈环半径
//r不可设置 //甜甜圈切面半径
vertices = 33008
t = linspace(0, 2*PI, vertices)
if (typeof recFun_LookyCurve !== “function”) {
    recFun_LookyCurve = (function fun(t_n, R_n, ox_n, oy_n, isneedD, m_n, n_n, deep_n, thePt) { // isneedD是否要对称处理 第一步:ox_n,oy_n极坐标化的圆心 
  var r_n = 2*PI*R_n * m_n / n_n /4
  var scale_n = r_n
  var p_x_n = t_n * R_n * m_n
  var u_p_x_n1 = p_x_n / scale_n // n-1的平面坐标 (以r_n为单元的单元坐标)
  var u_p_y_n1 = pow(1*1- pow(u_p_x_n1 – (floor(u_p_x_n1/2)*2+1), 2), 0.5) * (u_p_x_n1%4<2?1:-1)
  var p_y_n = u_p_y_n1 * scale_n
  
  //递归调用
  if (deep_n > 1) {
   var tempPt = new Object()
   var acosV = (1-u_p_x_n1%2)
   var new_t_n = acos( acosV ) + (floor(u_p_x_n1/2)*PI)
   var newXYZZhi_n = fun( new_t_n, r_n, r_n*(floor(u_p_x_n1/2)*2+1), 0, u_p_x_n1%4<2?false:true, m_n, n_n, deep_n-1, tempPt)
   p_x_n = tempPt.x
   p_y_n = tempPt.y
  } else {
   //p_x_n = p_x_n1
   //p_y_n = p_y_n1
  }
   
  if (deep_n<deep)
  {
   if (!isneedD) {
    // 极坐标
    var Rji_n = p_y_n + R_n // 极坐标半径
    var Tji_n = p_x_n / R_n //m_n * t_n // p_x_n / R_n // 极坐标弧度
    //转n+1平面坐标
    var j_x_n = Rji_n * cos(Tji_n) 
    var j_y_n = Rji_n * sin(Tji_n)
    //圆心平移后变成(n+1)的真正坐标
    thePt.x = -j_x_n + ox_n // 返回 p_x_n_1
    thePt.y = j_y_n + oy_n // 返回 p_y_n_1
   } else {
    // 极坐标
    var Rji_n = R_n – p_y_n // 极坐标半径
    var Tji_n = p_x_n / R_n ///m_n * t_n // p_x_n / R_n // 极坐标弧度
    //转n+1平面坐标
    var j_x_n = Rji_n * cos(Tji_n) 
    var j_y_n = Rji_n * sin(Tji_n)
    //圆心平移后变成(n+1)的真正坐标
    thePt.x = j_x_n + ox_n // 返回 p_x_n_1
    thePt.y = j_y_n + oy_n // 返回 p_y_n_1
   }
  } else {
    // 极坐标
    var Rji_n = R_n + p_y_n // 极坐标半径
    var Tji_n = p_x_n / R_n // 极坐标弧度
    //转n+1平面坐标
    var j_x_n = Rji_n * cos(Tji_n) 
    var j_y_n = Rji_n * sin(Tji_n)
    //圆心平移后变成(n+1)的真正坐标
    thePt.x = ox_n + j_x_n // 返回 p_x_n_1
    thePt.y = oy_n + j_y_n // 返回 p_y_n_1
  
  
    //thePt.x = p_x_n // 返回 p_x_n_1
    //thePt.y = p_y_n // 返回 p_y_n_1
  }
 });
}
var xyPt = new Object()
recFun_LookyCurve(t, R, 0, -R, false, m, n, deep, xyPt)
x = xyPt.x
y = xyPt.y
z = 0
——算法修正—–
代码:
//高清版 圆弧分形(by Looky)—-创意来自绕圆环的圆线
deep = 5 //分形深度
m = 1 //绕大圆环数(整数)
n = 5 //绕小圆环数(整数)
R = 1 //甜甜圈环半径
//r不可设置 //甜甜圈切面半径
vertices = 32000
t = linspace(0 , 1 * 2 * PI , vertices)
len = t * R *m * pow(PI/2, deep)
if (typeof recFun_LookyCurve !== “function”) {
recFun_LookyCurve = (function fun( pt, fuduDing, m_n, n_n, R0, deep_n){
 var r_n = R0 * pow(m_n*PI/(2*n_n), deep_n)
 var rLenDing = fuduDing/ (PI/2)
 //if (deep_n == 1) { return;}
 if (deep_n == 0) {
  var theta = pt.x/r_n
  var u_x_n = rLenDing / r_n
  ox_n = 0
  var Rji = (pt.y + r_n)
  pt.x = (-Rji * cos(theta) + r_n) + ox_n
  pt.y = Rji * sin(theta)
 } else {
  var theta = pt.x/r_n
  var u_x_n = rLenDing / r_n
  ox_n = r_n * (floor(u_x_n/2)*2)
if (u_x_n%4<2) {
  var Rji = (pt.y + r_n)
  pt.x = (-Rji * cos(theta) + r_n) + ox_n
  pt.y = Rji * sin(theta)
} else {
  var Rji = (-pt.y + r_n)
  pt.x = (Rji * cos(theta) + r_n) + ox_n
  pt.y = Rji * sin(theta)
}
  fun( pt, rLenDing, m_n, n_n, R0, deep_n-1)
 }
})
}
var thePt = {x: len, y:0}
recFun_LookyCurve(thePt, len, m, n, R, deep)
x= thePt.x
y= thePt.y
z= 0

2019-03-27
29 views
暂无评论

发表评论