Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ugly way of making images seamless (tileable)
#1
Code:
w = 256;  h = 256

set window "seamless", w*2, h*2
set redraw off

' Create an image with a bunch of randomly colored ellipses.
img = createimage(256, 256)
set image img
for i = 1 to 1000
    set color rnd(256), rnd(256), rnd(256), rnd(256)
    draw ellipse rnd(w), rnd(h), 8 + rnd(24), 8 + rnd(24), rnd(2)
next
set image primary

' Make seamless.
MakeSeamless(img, 3)

' Draw four images.
set color 255, 255, 255
draw image img, 0, 0
draw image img, w, 0
draw image img, 0, h
draw image img, w, h
redraw
while not keydown(KEY_ESCAPE, true)  fwait 60


' MakeSeamless
' ------------
' Make image img seamless (tileable) by doing some copying and fading. The larger you set e, the
' smaller the fading areas become, 2-4 gives good results.
function MakeSeamless(img, e)
    e = max(e, 1)
    w = width(img);  h = height(img)
    set image img
    for x = 0 to w/2 - 1  for y = 0 to h - 1
        p0 = pixel(img, x, y)
        p1 = pixel(img, w/2 + x, y)
        k = 1 - pow(1 - x/(w/2), e);  ik = 1 - k
        set color k*p0[0] + ik*p1[0], k*p0[1] + ik*p1[1], k*p0[2] + ik*p1[2], k*p0[3] + ik*p1[3]
        draw pixel x, y
        k = pow(x/(w/2), e);  ik = 1 - k     
        set color k*p0[0] + ik*p1[0], k*p0[1] + ik*p1[1], k*p0[2] + ik*p1[2], k*p0[3] + ik*p1[3]
        draw pixel w/2 + x, y
    next
    for y = 0 to h/ 2 - 1  for x = 0 to w - 1
        p0 = pixel(img, x, y)
        p1 = pixel(img, x, h/2 + y)
        k = 1 - pow(1 - y/(h/2), e);  ik = 1 - k
        set color k*p0[0] + ik*p1[0], k*p0[1] + ik*p1[1], k*p0[2] + ik*p1[2], k*p0[3] + ik*p1[3]
        draw pixel x, y
        k = pow(y/(h/2), e);  ik = 1 - k
        set color k*p0[0] + ik*p1[0], k*p0[1] + ik*p1[1], k*p0[2] + ik*p1[2], k*p0[3] + ik*p1[3]
        draw pixel x, h/2 + y
    next
    set image primary
    return img
endfunc
Reply
#2
It's the craft of the code. Thanks for sharing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)