cellsortpixels.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. xcell=4;ycell=4
  2. function INT(a)
  3. return(a-a%1)
  4. end
  5. function SWAPPIXELS(tx0,ty0,tx1,ty1)
  6. r0,g0,b0=get_rgb(tx0,ty0)
  7. r1,g1,b1=get_rgb(tx1,ty1)
  8. set_rgb(tx1,ty1,r0,g0,b0)
  9. set_rgb(tx0,ty0,r1,g1,b1)
  10. end
  11. function SWAPPIXELSSORTLUM(tx0,ty0,tx1,ty1)
  12. r0,g0,b0=get_rgb(tx0,ty0)
  13. r1,g1,b1=get_rgb(tx1,ty1)
  14. w0=(b0*11+r0*30+g0*59)/100
  15. w1=(b1*11+r1*30+g1*59)/100
  16. if w0>w1 then
  17. set_rgb(tx1,ty1,r0,g0,b0)
  18. set_rgb(tx0,ty0,r1,g1,b1)
  19. end
  20. end
  21. function BAR(tx1,ty1,tx2,ty2,tcl)
  22. tr1=(INT(tcl/65536))%256
  23. tg1=(INT(tcl/256))%256
  24. tb1=tcl%256
  25. for tx3=tx1,tx2,1 do
  26. for ty3=ty1,ty2,1 do
  27. set_rgb(tx3,ty3,tr1/255,tg1/255,tb1/255)
  28. end;end
  29. end
  30. function COPY(tx1,ty1,tx2,ty2,tx3,ty3)
  31. for ty4=ty1,ty2,1 do
  32. for tx4=tx1,tx2,1 do
  33. r,g,b=get_rgb(tx4,ty4)
  34. set_rgb(tx3+tx4-tx1,ty3+ty4-ty1,r,g,b)
  35. end;end
  36. end
  37. function MOVESWAP(tx1,ty1,tx2,ty2,tx3,ty3)
  38. for ty4=ty1,ty2,1 do
  39. for tx4=tx1,tx2,1 do
  40. r0,g0,b0=get_rgb(tx4,ty4)
  41. r1,g1,b1=get_rgb(tx4-tx1+tx3,ty4-tx1+tx3)
  42. set_rgb(tx3+tx4-tx1,ty3+ty4-ty1,r0,g0,b0)
  43. set_rgb(tx4,ty4,r1,g1,b1)
  44. end;end
  45. end
  46. xycell=xcell*ycell
  47. for x1=0,width-1,xcell do
  48. for y1=0,height-1,ycell do
  49. for q2=0,xycell-2,1 do
  50. for q3=q2+1,xycell-1,1 do
  51. y2=INT(q2/xcell);y3=INT(q3/xcell)
  52. x2=q2%xcell;x3=q3%xcell
  53. x2s=x1+x2;y2s=y1+y2
  54. x3s=x1+x3;y3s=y1+y3
  55. SWAPPIXELSSORTLUM(x2s,y2s,x3s,y3s)
  56. end;end;end
  57. progress(x1/width)
  58. end
  59. flush()