154 tokens
Still being somewhat new to pico8, I managed to make this neat water reflect effect.
I'm sure it can be optimized a great deal, but for now its the best I can come up with, though I'm always improving.
--s★_tool -> rflc --[[ configuring to configure this tool, in your _init() or when ever you see a need to change the waters settings, you can use this code ◆ s★_rf_sy = 105 the sample code above sets the start-y position of the water. ◆ s★_rf_data = value data: ◆ sy - start y ◆ bg - background color ◆ ic - ignore color (for cls background colors so it doesn't draw a color that it doesn't need to. if you're using cls(1) then set ic to 1, for example.) ◆ rq - reflection quality ◆ wa - wave amp (how large it waves left/right) ◆ ws - wave speed (how fast it waves left/right) ]]-- --defaults s★_rf_sy=104 s★_rf_bg=1 s★_rf_ic=0 s★_rf_rq=13 s★_rf_wa=2 s★_rf_ws=0.02 --wave value, don't mod this --unless you need to. s★_rf_wv=0 --reflection effects s★_rflc = function(mode, data, val) --if not configuring, then draw rectfill(0, s★_rf_sy, 127, 127, s★_rf_bg) local _scl=(s★_rf_rq/127) local _ht=127-s★_rf_sy local _flc_col = 0 for i=0,s★_rf_rq do for j=0, _ht do local _x=((i/s★_rf_rq)*127)+(cos(s★_rf_wv+(j/6))*(s★_rf_wa+j/8)) local _s=(s★_rf_rq/128)*10 local c=pget(_x,s★_rf_sy-j) if c!= s★_rf_bg and c!= s★_rf_ic and c != 0 then local _y=(j/2) line(_x-_s-_y-j/14, 1+j+s★_rf_sy, _x+_s+_y+j/14, j+s★_rf_sy, c) end end end s★_rf_wv+=s★_rf_ws end |
to use this, just put this code in your draw code under everything you want to reflect.s★_rflc()
compressed code:
s★_rf_sy=104 s★_rf_bg=1 s★_rf_ic=0 s★_rf_rq=13 s★_rf_wa=2 s★_rf_ws=0.02 s★_rf_wv=0 s★_rflc = function(mode, data, val) rectfill(0, s★_rf_sy, 127, 127, s★_rf_bg) local _scl=(s★_rf_rq/127) local _ht=127-s★_rf_sy local _flc_col = 0 for i=0,s★_rf_rq do for j=0, _ht do local _x=((i/s★_rf_rq)*127)+(cos(s★_rf_wv+(j/6))*(s★_rf_wa+j/8)) local _s=(s★_rf_rq/128)*10 local c=pget(_x,s★_rf_sy-j) if c!= s★_rf_bg and c!= s★_rf_ic and c != 0 then local _y=(j/2) line(_x-_s-_y-j/14, 1+j+s★_rf_sy, _x+_s+_y+j/14, j+s★_rf_sy, c) end end end s★_rf_wv+=s★_rf_ws end |
[Please log in to post a comment]