Convert orx-shader-phrases and orx-noise to MPP
This commit is contained in:
73
orx-noise/src/commonMain/kotlin/Cell.kt
Normal file
73
orx-noise/src/commonMain/kotlin/Cell.kt
Normal file
@@ -0,0 +1,73 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
val Cell2D = arrayOf(
|
||||
Vector2(-0.4313539279, 0.1281943404), Vector2(-0.1733316799, 0.415278375), Vector2(-0.2821957395, -0.3505218461), Vector2(-0.2806473808, 0.3517627718), Vector2(0.3125508975, -0.3237467165), Vector2(0.3383018443, -0.2967353402), Vector2(-0.4393982022, -0.09710417025), Vector2(-0.4460443703, -0.05953502905),
|
||||
Vector2(-0.302223039, 0.3334085102), Vector2(-0.212681052, -0.3965687458), Vector2(-0.2991156529, 0.3361990872), Vector2(0.2293323691, 0.3871778202), Vector2(0.4475439151, -0.04695150755), Vector2(0.1777518, 0.41340573), Vector2(0.1688522499, -0.4171197882), Vector2(-0.0976597166, 0.4392750616),
|
||||
Vector2(0.08450188373, 0.4419948321), Vector2(-0.4098760448, -0.1857461384), Vector2(0.3476585782, -0.2857157906), Vector2(-0.3350670039, -0.30038326), Vector2(0.2298190031, -0.3868891648), Vector2(-0.01069924099, 0.449872789), Vector2(-0.4460141246, -0.05976119672), Vector2(0.3650293864, 0.2631606867),
|
||||
Vector2(-0.349479423, 0.2834856838), Vector2(-0.4122720642, 0.1803655873), Vector2(-0.267327811, 0.3619887311), Vector2(0.322124041, -0.3142230135), Vector2(0.2880445931, -0.3457315612), Vector2(0.3892170926, -0.2258540565), Vector2(0.4492085018, -0.02667811596), Vector2(-0.4497724772, 0.01430799601),
|
||||
Vector2(0.1278175387, -0.4314657307), Vector2(-0.03572100503, 0.4485799926), Vector2(-0.4297407068, -0.1335025276), Vector2(-0.3217817723, 0.3145735065), Vector2(-0.3057158873, 0.3302087162), Vector2(-0.414503978, 0.1751754899), Vector2(-0.3738139881, 0.2505256519), Vector2(0.2236891408, -0.3904653228),
|
||||
Vector2(0.002967775577, -0.4499902136), Vector2(0.1747128327, -0.4146991995), Vector2(-0.4423772489, -0.08247647938), Vector2(-0.2763960987, -0.355112935), Vector2(-0.4019385906, -0.2023496216), Vector2(0.3871414161, -0.2293938184), Vector2(-0.430008727, 0.1326367019), Vector2(-0.03037574274, -0.4489736231),
|
||||
Vector2(-0.3486181573, 0.2845441624), Vector2(0.04553517144, -0.4476902368), Vector2(-0.0375802926, 0.4484280562), Vector2(0.3266408905, 0.3095250049), Vector2(0.06540017593, -0.4452222108), Vector2(0.03409025829, 0.448706869), Vector2(-0.4449193635, 0.06742966669), Vector2(-0.4255936157, -0.1461850686),
|
||||
Vector2(0.449917292, 0.008627302568), Vector2(0.05242606404, 0.4469356864), Vector2(-0.4495305179, -0.02055026661), Vector2(-0.1204775703, 0.4335725488), Vector2(-0.341986385, -0.2924813028), Vector2(0.3865320182, 0.2304191809), Vector2(0.04506097811, -0.447738214), Vector2(-0.06283465979, 0.4455915232),
|
||||
Vector2(0.3932600341, -0.2187385324), Vector2(0.4472261803, -0.04988730975), Vector2(0.3753571011, -0.2482076684), Vector2(-0.273662295, 0.357223947), Vector2(0.1700461538, 0.4166344988), Vector2(0.4102692229, 0.1848760794), Vector2(0.323227187, -0.3130881435), Vector2(-0.2882310238, -0.3455761521),
|
||||
Vector2(0.2050972664, 0.4005435199), Vector2(0.4414085979, -0.08751256895), Vector2(-0.1684700334, 0.4172743077), Vector2(-0.003978032396, 0.4499824166), Vector2(-0.2055133639, 0.4003301853), Vector2(-0.006095674897, -0.4499587123), Vector2(-0.1196228124, -0.4338091548), Vector2(0.3901528491, -0.2242337048),
|
||||
Vector2(0.01723531752, 0.4496698165), Vector2(-0.3015070339, 0.3340561458), Vector2(-0.01514262423, -0.4497451511), Vector2(-0.4142574071, -0.1757577897), Vector2(-0.1916377265, -0.4071547394), Vector2(0.3749248747, 0.2488600778), Vector2(-0.2237774255, 0.3904147331), Vector2(-0.4166343106, -0.1700466149),
|
||||
Vector2(0.3619171625, 0.267424695), Vector2(0.1891126846, -0.4083336779), Vector2(-0.3127425077, 0.323561623), Vector2(-0.3281807787, 0.307891826), Vector2(-0.2294806661, 0.3870899429), Vector2(-0.3445266136, 0.2894847362), Vector2(-0.4167095422, -0.1698621719), Vector2(-0.257890321, -0.3687717212),
|
||||
Vector2(-0.3612037825, 0.2683874578), Vector2(0.2267996491, 0.3886668486), Vector2(0.207157062, 0.3994821043), Vector2(0.08355176718, -0.4421754202), Vector2(-0.4312233307, 0.1286329626), Vector2(0.3257055497, 0.3105090899), Vector2(0.177701095, -0.4134275279), Vector2(-0.445182522, 0.06566979625),
|
||||
Vector2(0.3955143435, 0.2146355146), Vector2(-0.4264613988, 0.1436338239), Vector2(-0.3793799665, -0.2420141339), Vector2(0.04617599081, -0.4476245948), Vector2(-0.371405428, -0.2540826796), Vector2(0.2563570295, -0.3698392535), Vector2(0.03476646309, 0.4486549822), Vector2(-0.3065454405, 0.3294387544),
|
||||
Vector2(-0.2256979823, 0.3893076172), Vector2(0.4116448463, -0.1817925206), Vector2(-0.2907745828, -0.3434387019), Vector2(0.2842278468, -0.348876097), Vector2(0.3114589359, -0.3247973695), Vector2(0.4464155859, -0.0566844308), Vector2(-0.3037334033, -0.3320331606), Vector2(0.4079607166, 0.1899159123),
|
||||
Vector2(-0.3486948919, -0.2844501228), Vector2(0.3264821436, 0.3096924441), Vector2(0.3211142406, 0.3152548881), Vector2(0.01183382662, 0.4498443737), Vector2(0.4333844092, 0.1211526057), Vector2(0.3118668416, 0.324405723), Vector2(-0.272753471, 0.3579183483), Vector2(-0.422228622, -0.1556373694),
|
||||
Vector2(-0.1009700099, -0.4385260051), Vector2(-0.2741171231, -0.3568750521), Vector2(-0.1465125133, 0.4254810025), Vector2(0.2302279044, -0.3866459777), Vector2(-0.3699435608, 0.2562064828), Vector2(0.105700352, -0.4374099171), Vector2(-0.2646713633, 0.3639355292), Vector2(0.3521828122, 0.2801200935),
|
||||
Vector2(-0.1864187807, -0.4095705534), Vector2(0.1994492955, -0.4033856449), Vector2(0.3937065066, 0.2179339044), Vector2(-0.3226158377, 0.3137180602), Vector2(0.3796235338, 0.2416318948), Vector2(0.1482921929, 0.4248640083), Vector2(-0.407400394, 0.1911149365), Vector2(0.4212853031, 0.1581729856),
|
||||
Vector2(-0.2621297173, 0.3657704353), Vector2(-0.2536986953, -0.3716678248), Vector2(-0.2100236383, 0.3979825013), Vector2(0.3624152444, 0.2667493029), Vector2(-0.3645038479, -0.2638881295), Vector2(0.2318486784, 0.3856762766), Vector2(-0.3260457004, 0.3101519002), Vector2(-0.2130045332, -0.3963950918),
|
||||
Vector2(0.3814998766, -0.2386584257), Vector2(-0.342977305, 0.2913186713), Vector2(-0.4355865605, 0.1129794154), Vector2(-0.2104679605, 0.3977477059), Vector2(0.3348364681, -0.3006402163), Vector2(0.3430468811, 0.2912367377), Vector2(-0.2291836801, -0.3872658529), Vector2(0.2547707298, -0.3709337882),
|
||||
Vector2(0.4236174945, -0.151816397), Vector2(-0.15387742, 0.4228731957), Vector2(-0.4407449312, 0.09079595574), Vector2(-0.06805276192, -0.444824484), Vector2(0.4453517192, -0.06451237284), Vector2(0.2562464609, -0.3699158705), Vector2(0.3278198355, -0.3082761026), Vector2(-0.4122774207, -0.1803533432),
|
||||
Vector2(0.3354090914, -0.3000012356), Vector2(0.446632869, -0.05494615882), Vector2(-0.1608953296, 0.4202531296), Vector2(-0.09463954939, 0.4399356268), Vector2(-0.02637688324, -0.4492262904), Vector2(0.447102804, -0.05098119915), Vector2(-0.4365670908, 0.1091291678), Vector2(-0.3959858651, 0.2137643437),
|
||||
Vector2(-0.4240048207, -0.1507312575), Vector2(-0.3882794568, 0.2274622243), Vector2(-0.4283652566, -0.1378521198), Vector2(0.3303888091, 0.305521251), Vector2(0.3321434919, -0.3036127481), Vector2(-0.413021046, -0.1786438231), Vector2(0.08403060337, -0.4420846725), Vector2(-0.3822882919, 0.2373934748),
|
||||
Vector2(-0.3712395594, -0.2543249683), Vector2(0.4472363971, -0.04979563372), Vector2(-0.4466591209, 0.05473234629), Vector2(0.0486272539, -0.4473649407), Vector2(-0.4203101295, -0.1607463688), Vector2(0.2205360833, 0.39225481), Vector2(-0.3624900666, 0.2666476169), Vector2(-0.4036086833, -0.1989975647),
|
||||
Vector2(0.2152727807, 0.3951678503), Vector2(-0.4359392962, -0.1116106179), Vector2(0.4178354266, 0.1670735057), Vector2(0.2007630161, 0.4027334247), Vector2(-0.07278067175, -0.4440754146), Vector2(0.3644748615, -0.2639281632), Vector2(-0.4317451775, 0.126870413), Vector2(-0.297436456, 0.3376855855),
|
||||
Vector2(-0.2998672222, 0.3355289094), Vector2(-0.2673674124, 0.3619594822), Vector2(0.2808423357, 0.3516071423), Vector2(0.3498946567, 0.2829730186), Vector2(-0.2229685561, 0.390877248), Vector2(0.3305823267, 0.3053118493), Vector2(-0.2436681211, -0.3783197679), Vector2(-0.03402776529, 0.4487116125),
|
||||
Vector2(-0.319358823, 0.3170330301), Vector2(0.4454633477, -0.06373700535), Vector2(0.4483504221, 0.03849544189), Vector2(-0.4427358436, -0.08052932871), Vector2(0.05452298565, 0.4466847255), Vector2(-0.2812560807, 0.3512762688), Vector2(0.1266696921, 0.4318041097), Vector2(-0.3735981243, 0.2508474468),
|
||||
Vector2(0.2959708351, -0.3389708908), Vector2(-0.3714377181, 0.254035473), Vector2(-0.404467102, -0.1972469604), Vector2(0.1636165687, -0.419201167), Vector2(0.3289185495, -0.3071035458), Vector2(-0.2494824991, -0.3745109914), Vector2(0.03283133272, 0.4488007393), Vector2(-0.166306057, -0.4181414777),
|
||||
Vector2(-0.106833179, 0.4371346153), Vector2(0.06440260376, -0.4453676062), Vector2(-0.4483230967, 0.03881238203), Vector2(-0.421377757, -0.1579265206), Vector2(0.05097920662, -0.4471030312), Vector2(0.2050584153, -0.4005634111), Vector2(0.4178098529, -0.167137449), Vector2(-0.3565189504, -0.2745801121),
|
||||
Vector2(0.4478398129, 0.04403977727), Vector2(-0.3399999602, -0.2947881053), Vector2(0.3767121994, 0.2461461331), Vector2(-0.3138934434, 0.3224451987), Vector2(-0.1462001792, -0.4255884251), Vector2(0.3970290489, -0.2118205239), Vector2(0.4459149305, -0.06049689889), Vector2(-0.4104889426, -0.1843877112),
|
||||
Vector2(0.1475103971, -0.4251360756), Vector2(0.09258030352, 0.4403735771), Vector2(-0.1589664637, -0.4209865359), Vector2(0.2482445008, 0.3753327428), Vector2(0.4383624232, -0.1016778537), Vector2(0.06242802956, 0.4456486745), Vector2(0.2846591015, -0.3485243118), Vector2(-0.344202744, -0.2898697484),
|
||||
Vector2(0.1198188883, -0.4337550392), Vector2(-0.243590703, 0.3783696201), Vector2(0.2958191174, -0.3391033025), Vector2(-0.1164007991, 0.4346847754), Vector2(0.1274037151, -0.4315881062), Vector2(0.368047306, 0.2589231171), Vector2(0.2451436949, 0.3773652989), Vector2(-0.4314509715, 0.12786735))
|
||||
|
||||
val Cell3D = arrayOf(
|
||||
Vector3(0.1453787434, -0.4149781685, -0.0956981749), Vector3(-0.01242829687, -0.1457918398, -0.4255470325), Vector3(0.2877979582, -0.02606483451, -0.3449535616), Vector3(-0.07732986802, 0.2377094325, 0.3741848704), Vector3(0.1107205875, -0.3552302079, -0.2530858567), Vector3(0.2755209141, 0.2640521179, -0.238463215), Vector3(0.294168941, 0.1526064594, 0.3044271714), Vector3(0.4000921098, -0.2034056362, 0.03244149937),
|
||||
Vector3(-0.1697304074, 0.3970864695, -0.1265461359), Vector3(-0.1483224484, -0.3859694688, 0.1775613147), Vector3(0.2623596946, -0.2354852944, 0.2796677792), Vector3(-0.2709003183, 0.3505271138, -0.07901746678), Vector3(-0.03516550699, 0.3885234328, 0.2243054374), Vector3(-0.1267712655, 0.1920044036, 0.3867342179), Vector3(0.02952021915, 0.4409685861, 0.08470692262), Vector3(-0.2806854217, -0.266996757, 0.2289725438),
|
||||
Vector3(-0.171159547, 0.2141185563, 0.3568720405), Vector3(0.2113227183, 0.3902405947, -0.07453178509), Vector3(-0.1024352839, 0.2128044156, -0.3830421561), Vector3(-0.3304249877, -0.1566986703, 0.2622305365), Vector3(0.2091111325, 0.3133278055, -0.2461670583), Vector3(0.344678154, -0.1944240454, -0.2142341261), Vector3(0.1984478035, -0.3214342325, -0.2445373252), Vector3(-0.2929008603, 0.2262915116, 0.2559320961),
|
||||
Vector3(-0.1617332831, 0.006314769776, -0.4198838754), Vector3(-0.3582060271, -0.148303178, -0.2284613961), Vector3(-0.1852067326, -0.3454119342, -0.2211087107), Vector3(0.3046301062, 0.1026310383, 0.314908508), Vector3(-0.03816768434, -0.2551766358, -0.3686842991), Vector3(-0.4084952196, 0.1805950793, 0.05492788837), Vector3(-0.02687443361, -0.2749741471, 0.3551999201), Vector3(-0.03801098351, 0.3277859044, 0.3059600725),
|
||||
Vector3(0.2371120802, 0.2900386767, -0.2493099024), Vector3(0.4447660503, 0.03946930643, 0.05590469027), Vector3(0.01985147278, -0.01503183293, -0.4493105419), Vector3(0.4274339143, 0.03345994256, -0.1366772882), Vector3(-0.2072988631, 0.2871414597, -0.2776273824), Vector3(-0.3791240978, 0.1281177671, 0.2057929936), Vector3(-0.2098721267, -0.1007087278, -0.3851122467), Vector3(0.01582798878, 0.4263894424, 0.1429738373),
|
||||
Vector3(-0.1888129464, -0.3160996813, -0.2587096108), Vector3(0.1612988974, -0.1974805082, -0.3707885038), Vector3(-0.08974491322, 0.229148752, -0.3767448739), Vector3(0.07041229526, 0.4150230285, -0.1590534329), Vector3(-0.1082925611, -0.1586061639, 0.4069604477), Vector3(0.2474100658, -0.3309414609, 0.1782302128), Vector3(-0.1068836661, -0.2701644537, -0.3436379634), Vector3(0.2396452163, 0.06803600538, -0.3747549496),
|
||||
Vector3(-0.3063886072, 0.2597428179, 0.2028785103), Vector3(0.1593342891, -0.3114350249, -0.2830561951), Vector3(0.2709690528, 0.1412648683, -0.3303331794), Vector3(-0.1519780427, 0.3623355133, 0.2193527988), Vector3(0.1699773681, 0.3456012883, 0.2327390037), Vector3(-0.1986155616, 0.3836276443, -0.1260225743), Vector3(-0.1887482106, -0.2050154888, -0.353330953), Vector3(0.2659103394, 0.3015631259, -0.2021172246),
|
||||
Vector3(-0.08838976154, -0.4288819642, -0.1036702021), Vector3(-0.04201869311, 0.3099592485, 0.3235115047), Vector3(-0.3230334656, 0.201549922, -0.2398478873), Vector3(0.2612720941, 0.2759854499, -0.2409749453), Vector3(0.385713046, 0.2193460345, 0.07491837764), Vector3(0.07654967953, 0.3721732183, 0.241095919), Vector3(0.4317038818, -0.02577753072, 0.1243675091), Vector3(-0.2890436293, -0.3418179959, -0.04598084447),
|
||||
Vector3(-0.2201947582, 0.383023377, -0.08548310451), Vector3(0.4161322773, -0.1669634289, -0.03817251927), Vector3(0.2204718095, 0.02654238946, -0.391391981), Vector3(-0.1040307469, 0.3890079625, -0.2008741118), Vector3(-0.1432122615, 0.371614387, -0.2095065525), Vector3(0.3978380468, -0.06206669342, 0.2009293758), Vector3(-0.2599274663, 0.2616724959, -0.2578084893), Vector3(0.4032618332, -0.1124593585, 0.1650235939),
|
||||
Vector3(-0.08953470255, -0.3048244735, 0.3186935478), Vector3(0.118937202, -0.2875221847, 0.325092195), Vector3(0.02167047076, -0.03284630549, -0.4482761547), Vector3(-0.3411343612, 0.2500031105, 0.1537068389), Vector3(0.3162964612, 0.3082064153, -0.08640228117), Vector3(0.2355138889, -0.3439334267, -0.1695376245), Vector3(-0.02874541518, -0.3955933019, 0.2125550295), Vector3(-0.2461455173, 0.02020282325, -0.3761704803),
|
||||
Vector3(0.04208029445, -0.4470439576, 0.02968078139), Vector3(0.2727458746, 0.2288471896, -0.2752065618), Vector3(-0.1347522818, -0.02720848277, -0.4284874806), Vector3(0.3829624424, 0.1231931484, -0.2016512234), Vector3(-0.3547613644, 0.1271702173, 0.2459107769), Vector3(0.2305790207, 0.3063895591, 0.2354968222), Vector3(-0.08323845599, -0.1922245118, 0.3982726409), Vector3(0.2993663085, -0.2619918095, -0.2103333191),
|
||||
Vector3(-0.2154865723, 0.2706747713, 0.287751117), Vector3(0.01683355354, -0.2680655787, -0.3610505186), Vector3(0.05240429123, 0.4335128183, -0.1087217856), Vector3(0.00940104872, -0.4472890582, 0.04841609928), Vector3(0.3465688735, 0.01141914583, -0.2868093776), Vector3(-0.3706867948, -0.2551104378, 0.003156692623), Vector3(0.2741169781, 0.2139972417, -0.2855959784), Vector3(0.06413433865, 0.1708718512, 0.4113266307),
|
||||
Vector3(-0.388187972, -0.03973280434, -0.2241236325), Vector3(0.06419469312, -0.2803682491, 0.3460819069), Vector3(-0.1986120739, -0.3391173584, 0.2192091725), Vector3(-0.203203009, -0.3871641506, 0.1063600375), Vector3(-0.1389736354, -0.2775901578, -0.3257760473), Vector3(-0.06555641638, 0.342253257, -0.2847192729), Vector3(-0.2529246486, -0.2904227915, 0.2327739768), Vector3(0.1444476522, 0.1069184044, 0.4125570634),
|
||||
Vector3(-0.3643780054, -0.2447099973, -0.09922543227), Vector3(0.4286142488, -0.1358496089, -0.01829506817), Vector3(0.165872923, -0.3136808464, -0.2767498872), Vector3(0.2219610524, -0.3658139958, 0.1393320198), Vector3(0.04322940318, -0.3832730794, 0.2318037215), Vector3(-0.08481269795, -0.4404869674, -0.03574965489), Vector3(0.1822082075, -0.3953259299, 0.1140946023), Vector3(-0.3269323334, 0.3036542563, 0.05838957105),
|
||||
Vector3(-0.4080485344, 0.04227858267, -0.184956522), Vector3(0.2676025294, -0.01299671652, 0.36155217), Vector3(0.3024892441, -0.1009990293, -0.3174892964), Vector3(0.1448494052, 0.425921681, -0.0104580805), Vector3(0.4198402157, 0.08062320474, 0.1404780841), Vector3(-0.3008872161, -0.333040905, -0.03241355801), Vector3(0.3639310428, -0.1291284382, -0.2310412139), Vector3(0.3295806598, 0.0184175994, -0.3058388149),
|
||||
Vector3(0.2776259487, -0.2974929052, -0.1921504723), Vector3(0.4149000507, -0.144793182, -0.09691688386), Vector3(0.145016715, -0.0398992945, 0.4241205002), Vector3(0.09299023471, -0.299732164, -0.3225111565), Vector3(0.1028907093, -0.361266869, 0.247789732), Vector3(0.2683057049, -0.07076041213, -0.3542668666), Vector3(-0.4227307273, -0.07933161816, -0.1323073187), Vector3(-0.1781224702, 0.1806857196, -0.3716517945),
|
||||
Vector3(0.4390788626, -0.02841848598, -0.09435116353), Vector3(0.2972583585, 0.2382799621, -0.2394997452), Vector3(-0.1707002821, 0.2215845691, 0.3525077196), Vector3(0.3806686614, 0.1471852559, -0.1895464869), Vector3(-0.1751445661, -0.274887877, 0.3102596268), Vector3(-0.2227237566, -0.2316778837, 0.3149912482), Vector3(0.1369633021, 0.1341343041, -0.4071228836), Vector3(-0.3529503428, -0.2472893463, -0.129514612),
|
||||
Vector3(-0.2590744185, -0.2985577559, -0.2150435121), Vector3(-0.3784019401, 0.2199816631, -0.1044989934), Vector3(-0.05635805671, 0.1485737441, 0.4210102279), Vector3(0.3251428613, 0.09666046873, -0.2957006485), Vector3(-0.4190995804, 0.1406751354, -0.08405978803), Vector3(-0.3253150961, -0.3080335042, -0.04225456877), Vector3(0.2857945863, -0.05796152095, 0.3427271751), Vector3(-0.2733604046, 0.1973770973, -0.2980207554),
|
||||
Vector3(0.219003657, 0.2410037886, -0.3105713639), Vector3(0.3182767252, -0.271342949, 0.1660509868), Vector3(-0.03222023115, -0.3331161506, -0.300824678), Vector3(-0.3087780231, 0.1992794134, -0.2596995338), Vector3(-0.06487611647, -0.4311322747, 0.1114273361), Vector3(0.3921171432, -0.06294284106, -0.2116183942), Vector3(-0.1606404506, -0.358928121, -0.2187812825), Vector3(-0.03767771199, -0.2290351443, 0.3855169162),
|
||||
Vector3(0.1394866832, -0.3602213994, 0.2308332918), Vector3(-0.4345093872, 0.005751117145, 0.1169124335), Vector3(-0.1044637494, 0.4168128432, -0.1336202785), Vector3(0.2658727501, 0.2551943237, 0.2582393035), Vector3(0.2051461999, 0.1975390727, 0.3484154868), Vector3(-0.266085566, 0.23483312, 0.2766800993), Vector3(0.07849405464, -0.3300346342, -0.2956616708), Vector3(-0.2160686338, 0.05376451292, -0.3910546287),
|
||||
Vector3(-0.185779186, 0.2148499206, 0.3490352499), Vector3(0.02492421743, -0.3229954284, -0.3123343347), Vector3(-0.120167831, 0.4017266681, 0.1633259825), Vector3(-0.02160084693, -0.06885389554, 0.4441762538), Vector3(0.2597670064, 0.3096300784, 0.1978643903), Vector3(-0.1611553854, -0.09823036005, 0.4085091653), Vector3(-0.3278896792, 0.1461670309, 0.2713366126), Vector3(0.2822734956, 0.03754421121, -0.3484423997),
|
||||
Vector3(0.03169341113, 0.347405252, -0.2842624114), Vector3(0.2202613604, -0.3460788041, -0.1849713341), Vector3(0.2933396046, 0.3031973659, 0.1565989581), Vector3(-0.3194922995, 0.2453752201, -0.200538455), Vector3(-0.3441586045, -0.1698856132, -0.2349334659), Vector3(0.2703645948, -0.3574277231, 0.04060059933), Vector3(0.2298568861, 0.3744156221, 0.0973588921), Vector3(0.09326603877, -0.3170108894, 0.3054595587),
|
||||
Vector3(-0.1116165319, -0.2985018719, 0.3177080142), Vector3(0.2172907365, -0.3460005203, -0.1885958001), Vector3(0.1991339479, 0.3820341668, -0.1299829458), Vector3(-0.0541918155, -0.2103145071, 0.39412061), Vector3(0.08871336998, 0.2012117383, 0.3926114802), Vector3(0.2787673278, 0.3505404674, 0.04370535101), Vector3(-0.322166438, 0.3067213525, 0.06804996813), Vector3(-0.4277366384, 0.132066775, 0.04582286686),
|
||||
Vector3(0.240131882, -0.1612516055, 0.344723946), Vector3(0.1448607981, -0.2387819045, 0.3528435224), Vector3(-0.3837065682, -0.2206398454, 0.08116235683), Vector3(-0.4382627882, -0.09082753406, -0.04664855374), Vector3(-0.37728353, 0.05445141085, 0.2391488697), Vector3(0.1259579313, 0.348394558, 0.2554522098), Vector3(-0.1406285511, -0.270877371, -0.3306796947), Vector3(-0.1580694418, 0.4162931958, -0.06491553533),
|
||||
Vector3(0.2477612106, -0.2927867412, -0.2353514536), Vector3(0.2916132853, 0.3312535401, 0.08793624968), Vector3(0.07365265219, -0.1666159848, 0.411478311), Vector3(-0.26126526, -0.2422237692, 0.2748965434), Vector3(-0.3721862032, 0.252790166, 0.008634938242), Vector3(-0.3691191571, -0.255281188, 0.03290232422), Vector3(0.2278441737, -0.3358364886, 0.1944244981), Vector3(0.363398169, -0.2310190248, 0.1306597909),
|
||||
Vector3(-0.304231482, -0.2698452035, 0.1926830856), Vector3(-0.3199312232, 0.316332536, -0.008816977938), Vector3(0.2874852279, 0.1642275508, -0.304764754), Vector3(-0.1451096801, 0.3277541114, -0.2720669462), Vector3(0.3220090754, 0.0511344108, 0.3101538769), Vector3(-0.1247400865, -0.04333605335, -0.4301882115), Vector3(-0.2829555867, -0.3056190617, -0.1703910946), Vector3(0.1069384374, 0.3491024667, -0.2630430352),
|
||||
Vector3(-0.1420661144, -0.3055376754, -0.2982682484), Vector3(-0.250548338, 0.3156466809, -0.2002316239), Vector3(0.3265787872, 0.1871229129, 0.2466400438), Vector3(0.07646097258, -0.3026690852, 0.324106687), Vector3(0.3451771584, 0.2757120714, -0.0856480183), Vector3(0.298137964, 0.2852657134, 0.179547284), Vector3(0.2812250376, 0.3466716415, 0.05684409612), Vector3(0.4390345476, -0.09790429955, -0.01278335452),
|
||||
Vector3(0.2148373234, 0.1850172527, 0.3494474791), Vector3(0.2595421179, -0.07946825393, 0.3589187731), Vector3(0.3182823114, -0.307355516, -0.08203022006), Vector3(-0.4089859285, -0.04647718411, 0.1818526372), Vector3(-0.2826749061, 0.07417482322, 0.3421885344), Vector3(0.3483864637, 0.225442246, -0.1740766085), Vector3(-0.3226415069, -0.1420585388, -0.2796816575), Vector3(0.4330734858, -0.118868561, -0.02859407492),
|
||||
Vector3(-0.08717822568, -0.3909896417, -0.2050050172), Vector3(-0.2149678299, 0.3939973956, -0.03247898316), Vector3(-0.2687330705, 0.322686276, -0.1617284888), Vector3(0.2105665099, -0.1961317136, -0.3459683451), Vector3(0.4361845915, -0.1105517485, 0.004616608544), Vector3(0.05333333359, -0.313639498, -0.3182543336), Vector3(-0.05986216652, 0.1361029153, -0.4247264031), Vector3(0.3664988455, 0.2550543014, -0.05590974511),
|
||||
Vector3(-0.2341015558, -0.182405731, 0.3382670703), Vector3(-0.04730947785, -0.4222150243, -0.1483114513), Vector3(-0.2391566239, -0.2577696514, -0.2808182972), Vector3(-0.1242081035, 0.4256953395, -0.07652336246), Vector3(0.2614832715, -0.3650179274, 0.02980623099), Vector3(-0.2728794681, -0.3499628774, 0.07458404908), Vector3(0.007892900508, -0.1672771315, 0.4176793787), Vector3(-0.01730330376, 0.2978486637, -0.3368779738),
|
||||
Vector3(0.2054835762, -0.3252600376, -0.2334146693), Vector3(-0.3231994983, 0.1564282844, -0.2712420987), Vector3(-0.2669545963, 0.2599343665, -0.2523278991), Vector3(-0.05554372779, 0.3170813944, -0.3144428146), Vector3(-0.2083935713, -0.310922837, -0.2497981362), Vector3(0.06989323478, -0.3156141536, 0.3130537363), Vector3(0.3847566193, -0.1605309138, -0.1693876312), Vector3(-0.3026215288, -0.3001537679, -0.1443188342),
|
||||
Vector3(0.3450735512, 0.08611519592, 0.2756962409), Vector3(0.1814473292, -0.2788782453, -0.3029914042), Vector3(-0.03855010448, 0.09795110726, 0.4375151083), Vector3(0.3533670318, 0.2665752752, 0.08105160988), Vector3(-0.007945601311, 0.140359426, -0.4274764309), Vector3(0.4063099273, -0.1491768253, -0.1231199324), Vector3(-0.2016773589, 0.008816271194, -0.4021797064), Vector3(-0.07527055435, -0.425643481, -0.1251477955)
|
||||
)
|
||||
10
orx-noise/src/commonMain/kotlin/CubicNoise1D.kt
Normal file
10
orx-noise/src/commonMain/kotlin/CubicNoise1D.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
fun cubicLinear(seed: Int, x: Double) = cubic(seed, x, ::linear)
|
||||
fun cubicQuintic(seed: Int, x: Double) = cubic(seed, x, ::quintic)
|
||||
fun cubicHermite(seed: Int, x: Double) = cubic(seed, x, ::hermite)
|
||||
|
||||
|
||||
fun cubic(seed: Int, x: Double, interpolator: (Double) -> Double = ::linear): Double {
|
||||
return cubic(seed, x, 0.0, interpolator)
|
||||
}
|
||||
41
orx-noise/src/commonMain/kotlin/CubicNoise2D.kt
Normal file
41
orx-noise/src/commonMain/kotlin/CubicNoise2D.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
fun cubic(seed: Int, x: Double, y: Double) = cubic(seed, x, y, ::linear)
|
||||
fun cubicLinear(seed: Int, x: Double, y: Double) = cubic(seed, x, y, ::linear)
|
||||
fun cubicQuintic(seed: Int, x: Double, y: Double) = cubic(seed, x, y, ::quintic)
|
||||
fun cubicHermite(seed: Int, x: Double, y: Double) = cubic(seed, x, y, ::hermite)
|
||||
|
||||
fun cubic(seed: Int, position: Vector2) = cubic(seed, position.x, position.y, ::linear)
|
||||
fun cubicLinear(seed: Int, position: Vector2) = cubic(seed, position.x, position.y, ::linear)
|
||||
fun cubicQuintic(seed: Int, position: Vector2) = cubic(seed, position.x, position.y, ::quintic)
|
||||
fun cubicHermite(seed: Int, position: Vector2) = cubic(seed, position.x, position.y, ::hermite)
|
||||
|
||||
private const val CUBIC_2D_BOUNDING = 1 / (1.5 * 1.5).toFloat()
|
||||
|
||||
fun cubic(seed: Int, x: Double, y: Double, interpolator: (Double) -> Double = ::linear): Double {
|
||||
val x1 = x.fastFloor()
|
||||
val y1 = y.fastFloor()
|
||||
|
||||
val x0 = x1 - 1
|
||||
val y0 = y1 - 1
|
||||
val x2 = x1 + 1
|
||||
val y2 = y1 + 1
|
||||
val x3 = x1 + 2
|
||||
val y3 = y1 + 2
|
||||
|
||||
val xs = interpolator(x - x1.toDouble())
|
||||
val ys = interpolator(y - y1.toDouble())
|
||||
|
||||
return cubic(
|
||||
cubic(valCoord2D(seed, x0, y0), valCoord2D(seed, x1, y0), valCoord2D(seed, x2, y0), valCoord2D(seed, x3, y0),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y1), valCoord2D(seed, x1, y1), valCoord2D(seed, x2, y1), valCoord2D(seed, x3, y1),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y2), valCoord2D(seed, x1, y2), valCoord2D(seed, x2, y2), valCoord2D(seed, x3, y2),
|
||||
xs),
|
||||
cubic(valCoord2D(seed, x0, y3), valCoord2D(seed, x1, y3), valCoord2D(seed, x2, y3), valCoord2D(seed, x3, y3),
|
||||
xs),
|
||||
ys) * CUBIC_2D_BOUNDING
|
||||
}
|
||||
62
orx-noise/src/commonMain/kotlin/CubicNoise3D.kt
Normal file
62
orx-noise/src/commonMain/kotlin/CubicNoise3D.kt
Normal file
@@ -0,0 +1,62 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
private const val CUBIC_3D_BOUNDING = 1 / (1.5 * 1.5 * 1.5).toFloat()
|
||||
|
||||
fun cubic(seed: Int, x: Double, y: Double, z: Double) = cubic(seed, x, y, z, ::linear)
|
||||
fun cubicLinear(seed: Int, x: Double, y: Double, z: Double) = cubic(seed, x, y, z, ::linear)
|
||||
fun cubicQuintic(seed: Int, x: Double, y: Double, z: Double) = cubic(seed, x, y, z, ::quintic)
|
||||
fun cubicHermite(seed: Int, x: Double, y: Double, z: Double) = perlin(seed, x, y, z, ::hermite)
|
||||
|
||||
fun cubic(seed: Int, position: Vector3) = cubic(seed, position.x, position.y, position.z, ::linear)
|
||||
fun cubicLinear(seed: Int, position: Vector3) = cubic(seed, position.x, position.y, position.z, ::linear)
|
||||
fun cubicQuintic(seed: Int, position: Vector3) = cubic(seed, position.x, position.y, position.z, ::quintic)
|
||||
fun cubicHermite(seed: Int, position: Vector3) = perlin(seed, position.x, position.y, position.z, ::hermite)
|
||||
|
||||
fun cubic(seed: Int, x: Double, y: Double, z: Double, interpolator: (Double) -> Double): Double {
|
||||
val x1 = x.fastFloor()
|
||||
val y1 = y.fastFloor()
|
||||
val z1 = z.fastFloor()
|
||||
|
||||
val x0 = x1 - 1
|
||||
val y0 = y1 - 1
|
||||
val z0 = z1 - 1
|
||||
val x2 = x1 + 1
|
||||
val y2 = y1 + 1
|
||||
val z2 = z1 + 1
|
||||
val x3 = x1 + 2
|
||||
val y3 = y1 + 2
|
||||
val z3 = z1 + 2
|
||||
|
||||
val xs = interpolator(x - x1.toFloat())
|
||||
val ys = interpolator(y - y1.toFloat())
|
||||
val zs = interpolator(z - z1.toFloat())
|
||||
|
||||
return cubic(
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z0), valCoord3D(seed, x1, y0, z0), valCoord3D(seed, x2, y0, z0), valCoord3D(seed, x3, y0, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z0), valCoord3D(seed, x1, y1, z0), valCoord3D(seed, x2, y1, z0), valCoord3D(seed, x3, y1, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z0), valCoord3D(seed, x1, y2, z0), valCoord3D(seed, x2, y2, z0), valCoord3D(seed, x3, y2, z0), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z0), valCoord3D(seed, x1, y3, z0), valCoord3D(seed, x2, y3, z0), valCoord3D(seed, x3, y3, z0), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z1), valCoord3D(seed, x1, y0, z1), valCoord3D(seed, x2, y0, z1), valCoord3D(seed, x3, y0, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z1), valCoord3D(seed, x1, y1, z1), valCoord3D(seed, x2, y1, z1), valCoord3D(seed, x3, y1, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z1), valCoord3D(seed, x1, y2, z1), valCoord3D(seed, x2, y2, z1), valCoord3D(seed, x3, y2, z1), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z1), valCoord3D(seed, x1, y3, z1), valCoord3D(seed, x2, y3, z1), valCoord3D(seed, x3, y3, z1), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z2), valCoord3D(seed, x1, y0, z2), valCoord3D(seed, x2, y0, z2), valCoord3D(seed, x3, y0, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z2), valCoord3D(seed, x1, y1, z2), valCoord3D(seed, x2, y1, z2), valCoord3D(seed, x3, y1, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z2), valCoord3D(seed, x1, y2, z2), valCoord3D(seed, x2, y2, z2), valCoord3D(seed, x3, y2, z2), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z2), valCoord3D(seed, x1, y3, z2), valCoord3D(seed, x2, y3, z2), valCoord3D(seed, x3, y3, z2), xs),
|
||||
ys),
|
||||
cubic(
|
||||
cubic(valCoord3D(seed, x0, y0, z3), valCoord3D(seed, x1, y0, z3), valCoord3D(seed, x2, y0, z3), valCoord3D(seed, x3, y0, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y1, z3), valCoord3D(seed, x1, y1, z3), valCoord3D(seed, x2, y1, z3), valCoord3D(seed, x3, y1, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y2, z3), valCoord3D(seed, x1, y2, z3), valCoord3D(seed, x2, y2, z3), valCoord3D(seed, x3, y2, z3), xs),
|
||||
cubic(valCoord3D(seed, x0, y3, z3), valCoord3D(seed, x1, y3, z3), valCoord3D(seed, x2, y3, z3), valCoord3D(seed, x3, y3, z3), xs),
|
||||
ys),
|
||||
zs) * CUBIC_3D_BOUNDING
|
||||
}
|
||||
27
orx-noise/src/commonMain/kotlin/Distribute.kt
Normal file
27
orx-noise/src/commonMain/kotlin/Distribute.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
internal fun sumDistribution(probabilities: List<Double>): List<Double> = probabilities.foldIndexed(mutableListOf()) {
|
||||
index: Int, list: MutableList<Double>, prob: Double ->
|
||||
val prev = list.elementAtOrNull(index - 1) ?: 0.0
|
||||
list.add(prev + prob)
|
||||
list
|
||||
}
|
||||
|
||||
internal fun createDecreasingOdds(size: Int): List<Double> {
|
||||
var den = 4.0;
|
||||
var t = 1.0 + (1.0 / (size / 3.0))
|
||||
|
||||
return (1 until size).map {
|
||||
val prob = t / den
|
||||
|
||||
t -= prob
|
||||
den += 1.0
|
||||
prob
|
||||
}
|
||||
}
|
||||
|
||||
object Distribute {
|
||||
fun equal(size: Int): List<Double> = sumDistribution(List(size) { 1.0 / size })
|
||||
fun decreasing(size: Int): List<Double> = sumDistribution(createDecreasingOdds(size))
|
||||
fun increasing(size: Int): List<Double> = sumDistribution(createDecreasingOdds(size)).asReversed()
|
||||
}
|
||||
318
orx-noise/src/commonMain/kotlin/Fractal.kt
Normal file
318
orx-noise/src/commonMain/kotlin/Fractal.kt
Normal file
@@ -0,0 +1,318 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import kotlin.math.abs
|
||||
|
||||
inline fun fbm(seed: Int, position: Vector4, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
fbm(seed, position.x, position.y, position.z, position.w, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun fbm(seed: Int, x: Double, y: Double, z: Double, w: Double, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = noise(seed, x, y, z, w)
|
||||
var amp = 1.0
|
||||
|
||||
var lx = x
|
||||
var ly = y
|
||||
var lz = z
|
||||
var lw = w
|
||||
for (i in 1 until octaves) {
|
||||
lx *= lacunarity
|
||||
ly *= lacunarity
|
||||
lz *= lacunarity
|
||||
lw *= lacunarity
|
||||
amp *= gain
|
||||
sum += noise(seed + i, lx, ly, lz, lw) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun fbm(seed: Int, position: Vector3, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
fbm(seed, position.x, position.y, position.z, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun fbm(seed: Int, x: Double, y: Double, z: Double, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = noise(seed, x, y, z)
|
||||
var amp = 1.0
|
||||
|
||||
var lx = x
|
||||
var ly = y
|
||||
var lz = z
|
||||
for (i in 1 until octaves) {
|
||||
lx *= lacunarity
|
||||
ly *= lacunarity
|
||||
lz *= lacunarity
|
||||
amp *= gain
|
||||
sum += noise(seed + i, lx, ly, lz) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun fbm(seed: Int, position: Vector2, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
fbm(seed, position.x, position.y, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun fbm(seed: Int, x: Double, y: Double, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = noise(seed, x, y)
|
||||
var amp = 1.0
|
||||
|
||||
var lx = x
|
||||
var ly = y
|
||||
for (i in 1 until octaves) {
|
||||
lx *= lacunarity
|
||||
ly *= lacunarity
|
||||
amp *= gain
|
||||
sum += noise(seed + i, lx, ly) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun fbm(seed: Int, x: Double, crossinline noise: (Int, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = noise(seed, x)
|
||||
var amp = 1.0
|
||||
|
||||
var lx = x
|
||||
for (i in 1 until octaves) {
|
||||
lx *= lacunarity
|
||||
amp *= gain
|
||||
sum += noise(seed + i, lx) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun fbmFunc1D(crossinline noise: (Int, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double) -> Double {
|
||||
return { seed, x ->
|
||||
fbm(seed, x, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun fbmFunc2D(crossinline noise: (Int, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double) -> Double {
|
||||
return { seed, x, y ->
|
||||
fbm(seed, x, y, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun fbmFunc3D(crossinline noise: (Int, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z ->
|
||||
fbm(seed, x, y, z, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun fbmFunc4D(crossinline noise: (Int, Double, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z, w ->
|
||||
fbm(seed, x, y, z, w, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun billow(seed: Int, position: Vector4, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) = billow(seed, position.x, position.y,
|
||||
position.z, position.w, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun billow(seed: Int, x: Double, y: Double, z: Double, w: Double, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = abs(noise(seed, x, y, z, w) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
var z = z
|
||||
var w = w
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
z *= lacunarity
|
||||
w *= lacunarity
|
||||
amp *= gain
|
||||
sum += abs(noise(seed + i, x, y, z, w) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun billow(seed: Int, position: Vector3, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
billow(seed, position.x, position.y, position.z, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun billow(seed: Int, x: Double, y: Double, z: Double, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = abs(noise(seed, x, y, z) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
var z = z
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
z *= lacunarity
|
||||
amp *= gain
|
||||
sum += abs(noise(seed + i, x, y, z) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun billow(seed: Int, position: Vector2, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
billow(seed, position.x, position.y, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun billow(seed: Int, x: Double, y: Double, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = abs(noise(seed, x, y) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
amp *= gain
|
||||
sum += abs(noise(seed + i, x, y) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun billow(seed: Int, x: Double, crossinline noise: (Int, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = abs(noise(seed, x) * 2.0 - 1.0)
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
amp *= gain
|
||||
sum += abs(noise(seed + i, x) * 2.0 - 1.0) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun billowFunc1D(crossinline noise: (Int, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double) -> Double {
|
||||
return { seed, x ->
|
||||
billow(seed, x, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun billowFunc2D(crossinline noise: (Int, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double) -> Double {
|
||||
return { seed, x, y ->
|
||||
billow(seed, x, y, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun billowFunc3D(crossinline noise: (Int, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z ->
|
||||
billow(seed, x, y, z, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun billowFunc4D(crossinline noise: (Int, Double, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z, w ->
|
||||
billow(seed, x, y, z, w, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun rigid(seed: Int, position: Vector4, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
rigid(seed, position.x, position.y, position.z, position.w, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, z: Double, w: Double, crossinline noise: (Int, Double, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - abs(noise(seed, x, y, z, w))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
var z = z
|
||||
var w = w
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
z *= lacunarity
|
||||
w *= lacunarity
|
||||
amp *= gain
|
||||
sum -= (1.0 - abs(noise(seed + i, x, y, z, w))) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun rigid(seed: Int, position: Vector3, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
rigid(seed, position.x, position.y, position.z, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, z: Double, crossinline noise: (Int, Double, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - abs(noise(seed, x, y, z))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
var z = z
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
z *= lacunarity
|
||||
amp *= gain
|
||||
sum -= (1.0 - abs(noise(seed + i, x, y, z))) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun rigid(seed: Int, position: Vector2, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5) =
|
||||
rigid(seed, position.x, position.y, noise, octaves, lacunarity, gain)
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, y: Double, crossinline noise: (Int, Double, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - abs(noise(seed, x, y))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
var y = y
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
y *= lacunarity
|
||||
amp *= gain
|
||||
sum -= (1.0 - abs(noise(seed + i, x, y))) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun rigid(seed: Int, x: Double, crossinline noise: (Int, Double) -> Double,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
var sum = 1.0 - abs(noise(seed, x))
|
||||
var amp = 1.0
|
||||
|
||||
var x = x
|
||||
for (i in 1 until octaves) {
|
||||
x *= lacunarity
|
||||
amp *= gain
|
||||
sum -= (1.0 - abs(noise(seed + i, x))) * amp
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
inline fun rigidFunc1D(crossinline noise: (Int, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double) -> Double {
|
||||
return { seed, x ->
|
||||
rigid(seed, x, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun rigidFunc2D(crossinline noise: (Int, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double) -> Double {
|
||||
return { seed, x, y ->
|
||||
rigid(seed, x, y, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun rigidFunc3D(crossinline noise: (Int, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z ->
|
||||
rigid(seed, x, y, z, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun rigidFunc4D(crossinline noise: (Int, Double, Double, Double, Double) -> Double, octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): (Int, Double, Double, Double, Double) -> Double {
|
||||
return { seed, x, y, z, w ->
|
||||
rigid(seed, x, y, z, w, noise, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
42
orx-noise/src/commonMain/kotlin/GaussianRandom.kt
Normal file
42
orx-noise/src/commonMain/kotlin/GaussianRandom.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.log
|
||||
import kotlin.math.sqrt
|
||||
import kotlin.random.Random
|
||||
|
||||
fun gaussian(mean: Double = 0.0, deviation: Double = 1.0, random: Random = Random.Default): Double {
|
||||
var v1: Double
|
||||
var v2: Double
|
||||
var s: Double
|
||||
do {
|
||||
v1 = 2 * random.nextDouble() - 1
|
||||
v2 = 2 * random.nextDouble() - 1
|
||||
s = v1 * v1 + v2 * v2
|
||||
} while (s >= 1 || s == 0.0)
|
||||
val multiplier = sqrt(-2 * ln(s) / s)
|
||||
|
||||
return v1 * multiplier * deviation + mean
|
||||
}
|
||||
|
||||
fun Double.Companion.gaussian(
|
||||
mean: Double = 0.0,
|
||||
deviation: Double = 1.0,
|
||||
random: Random = Random.Default
|
||||
): Double = org.openrndr.extra.noise.gaussian(mean, deviation, random)
|
||||
|
||||
fun Vector2.Companion.gaussian(mean: Vector2 = Vector2.ZERO, deviation: Vector2 = Vector2.ONE, random: Random = Random.Default): Vector2 {
|
||||
return Vector2(gaussian(mean.x, deviation.x, random), gaussian(mean.y, deviation.y, random))
|
||||
}
|
||||
|
||||
fun Vector3.Companion.gaussian(mean: Vector3 = Vector3.ZERO, deviation: Vector3 = Vector3.ONE, random: Random = Random.Default): Vector3 {
|
||||
return Vector3(gaussian(mean.x, deviation.x, random), gaussian(mean.y, deviation.y, random), gaussian(mean.z, deviation.z, random))
|
||||
}
|
||||
|
||||
fun Vector4.Companion.gaussian(mean: Vector4 = Vector4.ZERO, deviation: Vector4 = Vector4.ONE, random: Random = Random.Default): Vector4 {
|
||||
return Vector4(gaussian(mean.x, deviation.x, random), gaussian(mean.y, deviation.y, random), gaussian(mean.z, deviation.z, random), gaussian(mean.w, deviation.w, random))
|
||||
}
|
||||
|
||||
157
orx-noise/src/commonMain/kotlin/GradCoord.kt
Normal file
157
orx-noise/src/commonMain/kotlin/GradCoord.kt
Normal file
File diff suppressed because one or more lines are too long
72
orx-noise/src/commonMain/kotlin/Gradient.kt
Normal file
72
orx-noise/src/commonMain/kotlin/Gradient.kt
Normal file
@@ -0,0 +1,72 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
|
||||
inline fun gradient1D(
|
||||
crossinline noise: (seed: Int, x: Double) -> Double,
|
||||
seed: Int,
|
||||
x: Double,
|
||||
epsilon: Double = 0.01
|
||||
): Double {
|
||||
val xn = noise(seed, x - epsilon)
|
||||
val xp = noise(seed, x + epsilon)
|
||||
return (xp - xn) / (2.0 * epsilon)
|
||||
}
|
||||
|
||||
inline fun gradient2D(
|
||||
crossinline noise: (seed: Int, x: Double, y: Double) -> Double,
|
||||
seed: Int,
|
||||
x: Double,
|
||||
y: Double,
|
||||
epsilon: Double = 0.01
|
||||
): Vector2 {
|
||||
val xn = noise(seed, x - epsilon, y)
|
||||
val xp = noise(seed, x + epsilon, y)
|
||||
val yn = noise(seed, x, y - epsilon)
|
||||
val yp = noise(seed, x, y + epsilon)
|
||||
return Vector2((xp - xn) / (2.0 * epsilon), (yp - yn) / (2.0 * epsilon))
|
||||
}
|
||||
|
||||
inline fun gradient3D(
|
||||
crossinline noise: (seed: Int, x: Double, y: Double, z: Double) -> Double,
|
||||
seed: Int,
|
||||
x: Double,
|
||||
y: Double,
|
||||
z: Double,
|
||||
epsilon: Double = 0.01
|
||||
): Vector3 {
|
||||
val xn = noise(seed, x - epsilon, y, z)
|
||||
val xp = noise(seed, x + epsilon, y, z)
|
||||
val yn = noise(seed, x, y - epsilon, z)
|
||||
val yp = noise(seed, x, y + epsilon, z)
|
||||
val zn = noise(seed, x, y, z - epsilon)
|
||||
val zp = noise(seed, x, y, z + epsilon)
|
||||
return Vector3((xp - xn) / (2.0 * epsilon), (yp - yn) / (2.0 * epsilon), (zp - zn) / (2.0 * epsilon))
|
||||
}
|
||||
|
||||
inline fun gradient4D(
|
||||
crossinline noise: (seed: Int, x: Double, y: Double, z: Double, w: Double) -> Double,
|
||||
seed: Int,
|
||||
x: Double,
|
||||
y: Double,
|
||||
z: Double,
|
||||
w: Double,
|
||||
epsilon: Double = 0.01
|
||||
): Vector4 {
|
||||
val xn = noise(seed, x - epsilon, y, z, w)
|
||||
val xp = noise(seed, x + epsilon, y, z, w)
|
||||
val yn = noise(seed, x, y - epsilon, z, w)
|
||||
val yp = noise(seed, x, y + epsilon, z, w)
|
||||
val zn = noise(seed, x, y, z - epsilon, w)
|
||||
val zp = noise(seed, x, y, z + epsilon, w)
|
||||
val wn = noise(seed, x, y, z, w - epsilon)
|
||||
val wp = noise(seed, x, y, z, w + epsilon)
|
||||
return Vector4(
|
||||
(xp - xn) / (2.0 * epsilon),
|
||||
(yp - yn) / (2.0 * epsilon),
|
||||
(zp - zn) / (2.0 * epsilon),
|
||||
(wp - wn) / (2.0 * epsilon)
|
||||
)
|
||||
}
|
||||
126
orx-noise/src/commonMain/kotlin/GradientPerturb.kt
Normal file
126
orx-noise/src/commonMain/kotlin/GradientPerturb.kt
Normal file
@@ -0,0 +1,126 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector3, interpolator: (Double) -> Double = ::quintic): Vector3 {
|
||||
|
||||
var seed_ = seed
|
||||
var amplitude_ = amplitude
|
||||
var frequency_ = frequency
|
||||
|
||||
var p = gradientPerturb(seed_, amplitude_, frequency_, position, interpolator)
|
||||
for (i in 0 until octaves) {
|
||||
frequency_ *= lacunarity
|
||||
amplitude_ *= gain
|
||||
seed_++
|
||||
p = gradientPerturb(seed_, amplitude_, frequency_, p, interpolator)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: Vector3, interpolator: (Double) -> Double = ::quintic): Vector3 {
|
||||
val xf = position.x * frequency
|
||||
val yf = position.y * frequency
|
||||
val zf = position.z * frequency
|
||||
|
||||
val x0 = xf.fastFloor()
|
||||
val y0 = yf.fastFloor()
|
||||
val z0 = zf.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
val z1 = z0 + 1
|
||||
|
||||
val xs = interpolator(xf - x0)
|
||||
val ys = interpolator(yf - y0)
|
||||
val zs = interpolator(zf - z0)
|
||||
|
||||
var vec0 = Cell3D[hash3D(seed, x0, y0, z0) and 0xff]
|
||||
var vec1 = Cell3D[hash3D(seed, x1, y0, z0) and 0xff]
|
||||
|
||||
var lx0x = mix(vec0.x, vec1.x, xs)
|
||||
var ly0x = mix(vec0.y, vec1.y, xs)
|
||||
var lz0x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y1, z0) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y1, z0) and 0xff]
|
||||
|
||||
var lx1x = mix(vec0.x, vec1.x, xs)
|
||||
var ly1x = mix(vec0.y, vec1.y, xs)
|
||||
var lz1x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
val lx0y = mix(lx0x, lx1x, ys)
|
||||
val ly0y = mix(ly0x, ly1x, ys)
|
||||
val lz0y = mix(lz0x, lz1x, ys)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y0, z1) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y0, z1) and 0xff]
|
||||
|
||||
lx0x = mix(vec0.x, vec1.x, xs)
|
||||
ly0x = mix(vec0.y, vec1.y, xs)
|
||||
lz0x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
vec0 = Cell3D[hash3D(seed, x0, y1, z1) and 0xff]
|
||||
vec1 = Cell3D[hash3D(seed, x1, y1, z1) and 0xff]
|
||||
|
||||
lx1x = mix(vec0.x, vec1.x, xs)
|
||||
ly1x = mix(vec0.y, vec1.y, xs)
|
||||
lz1x = mix(vec0.z, vec1.z, xs)
|
||||
|
||||
return position + Vector3(
|
||||
mix(lx0y, mix(lx0x, lx1x, ys), zs),
|
||||
mix(ly0y, mix(ly0x, ly1x, ys), zs),
|
||||
mix(lz0y, mix(lz0x, lz1x, ys), zs)
|
||||
) * amplitude
|
||||
}
|
||||
|
||||
fun gradientPerturbFractal(seed: Int, amplitude: Double = 1.0, frequency: Double = 2.0,
|
||||
lacunarity: Double = 2.0, gain: Double = 0.5,
|
||||
octaves: Int = 4, position: Vector2, interpolator: (Double) -> Double = ::quintic): Vector2 {
|
||||
|
||||
var seed_ = seed
|
||||
var amplitude_ = amplitude
|
||||
var frequency_ = frequency
|
||||
|
||||
var p = gradientPerturb(seed_, amplitude_, frequency_, position, interpolator)
|
||||
for (i in 0 until octaves) {
|
||||
frequency_ *= lacunarity
|
||||
amplitude_ *= gain
|
||||
seed_++
|
||||
p = gradientPerturb(seed_, amplitude_, frequency_, p, interpolator)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
fun gradientPerturb(seed: Int, amplitude: Double, frequency: Double, position: Vector2, interpolator: (Double) -> Double = ::quintic): Vector2 {
|
||||
val xf = position.x * frequency
|
||||
val yf = position.y * frequency
|
||||
val x0 = xf.fastFloor()
|
||||
val y0 = yf.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
|
||||
val xs = interpolator(xf - x0)
|
||||
val ys = interpolator(yf - y0)
|
||||
|
||||
var vec0 = Cell2D[hash2D(seed, x0, y0) and 0xff]
|
||||
var vec1 = Cell2D[hash2D(seed, x1, y0) and 0xff]
|
||||
|
||||
val lx0x = mix(vec0.x, vec1.x, xs)
|
||||
val ly0x = mix(vec0.y, vec1.y, xs)
|
||||
|
||||
vec0 = Cell2D[hash2D(seed, x0, y1) and 0xff]
|
||||
vec1 = Cell2D[hash2D(seed, x1, y1) and 0xff]
|
||||
|
||||
val lx1x = mix(vec0.x, vec1.x, xs)
|
||||
val ly1x = mix(vec0.y, vec1.y, xs)
|
||||
|
||||
return position + Vector2(
|
||||
mix(lx0x, lx1x, ys),
|
||||
mix(ly0x, ly1x, ys)
|
||||
) * amplitude
|
||||
|
||||
}
|
||||
18
orx-noise/src/commonMain/kotlin/Interpolation.kt
Normal file
18
orx-noise/src/commonMain/kotlin/Interpolation.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
fun hermite(t: Double): Double {
|
||||
return t * t * (3 - 2 * t)
|
||||
}
|
||||
|
||||
fun quintic(t: Double): Double {
|
||||
return t * t * t * (t * (t * 6 - 15) + 10)
|
||||
}
|
||||
|
||||
fun cubic(a: Double, b: Double, c: Double, d: Double, t: Double): Double {
|
||||
val p = d - c - (a - b)
|
||||
return t * t * t * p + t * t * (a - b - p) + t * (c - a) + b
|
||||
}
|
||||
|
||||
fun linear(x: Double): Double {
|
||||
return x
|
||||
}
|
||||
6
orx-noise/src/commonMain/kotlin/MathUtils.kt
Normal file
6
orx-noise/src/commonMain/kotlin/MathUtils.kt
Normal file
@@ -0,0 +1,6 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
|
||||
fun Double.fastFloor(): Int {
|
||||
return if (this >= 0) this.toInt() else this.toInt() - 1
|
||||
}
|
||||
9
orx-noise/src/commonMain/kotlin/PerlinNoise1D.kt
Normal file
9
orx-noise/src/commonMain/kotlin/PerlinNoise1D.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
fun perlin(seed: Int, x: Double) = perlin(seed, x, ::linear)
|
||||
fun perlinLinear(seed: Int, x: Double) = perlin(seed, x, ::linear)
|
||||
fun perlinQuintic(seed: Int, x: Double) = perlin(seed, x, ::quintic)
|
||||
fun perlinHermite(seed: Int, x: Double) = perlin(seed, x, ::hermite)
|
||||
|
||||
inline fun perlin(seed: Int, x: Double, crossinline interpolator: (Double) -> Double): Double =
|
||||
perlin(seed, x, 0.0, interpolator)
|
||||
34
orx-noise/src/commonMain/kotlin/PerlinNoise2D.kt
Normal file
34
orx-noise/src/commonMain/kotlin/PerlinNoise2D.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun perlin(seed: Int, x: Double, y: Double) = perlin(seed, x, y, ::linear)
|
||||
fun perlinLinear(seed: Int, x: Double, y: Double) = perlin(seed, x, y, ::linear)
|
||||
fun perlinQuintic(seed: Int, x: Double, y: Double) = perlin(seed, x, y, ::quintic)
|
||||
fun perlinHermite(seed: Int, x: Double, y: Double) = perlin(seed, x, y, ::hermite)
|
||||
|
||||
fun perlin(seed: Int, position: Vector2) = perlin(seed, position.x, position.y, ::linear)
|
||||
fun perlinLinear(seed: Int, position: Vector2) = perlin(seed, position.x, position.y, ::linear)
|
||||
fun perlinQuintic(seed: Int, position: Vector2) = perlin(seed, position.x, position.y, ::quintic)
|
||||
fun perlinHermite(seed: Int, position: Vector2) = perlin(seed, position.x, position.y, ::hermite)
|
||||
|
||||
inline fun perlin(seed: Int, x: Double, y: Double, crossinline interpolator: (Double) -> Double): Double {
|
||||
val x0 = x.fastFloor()
|
||||
val y0 = y.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
|
||||
val xs = interpolator(x - x0)
|
||||
val ys = interpolator(y - y0)
|
||||
|
||||
val xd0 = x - x0
|
||||
val yd0 = y - y0
|
||||
val xd1 = xd0 - 1
|
||||
val yd1 = yd0 - 1
|
||||
|
||||
val xf0 = mix(gradCoord2D(seed, x0, y0, xd0, yd0), gradCoord2D(seed, x1, y0, xd1, yd0), xs)
|
||||
val xf1 = mix(gradCoord2D(seed, x0, y1, xd0, yd1), gradCoord2D(seed, x1, y1, xd1, yd1), xs)
|
||||
|
||||
return mix(xf0, xf1, ys)
|
||||
}
|
||||
42
orx-noise/src/commonMain/kotlin/PerlinNoise3D.kt
Normal file
42
orx-noise/src/commonMain/kotlin/PerlinNoise3D.kt
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun perlinLinear(seed: Int, x: Double, y: Double, z: Double) = perlin(seed, x, y, z, ::linear)
|
||||
fun perlinQuintic(seed: Int, x: Double, y: Double, z: Double) = perlin(seed, x, y, z, ::quintic)
|
||||
fun perlinHermite(seed: Int, x: Double, y: Double, z: Double) = perlin(seed, x, y, z, ::hermite)
|
||||
|
||||
fun perlinLinear(seed: Int, position: Vector3) = perlin(seed, position.x, position.y, position.z, ::linear)
|
||||
fun perlinQuintic(seed: Int, position: Vector3) = perlin(seed, position.x, position.y, position.z, ::quintic)
|
||||
fun perlinHermite(seed: Int, position: Vector3) = perlin(seed, position.x, position.y, position.z, ::hermite)
|
||||
|
||||
inline fun perlin(seed: Int, x: Double, y: Double, z: Double, crossinline interpolator: (Double) -> Double = ::linear): Double {
|
||||
val x0 = x.fastFloor()
|
||||
val y0 = y.fastFloor()
|
||||
val z0 = z.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
val z1 = z0 + 1
|
||||
|
||||
val xs: Double = interpolator(x - x0)
|
||||
val ys: Double = interpolator(y - y0)
|
||||
val zs: Double = interpolator(z - z0)
|
||||
|
||||
val xd0 = x - x0
|
||||
val yd0 = y - y0
|
||||
val zd0 = z - z0
|
||||
val xd1 = xd0 - 1
|
||||
val yd1 = yd0 - 1
|
||||
val zd1 = zd0 - 1
|
||||
|
||||
val xf00 = mix(gradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), gradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs)
|
||||
val xf10 = mix(gradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), gradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs)
|
||||
val xf01 = mix(gradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), gradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs)
|
||||
val xf11 = mix(gradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), gradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs)
|
||||
|
||||
val yf0 = mix(xf00, xf10, ys)
|
||||
val yf1 = mix(xf01, xf11, ys)
|
||||
|
||||
return mix(yf0, yf1, zs)
|
||||
}
|
||||
121
orx-noise/src/commonMain/kotlin/PoissonDisk.kt
Normal file
121
orx-noise/src/commonMain/kotlin/PoissonDisk.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Polar
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.clamp
|
||||
import org.openrndr.shape.Rectangle
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.sqrt
|
||||
|
||||
/*
|
||||
* TODO v2
|
||||
* * Generalize to 3 dimensions
|
||||
*/
|
||||
|
||||
internal const val epsilon = 0.0000001
|
||||
|
||||
/**
|
||||
* Creates a random point distribution on a given area
|
||||
* Each point gets n [tries] at generating the next point
|
||||
* By default the points are generated along the circumference of r + epsilon to the point
|
||||
* They can also be generated on a ring like in the original algorithm from Robert Bridson
|
||||
*
|
||||
* @param width the width of the area
|
||||
* @param height the height of the area
|
||||
* @param r the minimum distance between each point
|
||||
* @param tries number of candidates per point
|
||||
* @param boundsMapper a custom function to check if a point is within bounds
|
||||
* @param randomOnRing generate random points on a ring with an annulus from r to 2r
|
||||
* @return a list of points
|
||||
*/
|
||||
fun poissonDiskSampling(
|
||||
width: Double,
|
||||
height: Double,
|
||||
r: Double,
|
||||
tries: Int = 30,
|
||||
randomOnRing: Boolean = false,
|
||||
boundsMapper: ((w: Double, h: Double, v: Vector2) -> Boolean)? = null
|
||||
): List<Vector2> {
|
||||
val disk = mutableListOf<Vector2>()
|
||||
val queue = mutableListOf<Int>()
|
||||
|
||||
val r2 = r * r
|
||||
val radius = r + epsilon
|
||||
|
||||
val cellSize = r / sqrt(2.0)
|
||||
val rows = ceil(height / cellSize).toInt()
|
||||
val cols = ceil(width / cellSize).toInt()
|
||||
|
||||
val grid = List(rows * cols) { -1 }.toMutableList()
|
||||
|
||||
fun addPoint(v: Vector2) {
|
||||
val x = (v.x / cellSize).fastFloor()
|
||||
val y = (v.y / cellSize).fastFloor()
|
||||
val index = x + y * cols
|
||||
|
||||
disk.add(v)
|
||||
|
||||
grid[index] = disk.lastIndex
|
||||
|
||||
queue.add(disk.lastIndex)
|
||||
}
|
||||
|
||||
addPoint(Vector2(width / 2.0, height / 2.0))
|
||||
|
||||
val boundsRect = Rectangle(0.0, 0.0, width, height)
|
||||
|
||||
while (queue.isNotEmpty()) {
|
||||
val activeIndex = Random.pick(queue)
|
||||
val active = disk[activeIndex]
|
||||
|
||||
var candidateAccepted = false
|
||||
|
||||
candidateSearch@ for (l in 0 until tries) {
|
||||
val c = if (randomOnRing) {
|
||||
active + Random.ring2d(r, 2 * r) as Vector2
|
||||
} else {
|
||||
active + Polar(Random.double0(360.0), radius).cartesian
|
||||
}
|
||||
|
||||
if (!boundsRect.contains(c)) continue@candidateSearch
|
||||
|
||||
// check if it's within bounds
|
||||
// choose another candidate if it's not
|
||||
if (boundsMapper != null && !boundsMapper(width, height, c)) continue@candidateSearch
|
||||
|
||||
val x = (c.x / cellSize).fastFloor()
|
||||
val y = (c.y / cellSize).fastFloor()
|
||||
|
||||
// Check closest neighbours in a 5x5 grid
|
||||
for (ix in (-2..2)) {
|
||||
for (iy in (-2..2)) {
|
||||
val nx = clamp(x + ix, 0, cols - 1)
|
||||
val ny = clamp(y + iy, 0, rows - 1)
|
||||
|
||||
val neighborIdx = grid[nx + ny * cols]
|
||||
|
||||
// -1 means the grid has no sample at that point
|
||||
if (neighborIdx == -1) continue
|
||||
|
||||
val neighbor = disk[neighborIdx]
|
||||
|
||||
// if the candidate is within one of the neighbours radius, try another candidate
|
||||
if ((neighbor - c).squaredLength <= r2) continue@candidateSearch
|
||||
}
|
||||
}
|
||||
|
||||
addPoint(c)
|
||||
|
||||
candidateAccepted = true
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
// If no candidate was accepted, remove the sample from the active list
|
||||
if (!candidateAccepted) {
|
||||
queue.remove(activeIndex)
|
||||
}
|
||||
}
|
||||
|
||||
return disk
|
||||
}
|
||||
387
orx-noise/src/commonMain/kotlin/Random.kt
Normal file
387
orx-noise/src/commonMain/kotlin/Random.kt
Normal file
@@ -0,0 +1,387 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import org.openrndr.shape.Rectangle
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.max
|
||||
import kotlin.math.pow
|
||||
import kotlin.math.sqrt
|
||||
import org.openrndr.extra.noise.fbm as orxFbm
|
||||
import kotlin.random.Random as DefaultRandom
|
||||
|
||||
private data class RandomState(var seed: String, var rng: DefaultRandom)
|
||||
/**
|
||||
* Deterministic Random using a seed to guarantee the same random values between iterations
|
||||
*/
|
||||
object Random {
|
||||
var rnd: DefaultRandom
|
||||
|
||||
private var seedTracking: Int = 0
|
||||
private var nextGaussian: Double = 0.0
|
||||
private var hasNextGaussian = false
|
||||
|
||||
private var state: RandomState
|
||||
|
||||
enum class Fractal {
|
||||
FBM, BILLOW, RIGID
|
||||
}
|
||||
|
||||
enum class Noise {
|
||||
LINEAR, QUINTIC, HERMIT
|
||||
}
|
||||
|
||||
var seed: String = "OPENRNDR"
|
||||
set(value) {
|
||||
field = value
|
||||
rnd = newRandomGenerator(value)
|
||||
}
|
||||
|
||||
init {
|
||||
rnd = newRandomGenerator(seed)
|
||||
|
||||
state = RandomState(seed, rnd)
|
||||
}
|
||||
|
||||
private fun newRandomGenerator(newSeed: String): DefaultRandom {
|
||||
return DefaultRandom(stringToInt(newSeed))
|
||||
}
|
||||
|
||||
private fun stringToInt(str: String): Int = str.toCharArray().fold(0) { i: Int, c: Char ->
|
||||
i + c.toInt()
|
||||
}
|
||||
|
||||
fun resetState() {
|
||||
rnd = newRandomGenerator(seed)
|
||||
}
|
||||
|
||||
fun randomizeSeed() {
|
||||
val seedBase = seed.replace(Regex("""-\d+"""), "")
|
||||
seedTracking = int0(999999)
|
||||
seed = "${seedBase}-${seedTracking}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this when you want to get non-deterministic values aka random every call
|
||||
*
|
||||
* @param fn
|
||||
*/
|
||||
fun unseeded(fn: () -> Unit) {
|
||||
push()
|
||||
|
||||
fn()
|
||||
|
||||
pop()
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this when you want to get non-deterministic values aka random every call
|
||||
* Follow it by calling .pop
|
||||
*/
|
||||
fun push() {
|
||||
state = RandomState(seed, rnd)
|
||||
|
||||
rnd = DefaultRandom
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to go back to seeded state
|
||||
*/
|
||||
fun pop() {
|
||||
resetState()
|
||||
|
||||
seed = state.seed
|
||||
rnd = state.rng
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this inside `extend` methods to get the same result between iterations
|
||||
*
|
||||
* @param fn
|
||||
*/
|
||||
fun isolated(fn: Random.() -> Unit) {
|
||||
val state = rnd
|
||||
val currentSeed = seed
|
||||
|
||||
resetState()
|
||||
|
||||
this.fn()
|
||||
|
||||
seed = currentSeed
|
||||
rnd = state
|
||||
}
|
||||
|
||||
fun double(min: Double = -1.0, max: Double = 1.0): Double {
|
||||
return Double.uniform(min, max, rnd)
|
||||
}
|
||||
|
||||
fun double0(max: Double = 1.0): Double {
|
||||
return rnd.nextDouble(max)
|
||||
}
|
||||
|
||||
fun int0(max: Int = Int.MAX_VALUE): Int {
|
||||
return rnd.nextInt(max)
|
||||
}
|
||||
|
||||
fun int(min: Int = 0, max: Int = Int.MAX_VALUE): Int {
|
||||
return rnd.nextInt(min, max)
|
||||
}
|
||||
|
||||
fun bool(probability: Double = 0.5): Boolean {
|
||||
return rnd.nextDouble(1.0) < probability
|
||||
}
|
||||
|
||||
fun <T> pick(coll: Collection<T>): T {
|
||||
return pick(coll, count = 1).first()
|
||||
}
|
||||
|
||||
fun <T> pick(coll: Collection<T>, compareAgainst: Collection<T>): T {
|
||||
return pick(coll, compareAgainst, 1).first()
|
||||
}
|
||||
|
||||
fun <T> pick(coll: Collection<T>, compareAgainst: Collection<T> = listOf(), count: Int): MutableList<T> {
|
||||
var list = coll.toMutableList()
|
||||
val picked = mutableListOf<T>()
|
||||
|
||||
if (coll.isEmpty()) return list
|
||||
|
||||
while (picked.size < count) {
|
||||
if (list.isEmpty()) {
|
||||
list = coll.toMutableList()
|
||||
}
|
||||
|
||||
var index = int0(list.size)
|
||||
var newElem = list.elementAt(index)
|
||||
|
||||
while (compareAgainst.contains(newElem)) {
|
||||
index = int0(list.size)
|
||||
newElem = list.elementAt(index)
|
||||
}
|
||||
|
||||
picked.add(list[index])
|
||||
list.removeAt(index)
|
||||
}
|
||||
|
||||
return picked
|
||||
}
|
||||
|
||||
fun gaussian(mean: Double = 0.0, standardDeviation: Double = 1.0): Double {
|
||||
return gaussian(mean, standardDeviation, rnd)
|
||||
}
|
||||
|
||||
/**
|
||||
* https://en.wikipedia.org/wiki/Pareto_distribution
|
||||
*/
|
||||
fun pareto(alpha: Double = 1.0): () -> Double {
|
||||
val invAlpha = 1.0 / max(alpha, 0.0)
|
||||
|
||||
return {
|
||||
1.0 / (1.0 - double0()).pow(invAlpha)
|
||||
}
|
||||
}
|
||||
|
||||
fun vector2(min: Double = -1.0, max: Double = 1.0): Vector2 {
|
||||
return Vector2.uniform(min, max, rnd)
|
||||
}
|
||||
|
||||
fun vector3(min: Double = -1.0, max: Double = 1.0): Vector3 {
|
||||
return Vector3.uniform(min, max, rnd)
|
||||
}
|
||||
|
||||
fun vector4(min: Double = -1.0, max: Double = 1.0): Vector4 {
|
||||
return Vector4.uniform(min, max, rnd)
|
||||
}
|
||||
|
||||
fun perlin(x: Double, y: Double, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> perlinLinear(sd, x, y)
|
||||
Noise.QUINTIC -> perlinQuintic(sd, x, y)
|
||||
Noise.HERMIT -> perlinHermite(sd, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun perlin(position: Vector2, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> perlinLinear(sd, position)
|
||||
Noise.QUINTIC -> perlinQuintic(sd, position)
|
||||
Noise.HERMIT -> perlinHermite(sd, position)
|
||||
}
|
||||
}
|
||||
|
||||
fun perlin(x: Double, y: Double, z: Double, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> perlinLinear(sd, x, y, z)
|
||||
Noise.QUINTIC -> perlinQuintic(sd, x, y, z)
|
||||
Noise.HERMIT -> perlinHermite(sd, x, y, z)
|
||||
}
|
||||
}
|
||||
|
||||
fun perlin(position: Vector3, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> perlinLinear(sd, position)
|
||||
Noise.QUINTIC -> perlinQuintic(sd, position)
|
||||
Noise.HERMIT -> perlinHermite(sd, position)
|
||||
}
|
||||
}
|
||||
|
||||
fun value(x: Double, y: Double, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> valueLinear(sd, x, y)
|
||||
Noise.QUINTIC -> valueQuintic(sd, x, y)
|
||||
Noise.HERMIT -> valueHermite(sd, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
fun value(position: Vector2, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> valueLinear(sd, position)
|
||||
Noise.QUINTIC -> valueQuintic(sd, position)
|
||||
Noise.HERMIT -> valueHermite(sd, position)
|
||||
}
|
||||
}
|
||||
|
||||
fun value(x: Double, y: Double, z: Double, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> valueLinear(sd, x, y, z)
|
||||
Noise.QUINTIC -> valueQuintic(sd, x, y, z)
|
||||
Noise.HERMIT -> valueHermite(sd, x, y, z)
|
||||
}
|
||||
}
|
||||
|
||||
fun value(position: Vector3, type: Noise = Noise.LINEAR): Double {
|
||||
val sd = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Noise.LINEAR -> valueLinear(sd, position)
|
||||
Noise.QUINTIC -> valueQuintic(sd, position)
|
||||
Noise.HERMIT -> valueHermite(sd, position)
|
||||
}
|
||||
}
|
||||
|
||||
fun simplex(x: Double, y: Double): Double {
|
||||
return simplex(stringToInt(seed), x, y)
|
||||
}
|
||||
|
||||
fun simplex(position: Vector2): Double {
|
||||
return simplex(stringToInt(seed), position)
|
||||
}
|
||||
|
||||
fun simplex(x: Double, y: Double, z: Double): Double {
|
||||
return simplex(stringToInt(seed), x, y, z)
|
||||
}
|
||||
|
||||
fun simplex(position: Vector3): Double {
|
||||
return simplex(stringToInt(seed), position)
|
||||
}
|
||||
|
||||
fun simplex(x: Double, y: Double, z: Double, w: Double): Double {
|
||||
return simplex(stringToInt(seed), x, y, z, w)
|
||||
}
|
||||
|
||||
fun simplex(position: Vector4): Double {
|
||||
return simplex(stringToInt(seed), position)
|
||||
}
|
||||
|
||||
fun fbm(x: Double, y: Double, noiseFun: (Int, Double, Double) -> Double, type: Fractal = Fractal.FBM,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
val s = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Fractal.FBM -> orxFbm(s, x, y, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.RIGID -> rigid(s, x, y, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.BILLOW -> billow(s, x, y, noiseFun, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
fun fbm(position: Vector2, noiseFun: (Int, Double, Double) -> Double,
|
||||
type: Fractal = Fractal.FBM,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
val s = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Fractal.FBM -> orxFbm(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.RIGID -> rigid(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.BILLOW -> billow(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
fun fbm(x: Double, y: Double, z: Double, noiseFun: (Int, Double, Double, Double) -> Double, type: Fractal = Fractal.FBM,
|
||||
octaves: Int = 8, lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
val s = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Fractal.FBM -> orxFbm(s, x, y, z, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.RIGID -> rigid(s, x, y, z, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.BILLOW -> billow(s, x, y, z, noiseFun, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
fun fbm(position: Vector3, noiseFun: (Int, Double, Double, Double) -> Double,
|
||||
type: Fractal = Fractal.FBM, octaves: Int = 8,
|
||||
lacunarity: Double = 0.5, gain: Double = 0.5): Double {
|
||||
val s = stringToInt(seed)
|
||||
|
||||
return when (type) {
|
||||
Fractal.FBM -> orxFbm(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.RIGID -> rigid(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
Fractal.BILLOW -> billow(s, position, noiseFun, octaves, lacunarity, gain)
|
||||
}
|
||||
}
|
||||
|
||||
fun cubic(x: Double, y: Double): Double {
|
||||
return cubic(stringToInt(seed), x, y)
|
||||
}
|
||||
|
||||
fun cubic(position: Vector2): Double {
|
||||
return cubic(stringToInt(seed), position)
|
||||
}
|
||||
|
||||
fun cubic(x: Double, y: Double, z: Double): Double {
|
||||
return cubic(stringToInt(seed), x, y, z)
|
||||
}
|
||||
|
||||
fun cubic(position: Vector3):Double {
|
||||
return cubic(stringToInt(seed), position)
|
||||
}
|
||||
|
||||
fun ring2d(innerRadius: Double = 0.0, outerRadius: Double = 1.0, count: Int = 1): Any {
|
||||
return when (count) {
|
||||
1 -> Vector2.uniformRing(innerRadius, outerRadius, rnd)
|
||||
else -> Vector2.uniformsRing(count, innerRadius, outerRadius, rnd)
|
||||
}
|
||||
}
|
||||
|
||||
fun ring3d(innerRadius: Double = 0.0, outerRadius: Double = 1.0, count: Int = 1): Any {
|
||||
return when (count) {
|
||||
1 -> Vector3.uniformRing(innerRadius, outerRadius, rnd)
|
||||
else -> Vector3.uniformsRing(count, innerRadius, outerRadius, rnd)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> roll(elements: Collection<T>, distribution: (Int) -> List<Double>): T {
|
||||
val result = double0()
|
||||
val probabilities = distribution(elements.size)
|
||||
val index = probabilities.indexOfFirst { result <= it }
|
||||
|
||||
return elements.elementAtOrNull(index) ?: elements.last()
|
||||
}
|
||||
|
||||
fun point(rect: Rectangle): Vector2 {
|
||||
return rect.position(vector2(0.0, 1.0))
|
||||
}
|
||||
}
|
||||
3
orx-noise/src/commonMain/kotlin/SimplexNoise1D.kt
Normal file
3
orx-noise/src/commonMain/kotlin/SimplexNoise1D.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
fun simplex(seed: Int, x: Double): Double = simplex(seed, x, 0.0)
|
||||
67
orx-noise/src/commonMain/kotlin/SimplexNoise2D.kt
Normal file
67
orx-noise/src/commonMain/kotlin/SimplexNoise2D.kt
Normal file
@@ -0,0 +1,67 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
private const val SQRT3 = 1.7320508075688772935274463415059
|
||||
private const val F2 = 0.5 * (SQRT3 - 1.0)
|
||||
private const val G2 = (3.0 - SQRT3) / 6.0
|
||||
|
||||
fun simplex(seed: Int, position: Vector2): Double = simplex(seed, position.x, position.y)
|
||||
|
||||
fun simplex(seed: Int, x: Double, y: Double): Double {
|
||||
var t = (x + y) * F2
|
||||
val i = (x + t).fastFloor()
|
||||
val j = (y + t).fastFloor()
|
||||
|
||||
t = ((i + j) * G2)
|
||||
val x0 = x - (i - t)
|
||||
val y0 = y - (j - t)
|
||||
|
||||
val i1: Int
|
||||
val j1: Int
|
||||
if (x0 > y0) {
|
||||
i1 = 1
|
||||
j1 = 0
|
||||
} else {
|
||||
i1 = 0
|
||||
j1 = 1
|
||||
}
|
||||
|
||||
val x1 = (x0 - i1 + G2)
|
||||
val y1 = (y0 - j1 + G2)
|
||||
val x2 = (x0 - 1 + 2 * G2)
|
||||
val y2 = (y0 - 1 + 2 * G2)
|
||||
|
||||
val n0: Double
|
||||
val n1: Double
|
||||
val n2: Double
|
||||
|
||||
t = 0.5 - x0 * x0 - y0 * y0
|
||||
if (t < 0)
|
||||
n0 = 0.0
|
||||
else {
|
||||
t *= t
|
||||
n0 = t * t * gradCoord2D(seed, i, j, x0, y0)
|
||||
}
|
||||
|
||||
t = 0.5 - x1 * x1 - y1 * y1
|
||||
if (t < 0)
|
||||
n1 = 0.0
|
||||
else {
|
||||
t *= t
|
||||
n1 = t * t * gradCoord2D(seed, i + i1, j + j1, x1, y1)
|
||||
}
|
||||
|
||||
t = 0.5 - x2 * x2 - y2 * y2
|
||||
if (t < 0)
|
||||
n2 = 0.0
|
||||
else {
|
||||
t *= t
|
||||
n2 = t * t * gradCoord2D(seed, i + 1, j + 1, x2, y2)
|
||||
}
|
||||
|
||||
return 50.0 * (n0 + n1 + n2)
|
||||
}
|
||||
|
||||
fun Vector2.Companion.simplex(seed: Int, x: Double): Vector2 = Vector2(simplex(seed, x, 0.0, 0.0, 0.0),
|
||||
simplex(seed, 0.0, x + 31.3383, 0.0, 0.0))
|
||||
106
orx-noise/src/commonMain/kotlin/SimplexNoise3D.kt
Normal file
106
orx-noise/src/commonMain/kotlin/SimplexNoise3D.kt
Normal file
@@ -0,0 +1,106 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector3
|
||||
|
||||
private const val F3 = (1.0 / 3.0).toFloat()
|
||||
private const val G3 = (1.0 / 6.0).toFloat()
|
||||
private const val G33 = G3 * 3 - 1
|
||||
|
||||
fun simplex(seed: Int, position: Vector3): Double = simplex(seed, position.x, position.y, position.z)
|
||||
|
||||
fun simplex(seed: Int, x: Double, y: Double, z: Double): Double {
|
||||
|
||||
val t = (x + y + z) / 3.0
|
||||
val i = (x + t).fastFloor()
|
||||
val j = (y + t).fastFloor()
|
||||
val k = (z + t).fastFloor()
|
||||
|
||||
val t2 = (i + j + k) / 6.0
|
||||
val x0 = x - (i - t2)
|
||||
val y0 = y - (j - t2)
|
||||
val z0 = z - (k - t2)
|
||||
|
||||
val i1: Int
|
||||
val j1: Int
|
||||
val k1: Int
|
||||
|
||||
val i2: Int
|
||||
val j2: Int
|
||||
val k2: Int
|
||||
|
||||
if (x0 >= y0) {
|
||||
when {
|
||||
y0 >= z0 -> {
|
||||
i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; }
|
||||
x0 >= z0 -> {
|
||||
i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; }
|
||||
else -> {
|
||||
i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; }
|
||||
}
|
||||
} else {
|
||||
when {
|
||||
y0 < z0 -> {
|
||||
i1 = 0; j1 = 0; k1 = 1; i2 = 0; j2 = 1; k2 = 1; }
|
||||
x0 < z0 -> {
|
||||
i1 = 0; j1 = 1; k1 = 0; i2 = 0; j2 = 1; k2 = 1; }
|
||||
else -> {
|
||||
i1 = 0; j1 = 1; k1 = 0; i2 = 1; j2 = 1; k2 = 0; }
|
||||
}
|
||||
}
|
||||
val x1 = x0 - i1 + 1.0 / 6.0
|
||||
val y1 = y0 - j1 + 1.0 / 6.0
|
||||
val z1 = z0 - k1 + 1.0 / 6.0
|
||||
val x2 = x0 - i2 + 1.0 / 3.0
|
||||
val y2 = y0 - j2 + 1.0 / 3.0
|
||||
val z2 = z0 - k2 + 1.0 / 3.0
|
||||
val x3 = x0 + G33
|
||||
val y3 = y0 + G33
|
||||
val z3 = z0 + G33
|
||||
|
||||
val n0: Double
|
||||
run {
|
||||
var lt = 0.6 - x0 * x0 - y0 * y0 - z0 * z0
|
||||
if (lt < 0) {
|
||||
n0 = 0.0
|
||||
} else {
|
||||
lt *= lt
|
||||
n0 = lt * lt * gradCoord3D(seed, i, j, k, x0, y0, z0)
|
||||
}
|
||||
}
|
||||
val n1: Double
|
||||
run {
|
||||
var lt = 0.6 - x1 * x1 - y1 * y1 - z1 * z1
|
||||
if (lt < 0) {
|
||||
n1 = 0.0
|
||||
} else {
|
||||
lt *= lt
|
||||
n1 = lt * lt * gradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1)
|
||||
}
|
||||
}
|
||||
val n2: Double
|
||||
run {
|
||||
var lt = 0.6 - x2 * x2 - y2 * y2 - z2 * z2
|
||||
if (lt < 0) {
|
||||
n2 = 0.0
|
||||
} else {
|
||||
lt *= lt
|
||||
n2 = lt * lt * gradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2)
|
||||
}
|
||||
}
|
||||
|
||||
val n3: Double
|
||||
run {
|
||||
var lt = 0.6 - x3 * x3 - y3 * y3 - z3 * z3
|
||||
if (lt < 0)
|
||||
n3 = 0.0
|
||||
else {
|
||||
lt *= lt
|
||||
n3 = lt * lt * gradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3)
|
||||
}
|
||||
}
|
||||
return 32 * (n0 + n1 + n2 + n3)
|
||||
}
|
||||
|
||||
fun Vector3.Companion.simplex(seed: Int, x: Double): Vector3 = Vector3(simplex(seed, x, 0.0, 0.0),
|
||||
simplex(seed, 0.0, x + 31.3383, 0.0),
|
||||
simplex(seed, 0.0, 0.0, x - 483.23))
|
||||
114
orx-noise/src/commonMain/kotlin/SimplexNoise4D.kt
Normal file
114
orx-noise/src/commonMain/kotlin/SimplexNoise4D.kt
Normal file
@@ -0,0 +1,114 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector4
|
||||
|
||||
private val SIMPLEX_4D = byteArrayOf(
|
||||
0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0,
|
||||
0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0,
|
||||
1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0,
|
||||
2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0
|
||||
)
|
||||
|
||||
private const val F4 = ((2.23606797 - 1.0) / 4.0)
|
||||
private const val G4 = ((5.0 - 2.23606797) / 20.0)
|
||||
|
||||
fun simplex(seed: Int, position: Vector4) =
|
||||
simplex(seed, position.x, position.y, position.z, position.w)
|
||||
|
||||
fun simplex(seed: Int, x: Double, y: Double, z: Double, w: Double): Double {
|
||||
|
||||
var t = (x + y + z + w) * F4
|
||||
val i = (x + t).fastFloor()
|
||||
val j = (y + t).fastFloor()
|
||||
val k = (z + t).fastFloor()
|
||||
val l = (w + t).fastFloor()
|
||||
|
||||
val t2 = (i + j + k + l) * G4
|
||||
val x0 = x - (i - t2)
|
||||
val y0 = y - (j - t2)
|
||||
val z0 = z - (k - t2)
|
||||
val w0 = w - (l - t2)
|
||||
|
||||
var c = if (x0 > y0) 32 else 0
|
||||
c += if (x0 > z0) 16 else 0
|
||||
c += if (y0 > z0) 8 else 0
|
||||
c += if (x0 > w0) 4 else 0
|
||||
c += if (y0 > w0) 2 else 0
|
||||
c += if (z0 > w0) 1 else 0
|
||||
c = c shl 2
|
||||
|
||||
val i1 = if (SIMPLEX_4D[c] >= 3) 1 else 0
|
||||
val i2 = if (SIMPLEX_4D[c] >= 2) 1 else 0
|
||||
val i3 = if (SIMPLEX_4D[c++] >= 1) 1 else 0
|
||||
val j1 = if (SIMPLEX_4D[c] >= 3) 1 else 0
|
||||
val j2 = if (SIMPLEX_4D[c] >= 2) 1 else 0
|
||||
val j3 = if (SIMPLEX_4D[c++] >= 1) 1 else 0
|
||||
val k1 = if (SIMPLEX_4D[c] >= 3) 1 else 0
|
||||
val k2 = if (SIMPLEX_4D[c] >= 2) 1 else 0
|
||||
val k3 = if (SIMPLEX_4D[c++] >= 1) 1 else 0
|
||||
val l1 = if (SIMPLEX_4D[c] >= 3) 1 else 0
|
||||
val l2 = if (SIMPLEX_4D[c] >= 2) 1 else 0
|
||||
val l3 = if (SIMPLEX_4D[c] >= 1) 1 else 0
|
||||
|
||||
|
||||
val x1 = x0 - i1 + G4
|
||||
val y1 = y0 - j1 + G4
|
||||
val z1 = z0 - k1 + G4
|
||||
val w1 = w0 - l1 + G4
|
||||
val x2 = x0 - i2 + 2 * G4
|
||||
val y2 = y0 - j2 + 2 * G4
|
||||
val z2 = z0 - k2 + 2 * G4
|
||||
val w2 = w0 - l2 + 2 * G4
|
||||
val x3 = x0 - i3 + 3 * G4
|
||||
val y3 = y0 - j3 + 3 * G4
|
||||
val z3 = z0 - k3 + 3 * G4
|
||||
val w3 = w0 - l3 + 3 * G4
|
||||
val x4 = x0 - 1 + 4 * G4
|
||||
val y4 = y0 - 1 + 4 * G4
|
||||
val z4 = z0 - 1 + 4 * G4
|
||||
val w4 = w0 - 1 + 4 * G4
|
||||
|
||||
val n0: Double
|
||||
val n1: Double
|
||||
val n2: Double
|
||||
val n3: Double
|
||||
val n4: Double
|
||||
|
||||
t = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0
|
||||
if (t < 0) n0 = 0.0 else {
|
||||
t *= t
|
||||
n0 = t * t * gradCoord4D(seed, i, j, k, l, x0, y0, z0, w0)
|
||||
}
|
||||
t = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1
|
||||
if (t < 0) n1 = 0.0 else {
|
||||
t *= t
|
||||
n1 = t * t * gradCoord4D(seed, i + i1, j + j1, k + k1, l + l1, x1, y1, z1, w1)
|
||||
}
|
||||
t = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2
|
||||
if (t < 0) n2 = 0.0 else {
|
||||
t *= t
|
||||
n2 = t * t * gradCoord4D(seed, i + i2, j + j2, k + k2, l + l2, x2, y2, z2, w2)
|
||||
}
|
||||
t = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3
|
||||
if (t < 0) n3 = 0.0 else {
|
||||
t *= t
|
||||
n3 = t * t * gradCoord4D(seed, i + i3, j + j3, k + k3, l + l3, x3, y3, z3, w3)
|
||||
}
|
||||
t = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4
|
||||
if (t < 0) n4 = 0.0 else {
|
||||
t *= t
|
||||
n4 = t * t * gradCoord4D(seed, i + 1, j + 1, k + 1, l + 1, x4, y4, z4, w4)
|
||||
}
|
||||
|
||||
return 27 * (n0 + n1 + n2 + n3 + n4)
|
||||
}
|
||||
|
||||
fun Vector4.Companion.simplex(seed: Int, x: Double): Vector4 = Vector4(simplex(seed, x, 0.0, 0.0, 0.0),
|
||||
simplex(seed, 0.0, x + 31.3383, 0.0, 0.0),
|
||||
simplex(seed, 0.0, 0.0, x - 483.23, 0.0),
|
||||
simplex(seed, 0.0, 0.0, 0.0, x + 943.3)
|
||||
)
|
||||
151
orx-noise/src/commonMain/kotlin/UniformRandom.kt
Normal file
151
orx-noise/src/commonMain/kotlin/UniformRandom.kt
Normal file
@@ -0,0 +1,151 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.IntVector2
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.Vector4
|
||||
import org.openrndr.shape.Rectangle
|
||||
import kotlin.random.Random
|
||||
|
||||
fun random(min: Double = -1.0, max: Double = 1.0,
|
||||
random: Random = Random.Default) =
|
||||
(random.nextDouble() * (max - min)) + min
|
||||
|
||||
fun Int.Companion.uniform(min: Int = -1, max: Int = 2,
|
||||
random: Random = Random.Default) =
|
||||
(random.nextDouble() * (max - min)).toInt() + min
|
||||
|
||||
fun Double.Companion.uniform(min: Double = -1.0, max: Double = 1.0,
|
||||
random: Random = Random.Default) =
|
||||
(random.nextDouble() * (max - min)) + min
|
||||
|
||||
fun Vector2.Companion.uniform(min: Vector2 = -ONE, max: Vector2 = ONE,
|
||||
random: Random = Random.Default) =
|
||||
Vector2(Double.uniform(min.x, max.x, random),
|
||||
Double.uniform(min.y, max.y, random))
|
||||
|
||||
fun Vector2.Companion.uniform(min: Double = -1.0, max: Double = 1.0,
|
||||
random: Random = Random.Default) =
|
||||
Vector2.uniform(Vector2(min, min), Vector2(max, max), random)
|
||||
|
||||
fun Vector2.Companion.uniform(rect: Rectangle,
|
||||
random: Random = Random.Default) =
|
||||
Vector2.uniform(rect.corner,
|
||||
rect.corner + rect.dimensions, random)
|
||||
|
||||
fun IntVector2.Companion.uniform(min: IntVector2 = IntVector2(-1, -1),
|
||||
max: IntVector2 = IntVector2(2, 2),
|
||||
random: Random = Random.Default) =
|
||||
IntVector2(Int.uniform(min.x, max.x, random),
|
||||
Int.uniform(min.y, max.y, random))
|
||||
|
||||
fun IntVector2.Companion.uniform(min: Int = -1, max: Int = 2,
|
||||
random: Random = Random.Default) =
|
||||
IntVector2.uniform(IntVector2(min, min),
|
||||
IntVector2(max, max), random)
|
||||
|
||||
fun Vector2.Companion.uniformRing(innerRadius: Double = 0.0,
|
||||
outerRadius: Double = 1.0,
|
||||
random: Random = Random.Default): Vector2 {
|
||||
while (true) {
|
||||
uniform(-outerRadius, outerRadius, random).let {
|
||||
val squaredLength = it.squaredLength
|
||||
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Vector2.Companion.uniforms(count: Int,
|
||||
min: Vector2 = -ONE,
|
||||
max: Vector2 = ONE,
|
||||
random: Random = Random.Default): List<Vector2> =
|
||||
List(count) {
|
||||
Vector2.uniform(min, max, random)
|
||||
}
|
||||
|
||||
fun Vector2.Companion.uniforms(count: Int,
|
||||
rect: Rectangle,
|
||||
random: Random = Random.Default): List<Vector2> =
|
||||
List(count) { Vector2.uniform(rect, random) }
|
||||
|
||||
fun Vector2.Companion.uniformsRing(count: Int,
|
||||
innerRadius: Double = 0.0, outerRadius: Double = 1.0,
|
||||
random: Random = Random.Default): List<Vector2> =
|
||||
List(count) {
|
||||
Vector2.uniformRing(innerRadius, outerRadius, random)
|
||||
}
|
||||
|
||||
fun Vector3.Companion.uniform(min: Double = -1.0, max: Double = 1.0, random: Random = Random.Default): Vector3 =
|
||||
Vector3.uniform(Vector3(min, min, min), Vector3(max, max, max), random)
|
||||
|
||||
fun Vector3.Companion.uniform(min: Vector3 = -ONE,
|
||||
max: Vector3 = ONE,
|
||||
random: Random = Random.Default): Vector3 {
|
||||
return Vector3(Double.uniform(min.x, max.x, random),
|
||||
Double.uniform(min.y, max.y, random),
|
||||
Double.uniform(min.z, max.z, random))
|
||||
}
|
||||
|
||||
fun Vector3.Companion.uniformRing(innerRadius: Double = 0.0,
|
||||
outerRadius: Double = 1.0,
|
||||
random: Random = Random.Default): Vector3 {
|
||||
while (true) {
|
||||
uniform(-outerRadius, outerRadius, random).let {
|
||||
val squaredLength = it.squaredLength
|
||||
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Vector3.Companion.uniforms(count: Int,
|
||||
min: Double = -1.0,
|
||||
max: Double = 1.0,
|
||||
random: Random = Random.Default): List<Vector3> =
|
||||
List(count) {
|
||||
Vector3.uniform(min, max, random)
|
||||
}
|
||||
|
||||
|
||||
fun Vector3.Companion.uniforms(count: Int,
|
||||
min: Vector3 = -ONE,
|
||||
max: Vector3 = ONE,
|
||||
random: Random = Random.Default): List<Vector3> =
|
||||
List(count) {
|
||||
Vector3.uniform(min, max, random)
|
||||
}
|
||||
|
||||
fun Vector3.Companion.uniformsRing(count: Int,
|
||||
innerRadius: Double = 0.0, outerRadius: Double = 1.0,
|
||||
random: Random = Random.Default): List<Vector3> =
|
||||
List(count) {
|
||||
Vector3.uniformRing(innerRadius, outerRadius, random)
|
||||
}
|
||||
|
||||
|
||||
fun Vector4.Companion.uniform(min: Double = -1.0, max: Double = 1.0, random: Random = Random.Default): Vector4 =
|
||||
Vector4.uniform(Vector4(min, min, min, min), Vector4(max, max, max, max), random)
|
||||
|
||||
fun Vector4.Companion.uniform(min: Vector4 = -ONE, max: Vector4 = ONE, random: Random = Random.Default): Vector4 {
|
||||
return Vector4(Double.uniform(min.x, max.x, random),
|
||||
Double.uniform(min.y, max.y, random),
|
||||
Double.uniform(min.z, max.z, random),
|
||||
Double.uniform(min.w, max.w, random))
|
||||
}
|
||||
|
||||
fun Vector4.Companion.uniformRing(innerRadius: Double = 0.0,
|
||||
outerRadius: Double = 1.0,
|
||||
random: Random = Random.Default): Vector4 {
|
||||
while (true) {
|
||||
uniform(-outerRadius, outerRadius, random).let {
|
||||
val squaredLength = it.squaredLength
|
||||
if (squaredLength >= innerRadius * innerRadius && squaredLength < outerRadius * outerRadius) {
|
||||
return it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
orx-noise/src/commonMain/kotlin/ValueNoise1D.kt
Normal file
8
orx-noise/src/commonMain/kotlin/ValueNoise1D.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
fun valueLinear(seed: Int, x: Double) = value(seed, x, ::linear)
|
||||
fun valueQuintic(seed: Int, x: Double) = value(seed, x, ::quintic)
|
||||
fun valueHermite(seed: Int, x: Double) = value(seed, x, ::hermite)
|
||||
|
||||
inline fun value(seed: Int, x: Double, crossinline interpolation: (Double) -> Double = ::linear): Double =
|
||||
value(seed, x, 0.0, interpolation)
|
||||
32
orx-noise/src/commonMain/kotlin/ValueNoise2D.kt
Normal file
32
orx-noise/src/commonMain/kotlin/ValueNoise2D.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun valueLinear(seed: Int, x: Double, y: Double) = value(seed, x, y, ::linear)
|
||||
fun valueQuintic(seed: Int, x: Double, y: Double) = value(seed, x, y, ::quintic)
|
||||
fun valueHermite(seed: Int, x: Double, y: Double) = value(seed, x, y, ::hermite)
|
||||
|
||||
fun valueLinear(seed: Int, position: Vector2) =
|
||||
value(seed, position.x, position.y, ::linear)
|
||||
|
||||
fun valueQuintic(seed: Int, position: Vector2) =
|
||||
value(seed, position.x, position.y, ::quintic)
|
||||
|
||||
fun valueHermite(seed: Int, position: Vector2) =
|
||||
value(seed, position.x, position.y, ::hermite)
|
||||
|
||||
inline fun value(seed: Int, x: Double, y: Double, crossinline interpolation: (Double) -> Double = ::linear): Double {
|
||||
val x0 = x.fastFloor()
|
||||
val y0 = y.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
|
||||
val xs = interpolation(x - x0)
|
||||
val ys = interpolation(y - y0)
|
||||
|
||||
val xf0 = mix(valCoord2D(seed, x0, y0), valCoord2D(seed, x1, y0), xs)
|
||||
val xf1 = mix(valCoord2D(seed, x0, y1), valCoord2D(seed, x1, y1), xs)
|
||||
|
||||
return mix(xf0, xf1, ys)
|
||||
}
|
||||
41
orx-noise/src/commonMain/kotlin/ValueNoise3D.kt
Normal file
41
orx-noise/src/commonMain/kotlin/ValueNoise3D.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.openrndr.extra.noise
|
||||
|
||||
import org.openrndr.math.Vector3
|
||||
import org.openrndr.math.mix
|
||||
|
||||
fun valueLinear(seed: Int, x: Double, y: Double, z: Double) = value(seed, x, y, z, ::linear)
|
||||
fun valueQuintic(seed: Int, x: Double, y: Double, z: Double) = value(seed, x, y, z, ::quintic)
|
||||
fun valueHermite(seed: Int, x: Double, y: Double, z: Double) = value(seed, x, y, z, ::hermite)
|
||||
|
||||
fun valueLinear(seed: Int, position: Vector3) =
|
||||
value(seed, position.x, position.y, position.z, ::linear)
|
||||
|
||||
fun valueQuintic(seed: Int, position: Vector3) =
|
||||
value(seed, position.x, position.y, position.z, ::quintic)
|
||||
|
||||
fun valueHermite(seed: Int, position: Vector3) =
|
||||
value(seed, position.x, position.y, position.z, ::hermite)
|
||||
|
||||
inline fun value(seed: Int, x: Double, y: Double, z: Double, crossinline interpolation: (Double) -> Double = ::linear): Double {
|
||||
val x0 = x.fastFloor()
|
||||
val y0 = y.fastFloor()
|
||||
val z0 = z.fastFloor()
|
||||
val x1 = x0 + 1
|
||||
val y1 = y0 + 1
|
||||
val z1 = z0 + 1
|
||||
|
||||
val xs = interpolation(x - x0)
|
||||
val ys = interpolation(y - y0)
|
||||
val zs = interpolation(z - z0)
|
||||
|
||||
|
||||
val xf00 = mix(valCoord3D(seed, x0, y0, z0), valCoord3D(seed, x1, y0, z0), xs)
|
||||
val xf10 = mix(valCoord3D(seed, x0, y1, z0), valCoord3D(seed, x1, y1, z0), xs)
|
||||
val xf01 = mix(valCoord3D(seed, x0, y0, z1), valCoord3D(seed, x1, y0, z1), xs)
|
||||
val xf11 = mix(valCoord3D(seed, x0, y1, z1), valCoord3D(seed, x1, y1, z1), xs)
|
||||
|
||||
val yf0 = mix(xf00, xf10, ys)
|
||||
val yf1 = mix(xf01, xf11, ys)
|
||||
|
||||
return mix(yf0, yf1, zs)
|
||||
}
|
||||
271
orx-noise/src/commonMain/kotlin/filters/NoiseFilters.kt
Normal file
271
orx-noise/src/commonMain/kotlin/filters/NoiseFilters.kt
Normal file
@@ -0,0 +1,271 @@
|
||||
//package org.openrndr.extra.noise.filters
|
||||
//
|
||||
//import org.openrndr.color.ColorRGBa
|
||||
//import org.openrndr.draw.Filter
|
||||
//import org.openrndr.draw.filterShaderFromUrl
|
||||
//import org.openrndr.extra.parameters.*
|
||||
//import org.openrndr.math.Vector2
|
||||
//import org.openrndr.math.Vector3
|
||||
//import org.openrndr.math.Vector4
|
||||
//import org.openrndr.resourceUrl
|
||||
//
|
||||
///**
|
||||
// * Hash noise filter that produces white-noise-like noise.
|
||||
// */
|
||||
//class HashNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/hash-noise.frag"))) {
|
||||
// /**
|
||||
// * noise gain per channel, default is Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise bias per channel, default is Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * is the noise monochrome, default is true
|
||||
// */
|
||||
// @BooleanParameter("Monochrome")
|
||||
// var monochrome: Boolean by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise seed, feed it with time to animate
|
||||
// */
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Double by parameters
|
||||
//
|
||||
// init {
|
||||
// monochrome = true
|
||||
// gain = Vector4(1.0, 1.0, 1.0, 0.0)
|
||||
// bias = Vector4(0.0, 0.0, 0.0, 1.0)
|
||||
// seed = 0.0
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Speckle noise filter
|
||||
// */
|
||||
//class SpeckleNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/speckle-noise.frag"))) {
|
||||
//
|
||||
// /**
|
||||
// * The color of the generated speckles
|
||||
// */
|
||||
// @ColorParameter("Color")
|
||||
// var color: ColorRGBa by parameters
|
||||
//
|
||||
// /**
|
||||
// * Density of the speckles, default is 0.1, min, 0.0, max is 1.0
|
||||
// */
|
||||
// @DoubleParameter("Density", 0.0, 1.0)
|
||||
// var density: Double by parameters
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Noisiness of the generated speckles, default is 0.0, min is 0.0, max is 1.0
|
||||
// */
|
||||
// @DoubleParameter("Noise", 0.0, 1.0)
|
||||
// var noise: Double by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// /**
|
||||
// * noise seed, feed it with time to animate
|
||||
// */
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Double by parameters
|
||||
//
|
||||
// init {
|
||||
// density = 0.1
|
||||
// color = ColorRGBa.WHITE
|
||||
// seed = 0.0
|
||||
// noise = 0.0
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces cell or Voronoi noise
|
||||
// */
|
||||
//class CellNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/cell-noise.frag"))) {
|
||||
// var seed: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector2(1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector2.ZERO
|
||||
// scale = Vector2.ONE
|
||||
// lacunarity = Vector2(2.0, 2.0)
|
||||
// gain = Vector4.ONE
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ZERO
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces value noise
|
||||
// */
|
||||
//class ValueNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/value-noise.frag"))) {
|
||||
// @DoubleParameter("Seed", 0.0, 10000.0)
|
||||
// var seed: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector2(1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector2(2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector2 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector2.ZERO
|
||||
// scale = Vector2.ONE
|
||||
// lacunarity = Vector2(2.0, 2.0)
|
||||
// gain = Vector4.ONE
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ZERO
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Filter that produces 3D Simplex Noise
|
||||
// */
|
||||
//@Description("Simplex Noise")
|
||||
//class SimplexNoise3D : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/simplex-noise-3d.frag"))) {
|
||||
// var seed: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * base noise scale, default is Vector3(1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var scale: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * lacunarity is the amount by which scale is modulated per octave, default is Vector3(2.0, 2.0, 2.0)
|
||||
// */
|
||||
// var lacunarity: Vector3 by parameters
|
||||
//
|
||||
// /**
|
||||
// * gain is the base intensity per channel, default is Vector2(1.0, 1.0, 1.0, 1.0)
|
||||
// */
|
||||
// var gain: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * decay is the amount by which gain is modulated per octave, default is Vector4(0.5, 0.5, 0.5, 0.5)
|
||||
// */
|
||||
// var decay: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * the number of octaves of noise to generate, default is 4
|
||||
// */
|
||||
// @IntParameter("Octaves", 1, 8)
|
||||
// var octaves: Int by parameters
|
||||
//
|
||||
// /**
|
||||
// * the value to add to the resulting noise
|
||||
// */
|
||||
// var bias: Vector4 by parameters
|
||||
//
|
||||
// /**
|
||||
// * should the output colors be multiplied by the alpha channel, default is true
|
||||
// */
|
||||
// @BooleanParameter("Premultiplied alpha")
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// seed = Vector3.ZERO
|
||||
// scale = Vector3.ONE
|
||||
// lacunarity = Vector3(2.0, 2.0, 2.0)
|
||||
// gain = Vector4.ONE / 2.0
|
||||
// decay = Vector4.ONE / 2.0
|
||||
// octaves = 4
|
||||
// bias = Vector4.ONE / 2.0
|
||||
// premultipliedAlpha = true
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Filter for Worley Noise
|
||||
// */
|
||||
//@Description("Worley Noise")
|
||||
//class WorleyNoise : Filter(filterShaderFromUrl(resourceUrl("/org/openrndr/extra/noise/shaders/gl3/worley-noise.frag"))) {
|
||||
// @DoubleParameter("Scale", 0.1, 200.0)
|
||||
// var scale: Double by parameters
|
||||
//
|
||||
// @BooleanParameter("Premultiplied alpha")
|
||||
// var premultipliedAlpha: Boolean by parameters
|
||||
//
|
||||
// init {
|
||||
// premultipliedAlpha = true
|
||||
// scale = 5.0
|
||||
// }
|
||||
//}
|
||||
36
orx-noise/src/commonMain/kotlin/phrases/NoisePhrases.kt
Normal file
36
orx-noise/src/commonMain/kotlin/phrases/NoisePhrases.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
//@file:ShaderPhrases(exports = ["hash22","hash21","valueNoise21"])
|
||||
package org.openrndr.extra.noise.phrases
|
||||
|
||||
//import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
|
||||
val phraseHash22 = """vec2 hash22(vec2 p) {
|
||||
float n = sin(dot(p, vec2(41, 289)));
|
||||
return fract(vec2(262144, 32768)*n);
|
||||
}
|
||||
"""
|
||||
|
||||
val phraseHash21 = "float hash21(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }"
|
||||
|
||||
val phraseHash33 = """
|
||||
#define MOD3 vec3(.1031,.11369,.13787)
|
||||
vec3 hash33(vec3 p3) {
|
||||
p3 = fract(p3 * MOD3);
|
||||
p3 += dot(p3, p3.yxz+19.19);
|
||||
return -1.0 + 2.0 * fract(vec3((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y, (p3.y+p3.z)*p3.x));
|
||||
}
|
||||
"""
|
||||
|
||||
val phraseValueNoise21 = """
|
||||
float noise(vec2 x) {
|
||||
vec2 i = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
float a = hash21(i);
|
||||
float b = hash21(i + vec2(1.0, 0.0));
|
||||
float c = hash21(i + vec2(0.0, 1.0));
|
||||
float d = hash21(i + vec2(1.0, 1.0));
|
||||
|
||||
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
|
||||
}
|
||||
""".trimIndent()
|
||||
7
orx-noise/src/commonMain/kotlin/phrases/Simplex.kt
Normal file
7
orx-noise/src/commonMain/kotlin/phrases/Simplex.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
//@file:ShaderPhrases([])
|
||||
package org.openrndr.extra.noise.phrases
|
||||
//
|
||||
//import org.openrndr.extra.shaderphrases.annotations.ShaderPhrases
|
||||
//import org.openrndr.extra.shaderphrases.phraseResource
|
||||
//
|
||||
//val phraseSimplex3 by phraseResource("/org/openrndr/extra/noise/phrases/gl3/simplex-3.frag")
|
||||
Reference in New Issue
Block a user