#/*********************************************************** # fracint.rb -- フラクタル補間 #***********************************************************/ require "window.rb" left = 0; bottom = 0; right = 100; top = 100 x = [0, 30, 60, 100]; y = [0, 50, 40, 10] # 各点の座標 N = x.size - 1 a = []; c = []; d = []; e = []; f = [] # アフィン変換を求める q = x[N] - x[0] for i in 0...N printf("d[%d] = ", i); d[i] = gets.to_f a[i] = (x[i+1] - x[i]) / q.to_f e[i] = (x[N] * x[i] - x[0] * x[i+1]) / q.to_f c[i] = (y[i+1] - y[i] - d[i] * (y[N] - y[0])) / q.to_f f[i] = (x[N] * y[i] - x[0] * y[i+1] -\ d[i] * (x[N] * y[0] - x[0] * y[N])) / q.to_f end # アトラクタをプロットする gr_on(true) gr_window(left, bottom, right, top, 0, 0) gr_plot_start p = x[0]; q = y[0] for i in 0...5000 j = (N * rand()).to_i q = c[j] * p + d[j] * q + f[j] p = a[j] * p + e[j] gr_wdot(p, q) end gr_plot_end gr_off exit 0