Skip to content

Commit 3129f8b

Browse files
committed
Some playing around
1 parent 6ef85ce commit 3129f8b

File tree

2 files changed

+66
-49
lines changed

2 files changed

+66
-49
lines changed

projects/IFS_shader.lua

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ require "common"
33
require "colors"
44
local luv=require "colors_luv"
55
--local size_mult=0.25
6-
--__set_window_size(2560*size_mult,1440*size_mult)
7-
__set_window_size(1280,720)
8-
local aspect_ratio=1280/720
6+
local win_w=1024--2560
7+
local win_h=1024--1440
8+
__set_window_size(win_w,win_h)
9+
local aspect_ratio=win_w/win_h
910
local size=STATE.size
1011
local max_palette_size=50
1112
local sample_count=50000
@@ -422,23 +423,6 @@ function gen_palette( )
422423
end
423424
end
424425
palette.generators[palette.current_gen][2](ret,hue_range,sat_range,lit_range)
425-
426-
--[[ complementary
427-
gen_shades(ret,h1,s,l,0.15,5)
428-
gen_shades(ret,1-h1,s,0.15,l,5)
429-
--]]
430-
--[[ triadic
431-
gen_shades(ret,h1,s,l,0.2,5)
432-
gen_shades(ret,math.fmod(h1+0.33,1),s,0.2,l/2,5)
433-
gen_shades(ret,math.fmod(h1+0.66,1),s,l/2,l,3)
434-
--]]
435-
--[[ anologous
436-
gen_shades(ret,h1,s,0.2,l,3)
437-
gen_shades(ret,math.fmod(h1+0.05,1),s,0.2,l,3)
438-
gen_shades(ret,math.fmod(h1+0.1,1),s/2,l,0,3)
439-
gen_shades(ret,math.fmod(h1+0.15,1),s/2,l,0,3)
440-
gen_shades(ret,math.fmod(h1+0.2,1),s,l,0,3)
441-
--]]
442426
end
443427
function palette_chooser()
444428
if imgui.RadioButton("Show palette",palette.show) then
@@ -567,6 +551,29 @@ function rand_weighted(tbl)
567551
end
568552
end
569553
end
554+
function replace_random( s,substr,rep )
555+
local num_match=0
556+
local function count( )
557+
num_match=num_match+1
558+
return false
559+
end
560+
string.gsub(s,substr,count)
561+
print("input:",s," found:",count)
562+
num_rep=math.random(0,num_match-1)
563+
print("replacing:",num_rep)
564+
function rep_one( )
565+
if num_rep==0 then
566+
num_rep=num_rep-1
567+
return rep()
568+
else
569+
num_rep=num_rep-1
570+
return false
571+
end
572+
end
573+
local ret=string.gsub(s,substr,rep_one)
574+
print("returning:",ret)
575+
return ret
576+
end
570577
function random_math( steps,seed )
571578
local cur_string=seed or "R"
572579

@@ -578,11 +585,12 @@ function random_math( steps,seed )
578585
end
579586

580587
for i=1,steps do
581-
cur_string=string.gsub(cur_string,"R",M)
588+
cur_string=replace_random(cur_string,"R",M)
582589
end
583590
cur_string=string.gsub(cur_string,"R",MT)
584591
return cur_string
585592
end
593+
586594
function random_math_fourier( steps,complications ,seed)
587595
local cur_string=seed or "(R)/2"
588596
for i=1,steps do
@@ -650,33 +658,33 @@ function gui()
650658
end
651659
rand_complexity=rand_complexity or 3
652660
if imgui.Button("Rand function") then
653-
--str_x=random_math(rand_complexity)
654-
--str_y=random_math(rand_complexity)
655-
--str_x=random_math_fourier(4,rand_complexity)
661+
str_x=random_math(rand_complexity)
662+
str_y=random_math(rand_complexity)
663+
--str_x=random_math_fourier(2,rand_complexity)
656664
--str_y=random_math_fourier(4,rand_complexity)
657665

658-
str_x=random_math_power(3,rand_complexity)
659-
str_y=random_math_power(3,rand_complexity)
666+
--str_x=random_math_power(3,rand_complexity)
667+
--str_y=random_math_power(3,rand_complexity)
660668
--str_x="s.x"
661669
--str_y="s.y"
662670

