239 lines
24 KiB
Rust
239 lines
24 KiB
Rust
use eframe::egui;
|
|
use egui_plot::Plot;
|
|
use egui_plot::PlotBounds;
|
|
use egui_plot::Points;
|
|
use egui_plot::Line;
|
|
use num::complex::Complex;
|
|
use std::collections::VecDeque;
|
|
use std::f64::consts::PI;
|
|
use egui::ecolor::Color32;
|
|
|
|
type C = Complex<f64>;
|
|
fn z(re: f64, im: f64) -> C {
|
|
return Complex::new(re, im);
|
|
}
|
|
|
|
fn heart_points() -> Vec<C> {
|
|
let n = 100;
|
|
let mut pts = Vec::with_capacity(n);
|
|
|
|
for k in 0..n {
|
|
let t = 2.0 * PI * k as f64 / n as f64;
|
|
|
|
let x = 16.0 * t.sin().powi(3);
|
|
let y = 13.0 * t.cos() - 5.0 * (2.0 * t).cos() - 2.0 * (3.0 * t).cos() - (4.0 * t).cos();
|
|
|
|
pts.push(Complex::new(x, y));
|
|
}
|
|
|
|
pts
|
|
}
|
|
|
|
fn star_points() -> Vec<C> {
|
|
let n = 100;
|
|
let mut pts = Vec::with_capacity(n);
|
|
|
|
for k in 0..n {
|
|
let t = 2.0 * PI * k as f64 / n as f64;
|
|
|
|
let r = 1.0 + 0.35 * (5.0 * t).cos();
|
|
let x = r * t.cos();
|
|
let y = r * t.sin();
|
|
|
|
pts.push(C::new(x, y));
|
|
}
|
|
|
|
pts
|
|
}
|
|
|
|
fn pl_points() -> Vec<C> {
|
|
let x: Vec<f64> = vec![-0.51683, -0.5175970934423306, -0.518354060356653, -0.519087791495199, -0.5197265482083357, -0.5200158499596517, -0.5200606483568466, -0.5201245610270648, -0.5202127069594011, -0.5203231480090157, -0.5204790003906012, -0.519300192280936, -0.5172525623338785, -0.5151890488911149, -0.5130799236833181, -0.511021380729033, -0.508787012065353, -0.5057737340345604, -0.5022504618885519, -0.4964265433953864, -0.48636074196716683, -0.4764403364220719, -0.46643530981687087, -0.45621444778362136, -0.44630923486471685, -0.4363901728024042, -0.42604223131220376, -0.4155014249009841, -0.4058483245679939, -0.3956550567196297, -0.3851559202678762, -0.3758495147475159, -0.36703196232295404, -0.3585483139424033, -0.3499590157776108, -0.34116555495780165, -0.3326543580380893, -0.3240731575215475, -0.31664918162339645, -0.3096570153323872, -0.3028242475979054, -0.29284108982901147, -0.2845606146146703, -0.2761603975681723, -0.2676682527756908, -0.2586141983038218, -0.2500177100048542, -0.2406698388847149, -0.2319785185185185, -0.2230836285309992, -0.21412117260761887, -0.20410621532125664, -0.19461170494868074, -0.1861732531930878, -0.17727609247252651, -0.16724912507381742, -0.1579175910621365, -0.1484630227074335, -0.139, -0.12944822669094783, -0.11986916967862482, -0.11012672929684561, -0.10030578512396693, -0.09015481855592966, -0.08002834948814745, -0.06940427983539094, -0.05850052715709281, -0.0482599302792232, -0.038, -0.02772790036885537, -0.017678447447642437, -0.007649362794355151, 0.002433400395135929, 0.013098064874847864, 0.0238371240926766, 0.03357945042713639, 0.043484832067228765, 0.0533314864490224, 0.06310185185185183, 0.07260417123999918, 0.08156318711036493, 0.09008171035938405, 0.09833894504683605, 0.10600330788756862, 0.11031914850989236, 0.10803366279878676, 0.10822147411261887, 0.11320115702479337, 0.11951197734925008, 0.12715715641261094, 0.13595350145676746, 0.1455836738469276, 0.15510569524445558, 0.16519252134651277, 0.1748900137174211, 0.18456332488233007, 0.1939605556843818, 0.2036259101782028, 0.21253689584344618, 0.2214850228846984, 0.23073356429306843, 0.23969915852742296, 0.24865996681435304, 0.25696743484224965, 0.26513401673092524, 0.27440373234435983, 0.28209604986710285, 0.2884955944404765, 0.29531399052250895, 0.30262330363114875, 0.31051322024448147, 0.3186081010492642, 0.3270241078162505, 0.33555989928877583, 0.3443841422283234, 0.35314904219214904, 0.3626550891632373, 0.3716970047789393, 0.3812689462114255, 0.3909313757305737, 0.4013315768438389, 0.41107626335799585, 0.42114852687676685, 0.4312147568326877, 0.4414696933625615, 0.45147048027463704, 0.4612822814926121, 0.47129575356668424, 0.47843737997256525, 0.4818288287115622, 0.48482275927317253, 0.48763306278786234, 0.49024, 0.4919217543870499, 0.493491178801586, 0.49495206461101166, 0.4962927717950859, 0.4974446141653244, 0.4984715775034294, 0.49924021372793337, 0.49981671872278544, 0.49940021513986926, 0.4982659049220909, 0.4971584869303173, 0.4959469196093162, 0.4945711458426731, 0.4930390809327846, 0.4914486706778013, 0.48978999999999995, 0.4873052697776665, 0.48660930156580606, 0.49615530944585123, 0.5038818252930283, 0.5114730277986477, 0.5191480424075465, 0.5267040789694724, 0.5342749761877525, 0.5419673263190007, 0.5491946957175057, 0.556934072239588, 0.5641584504570241, 0.571464566716033, 0.5786052752605126, 0.5843518445345198, 0.5901247110220664, 0.5960441651490934, 0.6017804279711719, 0.6075314603436672, 0.6130161800640834, 0.6187243864829296, 0.6240702133672197, 0.6288934268302864, 0.6347772892273412, 0.6315034078773657, 0.6278428229648799, 0.6240502788521889, 0.6201672757572667, 0.6160564835375488, 0.6122031914492337, 0.6084009553137745, 0.6042768422517184, 0.6000061682842093, 0.5954346024885113, 0.5906520224384442, 0.5859750835154937, 0.5808925920360631, 0.5762523237888527, 0.571384190110471, 0.5663205409466566, 0.5610937262431477, 0.5557360959456826, 0.55028, 0.5434335681887749, 0.5373713554275538, 0.5311603936724659, 0.5250095416979714, 0.519022629601803, 0.5125850282232589, 0.5065530459992228, 0.5003283290202298, 0.49399874782927733, 0.4873715775034293, 0.48046554915546646, 0.473922043019729, 0.46677286694101516, 0.4650967440757951, 0.4671385185185185, 0.47073242410844496, 0.47499843716215306, 0.47962850480109753, 0.48469781395219413, 0.489944164613176, 0.49589100137174214, 0.5021474188677924, 0.5093361718707328, 0.5165904324646322, 0.5241801190973092, 0.5320335748155981, 0.5398829688065225, 0.5475249940585324, 0.5512354086936089, 0.5466945343857924, 0.5403588728835133, 0.5337845440219974, 0.5270690400381738, 0.520534883546206, 0.5136541325096696, 0.5067531179564236, 0.49965592435939843, 0.4927937988702451, 0.4857468870420355, 0.47871436459276984, 0.4706007888290104, 0.4628720438957475, 0.4537688759444254, 0.44517449931412906, 0.4356989030803908, 0.4275063197220651, 0.41878810737721056, 0.40956131118345984, 0.39984297627844617, 0.38965014779980195, 0.3789998708851602, 0.37072221637866265, 0.3622040259342739, 0.35345249046943267, 0.3444748009015778, 0.33527814814814816, 0.3258697231265827, 0.3162567167543201, 0.3064463199487993, 0.29644572362745913, 0.28626211870773854, 0.27590269610707635, 0.2653746467429112, 0.2546851615326822, 0.2438414313938281, 0.23285064724378776, 0.22172000000000003, 0.2102234641177617, 0.19930716197790582, 0.18895287002253944, 0.1759898879726765, 0.1639504411217573, 0.15279133288810975, 0.1424693666900615, 0.1306783326376715, 0.12004347003346391, 0.10868899062041701, 0.09873211924365581, 0.08868769346356122, 0.07790450037565738, 0.06731264432922221, 0.05730647828143694, 0.046793462891335534, 0.036609191063785476, 0.02637943846175251, 0.016089533607681755, 0.006028739594702249, -0.004123535116495025, -0.014949861846709114, -0.025228394546423324, -0.03527672397889723, -0.04531550068587106, -0.055752060962651714, -0.06653625738045696, -0.07658552281307103, -0.08660990297836031, -0.0966306635686526, -0.10649882544452792, -0.11545865569272974, -0.1250112581379554, -0.13466714705467084, -0.14495400645574205, -0.15492764131468753, -0.16502313298271976, -0.1751122503063489, -0.1854325925925926, -0.19559714305590342, -0.2065397401007319, -0.21687907113168214, -0.2273115593440785, -0.2369466994503756, -0.24714921863260703, -0.2572209771214852, -0.2666261274308229, -0.27667892668136324, -0.28731764017071026, -0.2965862695828812, -0.3061831864610805, -0.31607266470438494, -0.32621897821187085, -0.3365864008826145, -0.3471392066156927, -0.3578416693101817, -0.36865806286515806, -0.3773691999888694, -0.38611209639502875, -0.39486846031996325, -0.40362, -0.4124193906517475, -0.4208349599247242, -0.42888371288644017, -0.43658265460440554, -0.44538357695926717, -0.45373464317699996, -0.46166523801426157, -0.46920474622770925, -0.47754575145393335, -0.48544110215510894, -0.4929374602364838, -0.5000814876033058, -0.5078745227811221, -0.5153379698216736, -0.5225414814814816, -0.5291362617708563, -0.5352953565756535, -0.5414323173166209, -0.547587979519715, -0.5539393944959234, -0.5600507493669478, -0.5661431930879038, -0.5719573388203019, -0.5759792995664224, -0.5709925845229151, -0.563022962962963, -0.5552984391306184, -0.5476710415449257, -0.5404991896930739, -0.5337838756713137, -0.527100191446142, -0.5204963666457453, -0.5146160306874479, -0.5092286111806772, -0.5038748342521223, -0.4987630954582041, -0.4929323591284748, -0.4831027707232513, -0.4730251834949845, -0.46292259359228444, -0.4527223316936326, -0.45863119405461605, -0.46603259259259255, -0.473368566678931, -0.48065602248379113, -0.4874457400450789, -0.4946519464618638, -0.5021940740740741, -0.5086776612982185, -0.5152919525630759, -0.5219903230653644, -0.5287261480018015, -0.535452802569105, -0.5421236619639925, -0.5481950575853423, -0.5531199236317879, -0.5583966540210803, -0.563777254763738, -0.5690535146382713, -0.5740944429294476, -0.5788890554148773, -0.5835945085999265, -0.5881644511227984, -0.5930734508847274, -0.5976736879662867, -0.6024301582089645, -0.606570177450456, -0.6105561908339595, -0.6147862597611665, -0.6187700923735879, -0.6229572001104815, -0.6271117325793389, -0.6308779661630074, -0.6343433305506858, -0.6244102689789438, -0.6188936489679986, -0.6131270451170207, -0.6072879411191808, -0.6017086590422127, -0.595838393897139, -0.5895137266553918, -0.5829680852603167, -0.5762330879038317, -0.569614885906303, -0.5626214913547267, -0.5550844043330974, -0.5479009963320584, -0.5407378764277815, -0.5336358858042727, -0.5266685655040353];
|
|
let y: Vec<f64> = vec![0.194, 0.20425147918322084, 0.2143676268861454, 0.22440466392318248, 0.2346247713333725, 0.24465433953863705, 0.25480620530372594, 0.2650117295802634, 0.27554658847427443, 0.28561912096168296, 0.2963206836243261, 0.30649866683362553, 0.31672548892660923, 0.3269862467651725, 0.3373464962140536, 0.34716609776986274, 0.3571808124093707, 0.3669701577761081, 0.3765027505542106, 0.38470577594123045, 0.3853431510390096, 0.3837508907254361, 0.38180086283712544, 0.3797904132231405, 0.37769629690435624, 0.375124199849737, 0.37233137170088804, 0.36937832683533633, 0.36657351615326816, 0.3634967295132737, 0.3601861201031847, 0.356526496358339, 0.3508484200128002, 0.34537804499437796, 0.3398199023290759, 0.33408176643488247, 0.328424987514158, 0.3225158011808731, 0.3156139560898238, 0.308420747975624, 0.30072967242056314, 0.3018060172276793, 0.30768904419153276, 0.3134892896210344, 0.3188403389264547, 0.32422401900857367, 0.3293356232048059, 0.33489401118624257, 0.33998888888888884, 0.3450011509648057, 0.3496251350975319, 0.35006702117594685, 0.3469263958635431, 0.341439196093163, 0.3367647496081105, 0.3356054976558772, 0.339216547012828, 0.34289871712740094, 0.34658, 0.34986687167563807, 0.352866008271677, 0.35566675068200626, 0.35801051840721254, 0.35984492705856647, 0.3613916569634721, 0.3628968998628258, 0.3644109702267033, 0.36582600876636995, 0.366, 0.36685600830259535, 0.367041293415741, 0.3671371932878422, 0.36728513036703125, 0.3675125190791705, 0.36824867947921214, 0.3710387937223475, 0.3739357216796061, 0.3769753595025863, 0.38031444444444445, 0.38407356859071273, 0.38870015740508856, 0.3943605931676731, 0.40034880884139834, 0.406803655213496, 0.3977426443498344, 0.38779904500571466, 0.37779409891177873, 0.3686394966190834, 0.360561467011715, 0.3538190227342293, 0.348687393659068, 0.3451357451878236, 0.34193553329437626, 0.33846923204084517, 0.3350236351165981, 0.33143172659149395, 0.3277358722723614, 0.32350859356754974, 0.31879722828736295, 0.3140353867519187, 0.3090252770125498, 0.3039873553719008, 0.298645050051582, 0.2930641700960219, 0.2871298571780451, 0.2832281996992679, 0.28999627016002283, 0.29783117812138316, 0.3053168433132467, 0.3126256343560078, 0.3193897986393886, 0.32533991567547726, 0.33116631495034005, 0.3367242619852231, 0.3421207133883473, 0.34714557495163867, 0.3522307270233196, 0.35672436438664784, 0.36112327795864985, 0.3648575468180426, 0.3674561265548043, 0.369890708183766, 0.37240639786292673, 0.3749190377605254, 0.37747730194507056, 0.3799715713609929, 0.38228878453961107, 0.3831911451521645, 0.37594827160493827, 0.3664421578193939, 0.3567259787962267, 0.3468575798078737, 0.33702, 0.326708360804247, 0.3163511856242252, 0.3058265519597566, 0.29511109775440353, 0.2846815927255413, 0.2737739917695473, 0.2636902034733623, 0.2534832446287175, 0.24332806790484168, 0.232786520216964, 0.22281011111008048, 0.2127505935386927, 0.20269912039484733, 0.19254803840877915, 0.1824313000425642, 0.172, 0.1622115159863094, 0.1521979833535848, 0.1555462962344597, 0.16210148336749808, 0.16862852742299028, 0.17523555639034982, 0.18207516764420045, 0.18921380099330212, 0.1966423435353432, 0.2037862584522915, 0.21162961962240504, 0.21915701033392798, 0.22700951499486238, 0.23518486738623864, 0.24345694546732502, 0.25178854439713944, 0.2604067668625857, 0.2689290513954977, 0.27770645497934143, 0.2862293911773588, 0.2951644761460127, 0.3036168097050497, 0.31247948687981747, 0.30434254675105304, 0.2948609108326402, 0.2855512218398658, 0.27601263565148476, 0.26625746860503824, 0.2559335152978618, 0.24625741484841268, 0.23670988797267645, 0.22720080947213178, 0.21776085833335904, 0.20786944975723978, 0.19773348704883748, 0.18802194115422152, 0.1776906160781367, 0.16846246626040012, 0.15899598603110998, 0.1493913373403456, 0.13974868213818625, 0.13016818237471128, 0.12075, 0.11120642374154772, 0.1027622714750814, 0.09412790902598064, 0.0856138241923366, 0.07739537941397445, 0.06869180324827706, 0.06071549980985242, 0.05267017280240421, 0.04462628117724536, 0.03628086419753086, 0.027617017280240415, 0.01997354036230068, 0.012956707818930024, 0.002871961271731689, -0.007027777777777809, -0.016360980264846225, -0.025688587641541433, -0.03502953360768178, -0.044368101121406926, -0.0531573841980668, -0.06211589849108368, -0.07014739586457369, -0.07732204501911266, -0.08444478471069228, -0.09155903219523054, -0.09861588932895946, -0.10557011881904448, -0.11212481834980764, -0.12148988903420489, -0.13059103826758556, -0.13844293769240204, -0.1464849947078169, -0.1546933945928008, -0.16228566491359883, -0.17012659487436343, -0.17791969947407962, -0.18585701675462923, -0.1934478253610485, -0.20114203714525108, -0.20869403709578183, -0.21621945377661939, -0.22281196159122085, -0.23046494078629373, -0.23756828532235943, -0.24525944402704736, -0.25179019922724855, -0.2586193304125842, -0.26571224865737264, -0.27303436503593226, -0.2805510906225813, -0.2882278364916382, -0.29406960180315556, -0.29996733004980947, -0.30590642902857784, -0.3118723065364388, -0.3178503703703704, -0.3238260283273507, -0.32978468820435763, -0.33571175779836937, -0.34159264490636393, -0.34741275732531934, -0.35315750285221365, -0.35881228928402487, -0.3643625244177311, -0.3697936160503103, -0.3750909719787406, -0.38024, -0.3817891557447756, -0.3832600228177089, -0.3846549737039819, -0.3864009169647707, -0.3880217395359575, -0.3895230650861229, -0.3909105172838475, -0.39249326543673657, -0.39391785718629, -0.39543406592194785, -0.3967573258861444, -0.39808258452291506, -0.3994870548459805, -0.4008331527498225, -0.40204937668698004, -0.4029735573776743, -0.40300357444457835, -0.4031885711105546, -0.4037022908093279, -0.4038787497462122, -0.4036311332898416, -0.4033670765403242, -0.40311638062081895, -0.40251981811792037, -0.4016836213991769, -0.4008857295328553, -0.40006126032284894, -0.39897504068333584, -0.3975329143696944, -0.39706491211471945, -0.39875064362634616, -0.40322152263374483, -0.40690367396029475, -0.4097354328717231, -0.4100902092550853, -0.4088556691391003, -0.4073323441021788, -0.4055593390800156, -0.4035018518518518, -0.4012436499986087, -0.3985618568606172, -0.39579240472266797, -0.39267341482367807, -0.3887995344218638, -0.384620954169797, -0.38039422327550565, -0.37634564029232226, -0.37190255136818656, -0.36706346055185046, -0.3627273041711885, -0.35811424190893726, -0.3532234080525693, -0.34805393688955666, -0.3426049627073716, -0.33687561979348635, -0.33086504243537296, -0.3245723649205039, -0.3193345290369257, -0.31391515175219187, -0.30831378982148794, -0.30252999999999997, -0.2945714774208774, -0.2869551771876504, -0.2796609096474386, -0.2726684851473618, -0.26464758152899265, -0.2569973710680934, -0.24968296604448734, -0.2426694787379973, -0.23482085955978518, -0.22727893635879248, -0.21998830872751596, -0.2128935762584523, -0.20495411462858354, -0.19711545953360768, -0.1892949141553274, -0.18125667284002145, -0.17330314444310466, -0.1653605665882372, -0.15734095778723875, -0.14892763447143612, -0.14063392047193699, -0.13224368895567243, -0.12409492455418385, -0.11485983145401572, -0.10604558978211873, -0.09973407407407404, -0.09328355119401337, -0.0867059359434566, -0.07940332136794948, -0.07197136433202549, -0.06428391240225949, -0.05630440773411079, -0.048012512040103074, -0.039401090797785, -0.030562400352880915, -0.02195036420732166, -0.013734124718256953, -0.010869347963875103, -0.008716523710732494, -0.006553087326690035, -0.004368816560668413, 0.004243652709113373, 0.012479259259259252, 0.02083118310953633, 0.02930657094359572, 0.03736456799398947, 0.046093218688259996, 0.055434074074074066, 0.06364360855777446, 0.07220387101295579, 0.08108103681442523, 0.09024128133698993, 0.09965077995545703, 0.10927570804463366, 0.11905179250931928, 0.12816169275656264, 0.1379289639997568, 0.14790551207411326, 0.15772451640164528, 0.1671724096592906, 0.1762711402567662, 0.18537071762415502, 0.19440276038623144, 0.2042796965265346, 0.213626793390491, 0.22332690966392835, 0.23284806642076308, 0.24249286250939145, 0.2527281899703081, 0.26236770933495757, 0.27249908533349, 0.2825516402675876, 0.29185315635695797, 0.3014666800233743, 0.3027282130972, 0.29413708380612574, 0.2851891970001, 0.27613125525224697, 0.26776733895428106, 0.259648985127265, 0.2511829352807743, 0.2427021726910983, 0.23427797145003756, 0.22631643668601123, 0.218621426714858, 0.21107944221317348, 0.2038679007192628, 0.1966116266841458, 0.18928945650773626, 0.18195654825986635];
|
|
|
|
let mut pts = Vec::with_capacity(x.len());
|
|
for (val_x, val_y) in x.iter().zip(y) {
|
|
pts.push(z(*val_x, val_y))
|
|
}
|
|
pts
|
|
}
|
|
|
|
fn circle(center: [f64; 2], r: f64) -> Line<'static> {
|
|
let steps = 64;
|
|
let mut pts = Vec::with_capacity(steps + 1);
|
|
|
|
for k in 0..=steps {
|
|
let a = 2.0 * PI * k as f64 / steps as f64;
|
|
pts.push([
|
|
center[0] + r * a.cos(),
|
|
center[1] + r * a.sin(),
|
|
]);
|
|
}
|
|
|
|
Line::new("circle", pts)
|
|
}
|
|
|
|
fn fourier_coeff() -> Vec<C> {
|
|
let vals = pl_points();
|
|
let n = vals.len();
|
|
let i = z(0.0, 1.0);
|
|
let fourier = {
|
|
let mut fr: Vec<C> = vec![];
|
|
for k in 0..n {
|
|
let mut res = C::new(0.0, 0.0);
|
|
for (j, a) in vals.iter().enumerate() {
|
|
res += a / n as f64 * (-2.0 * PI * i * j as f64 * k as f64 / n as f64).exp();
|
|
}
|
|
fr.push(res);
|
|
}
|
|
fr
|
|
};
|
|
fourier
|
|
}
|
|
|
|
fn disp(fourier: &[C], deg: usize, t: f64) -> Vec<[f64; 2]> {
|
|
let n = fourier.len();
|
|
let deg = std::cmp::min(deg, n);
|
|
|
|
|
|
let i = z(0.0, 1.0);
|
|
|
|
let mut acc = z(0.0, 0.0);
|
|
let mut poly: Vec<[f64; 2]> = Vec::with_capacity(deg + 1);
|
|
poly.push([acc.re, acc.im]);
|
|
|
|
let idx = |freq: isize| -> usize { ((freq % n as isize) + n as isize) as usize % n };
|
|
|
|
let c0 = fourier[0];
|
|
acc += c0;
|
|
poly.push([acc.re, acc.im]);
|
|
|
|
let mut m: isize = 1;
|
|
while (m - 1) * 2 + 1 < deg as isize {
|
|
acc += fourier[idx(m)] * (2.0 * PI * i * m as f64 * t).exp();
|
|
poly.push([acc.re, acc.im]);
|
|
acc += fourier[idx(-m)] * (2.0 * PI * i * -m as f64 * t).exp();
|
|
poly.push([acc.re, acc.im]);
|
|
m += 1;
|
|
}
|
|
|
|
poly.into()
|
|
// let last_only = vec![*poly.last().unwrap()];
|
|
// last_only
|
|
}
|
|
|
|
struct MyApp {
|
|
fr: Vec<C>,
|
|
disp_deg: usize,
|
|
trail: VecDeque<(f64, [f64; 2])>,
|
|
period: f64,
|
|
focus_mode: bool,
|
|
current_bounds: ([f64; 2], [f64; 2]),
|
|
target_bounds: ([f64; 2], [f64; 2]),
|
|
}
|
|
|
|
impl eframe::App for MyApp {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.add(egui::Slider::new(&mut self.disp_deg, 2..=self.fr.len()).text("Degree of animation (epicycles - 1)"));
|
|
ui.add(egui::Slider::new(&mut self.period, 0.1..=25.0).text("Period"));
|
|
ui.checkbox(&mut self.focus_mode, "focus mode");
|
|
let time = ctx.input(|i| i.time) as f64;
|
|
let t = time / self.period;
|
|
|
|
let points = disp(&self.fr, self.disp_deg, t);
|
|
|
|
let end = *points.last().unwrap();
|
|
self.trail.push_back((time, end));
|
|
if let Some(oldest) = self.trail.front() {
|
|
if time - oldest.0 > self.period {
|
|
self.trail.pop_front();
|
|
}
|
|
}
|
|
|
|
let trail_points: Vec<[f64;2]> = self.trail.iter().map(|p| p.1).collect();
|
|
|
|
Plot::new("scatter_plot").show(ui, |plot_ui| {
|
|
if !trail_points.is_empty() {
|
|
for idx in 0..trail_points.len() - 1 {
|
|
let alpha = 255 - ((time - self.trail[idx].0) / self.period * 255.0).round() as u8;
|
|
// let alpha = (255.0 * (idx as f32) / trail_points.len() as f32).round() as u8;
|
|
plot_ui.add(Line::new("trace", vec![trail_points[idx], trail_points[idx+1]]).width(2.0).color(Color32::from_rgba_unmultiplied(240, 100, 100, alpha)));
|
|
}
|
|
|
|
for idx in 0..points.len() - 1 {
|
|
plot_ui.add(Line::new("vec", vec![points[idx], points[idx+1]]).color(Color32::from_rgb(150, 150, 150)));
|
|
}
|
|
|
|
let n = self.fr.len();
|
|
|
|
for idx in 0..points.len() - 1 {
|
|
let freq = if idx == 0 {
|
|
0
|
|
} else {
|
|
let k = (idx + 1) / 2;
|
|
if idx % 2 == 1 { k as isize } else { -(k as isize) }
|
|
};
|
|
|
|
let fr_idx = ((freq % n as isize) + n as isize) as usize % n;
|
|
|
|
plot_ui.add(circle(points[idx], self.fr[fr_idx].norm()).color(Color32::from_rgb(150, 150, 150)));
|
|
}
|
|
}
|
|
|
|
// Smooth bounds transition
|
|
|
|
let last = *points.last().unwrap();
|
|
|
|
if self.focus_mode {
|
|
self.target_bounds = ([last[0] - 0.1, last[1] - 0.1], [last[0] + 0.1, last[1] + 0.1]);
|
|
} else {
|
|
self.target_bounds = ([-0.7, -0.5], [0.7, 0.5]);
|
|
}
|
|
self.current_bounds = (
|
|
[
|
|
self.current_bounds.0[0] + (self.target_bounds.0[0] - self.current_bounds.0[0]) * 0.1,
|
|
self.current_bounds.0[1] + (self.target_bounds.0[1] - self.current_bounds.0[1]) * 0.1,
|
|
],
|
|
[
|
|
self.current_bounds.1[0] + (self.target_bounds.1[0] - self.current_bounds.1[0]) * 0.1,
|
|
self.current_bounds.1[1] + (self.target_bounds.1[1] - self.current_bounds.1[1]) * 0.1,
|
|
]
|
|
);
|
|
plot_ui.set_plot_bounds(PlotBounds::from_min_max(self.current_bounds.0, self.current_bounds.1));
|
|
|
|
// points
|
|
let scatter = Points::new("a1", points).radius(1.0).color(Color32::from_rgb(150, 150, 150));
|
|
plot_ui.points(scatter);
|
|
});
|
|
ctx.request_repaint();
|
|
});
|
|
}
|
|
}
|
|
fn main() {
|
|
let options = eframe::NativeOptions::default();
|
|
let fr = fourier_coeff();
|
|
let disp_deg = 200;
|
|
|
|
if disp_deg > fr.len() {
|
|
println!("deg is higher than points in dataset");
|
|
}
|
|
|
|
|
|
let _ = eframe::run_native(
|
|
"fourier epicycles",
|
|
options,
|
|
Box::new(|_cc| {
|
|
Ok(Box::new(MyApp {
|
|
fr,
|
|
disp_deg: disp_deg,
|
|
trail: VecDeque::new(),
|
|
period: 10.0,
|
|
focus_mode: false,
|
|
current_bounds: ([-0.7, -0.5], [0.7, 0.5]),
|
|
target_bounds: ([-0.7, -0.5], [0.7, 0.5]),
|
|
}))
|
|
}),
|
|
);
|
|
}
|
|
|