29

Cart #ball_effects-0 | 2019-10-14 | Code ▽ | License: CC4-BY-NC-SA
29

Made this cart to test some distortion effects for future projects.

A lot of people got interested in a tweet I made with it so I'm posting here in case anyone wants to see the code or use it on a project.

Move with the mouse;
Z/X (O/X) to change size;
Left mouse click to switch effect.

P#68876 2019-10-14 17:29 ( Edited 2021-01-27 21:35)

1

Omy ! number 5 is just like a real glass ball. Superb graphics ! Star for you.

P#68878 2019-10-14 17:42
1

Great job ! I was curious to see if it could be accelerated with some tricks I discovered recently and I get a 14% bonus on first effect. I was happy with this and try to increase radius, but it actually allow +2 before going >100% :'( It costs more token, is difficult to read and allow 2 pixels more on radius :D

It could be accelerated a bit more, using poke2 or poke4 but I didn't try.

for science :

 ```function ef_vac(r) local r=r local rr=r*r for j=-r,r do for i=-r,r,2 do local s=i*i+j*j if s
P#68905 2019-10-15 21:34 ( Edited 2019-10-15 21:37)

I think a good approach to make it less cpu intensive would be to mirror the effect in 4 quadrants since most effects are mirrored vertically and horizontally.

Another way could be to make a offset mask and save it on the spr memory, though this one only works if you don't indend to change the effect size/time at runtime.

It really depends on what it will be used for in the game :)

P#68962 2019-10-17 12:15

Commentated version of one of the effects:

 ```function ef_mirr(r) --r = radius local rr=r*r --i,j = iterates every pixel in a square that will contain the circle for i=-r,r do for j=-r,r do --s = hypotenuse - it will calculate the distance from the center (0=center; 1=border) --sometimes will use "s=(i*i+j*j)/rr" instead to change s from a linear to a parabolic funtion s=sqrt(i*i+j*j)/r --s<1 will ensure you only draw in the circle and note the entire rectangle if s<1 then --ss is where the magic happens, each effect will distort s into ss using a different function --you can try to experiment other effects by changing how s and ss are calculated --mirror ball ss=-1/s --px and py are the actual pixel coordinates on the screen local px,py=i+x,j+y --sset will draw the effect on the sprite sheet sset(i+r,j+r, --pget will copy a pixel elswhere on the screen draw it inside the circle --you can replace this with "s*16" or "ss*16" to get a rough idea of how the pixel offset affects the final result --in some cases the sine/cosine effect will be used here pget( flr(px+i*ss), flr(py+j*ss) ) ) end end end --draw a black circle to erase the background inside the circle circfill(x,y,r-1,0) --copy the circle from the background to the screen sspr(0,0,r*2,r*2,x-r,y-r) end```
P#69068 2019-10-19 16:40