663671
--str_y="-"..str_x
664-
--str_x=random_math(6,"cos(R)*R")
665-
--str_y=random_math(6,"sin(R)*R")
672+
--str_x=random_math(rand_complexity,"cos(R)*R")
673+
--str_y=random_math(rand_complexity,"sin(R)*R")
666674
--str_y="sin("..str_x..")"
667675
--str_x="cos("..str_x..")"
668676
--str_x=random_math_power(2,rand_complexity).."/"..random_math_power(2,rand_complexity)
669677
--str_y=random_math_fourier(2,rand_complexity).."/"..str_x
670678
str_preamble=""
671679
str_postamble=""
672-
--[[ offset
673-
str_preamble=str_preamble.."s+=params;"
680+
-- [[ offset
681+
str_preamble=str_preamble.."s+=params.xy;"
674682
--]]
675-
-- [[ normed-like
683+
--[[ normed-like
676684
str_preamble=str_preamble.."float l=length(s);"
677685
str_postamble=str_postamble.."s/=l;s*=move_dist;"
678686
--]]
679-
--[[ normed-like2
687+
-- [[ normed-like2
680688
str_preamble=str_preamble..""
681689
str_postamble=str_postamble.."s/=length(s);s*=move_dist;s+=p;"
682690
--]]

projects/isolines.lua

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ __set_window_size(1024,1024)
44
local aspect_ratio=1024/1024
55
local size=STATE.size
66

7-
local oversample=2
8-
str_x=str_x or "last_v.x+(diffuse.x*lap.x-last_v.x*last_v.y*last_v.y+feed*(1-last_v.x))*dt"
9-
str_y=str_y or "last_v.y+(diffuse.y*lap.y+last_v.x*last_v.y*last_v.y-(kill+feed)*(last_v.y))*dt"
7+
local oversample=1
8+
local org_str="last_v.x*last_v.y*last_v.y"
9+
local str_inner="(last_v.y*last_v.y*last_v.x/coord.x)"
10+
local str_inner="(last_v.x+params.x)*(last_v.y+params.y)*(last_v.y+params.z)"
11+
str_x=str_x or string.format("last_v.x+(diffuse.x*lap.x-%s+feed*(1-last_v.x))*dt",str_inner)
12+
str_y=str_y or string.format("last_v.y+(diffuse.y*lap.y+%s-(kill+feed)*(last_v.y))*dt",str_inner)
1013
config=make_config({
11-
{"v0",0,type="float",min=0,max=1},
12-
{"v1",0,type="float",min=0,max=1},
13-
{"v2",0,type="float",min=0,max=1},
14+
{"v0",0,type="float",min=-0.2,max=0.2},
15+
{"v1",0,type="float",min=-0.2,max=0.2},
16+
{"v2",0,type="float",min=-0.2,max=0.2},
1417
{"v3",0,type="float",min=0,max=1},
1518

1619
{"diffuse_x",1,type="float",min=0,max=1},
@@ -50,16 +53,19 @@ uniform float line_w;
5053
uniform vec2 limits;
5154
5255
void main(){
56+
vec3 in_col=vec3(0.2,0.1,0.9);
5357
vec2 normed=(pos.xy+vec2(1,1))/2;
5458
vec2 lv=texture(values,normed).xy;
5559
5660
//float v=clamp((lv-limits.x)/(limits.y-limits.x),0,1);
5761
5862
float w=line_w;
59-
//float vv=clamp(smoothstep(0.5-w,0.5,v)-smoothstep(0.5,0.5+w,v),0,1);
60-
//color=vec4(vv*0.8,0,0,1);
61-
vec3 in_col=vec3(0.2,0.1,0.9);
62-
color=vec4(lv.y*in_col,1);
63+
float v=lv.x;
64+
float c=0.5;
65+
float vv=clamp(smoothstep(c-w,c,v)-smoothstep(c,c+w,v),0,1);
66+
color=vec4(vv*in_col,1);
67+
68+
//color=vec4(lv.y*in_col,1);
6369
}
6470
]==]
6571

@@ -84,9 +90,9 @@ vec2 calc_new_value(vec2 last_v)
8490
vec2 normed=(pos.xy+vec2(1,1))/2;
8591
8692
vec2 coord=pos.xy;
87-
/*float rad=length(coord);
93+
float rad=length(coord);
8894
float ang=atan(coord.y,coord.x);
89-
coord=vec2(rad,ang);*/
95+
coord=vec2(rad,ang);
9096
9197
vec2 a=DX(-1,0);
9298
vec2 b=DX(0,1);
@@ -97,8 +103,8 @@ vec2 calc_new_value(vec2 last_v)
97103
vec2 f=DX(1,1);
98104
vec2 g=DX(1,-1);
99105
vec2 h=DX(-1,1);
100-
101-
vec2 lap=0.2*(a+b+c+d)+0.05*(e+f+g+h)-last_v;
106+
float main_dir_power=0.8;
107+
vec2 lap=(main_dir_power/4)*(a+b+c+d)+(1-main_dir_power)/4*(e+f+g+h)-last_v;
102108
103109
vec2 ret=vec2(%s,%s);
104110
return ret;
@@ -119,10 +125,12 @@ void main(){
119125
if(pos.x>0.95)
120126
nv=vec2(1,0);*/
121127
128+
//nv+=vec2(0,clamp(1-length(pos),0,1)/2000);
129+
122130
if(init>0.5)
123131
{
124-
if(length(pos)<0.01)
125-
nv=vec2(0.1,0.5+abs(cos(pos.x)*sin(pos.y))*50);
132+
if(length(pos)<0.05 && length(pos)>0.025)
133+
nv=vec2(0.0,1);
126134
else
127135
nv=vec2(1,0);
128136
//nv=vec2(rand(pos.xy),rand2(pos.xy));
@@ -138,7 +146,8 @@ function rnd( v )
138146
return math.random()*(v*2)-v
139147
end
140148
--last_v.x+(diffuse.x*lap.x-last_v.x*last_v.y*last_v.y+feed*(1-last_v.x))*dt
141-
local terminal_symbols={["coord.x"]=5,["coord.y"]=5,
149+
local terminal_symbols={
150+
["coord.x"]=5,--[[["coord.y"]=5,]]
142151
--["a"]=1,["b"]=1,["c"]=1,["d"]=1,
143152
--["e"]=1,["f"]=1,["g"]=1,["h"]=1,
144153
--["lap.x"]=1,["lap.y"]=1,

0 commit comments

Comments
 (0)