Skip to content

Commit

Permalink
搞定了,日后在整理重构一下代码,里面很多冗余。
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricporter committed Jul 30, 2012
1 parent 49248f0 commit ddc28a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 11 additions & 5 deletions EffectLab/Effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ def __init__(self, formula, antialias=2):
self.antialias = antialias

def filter(self, img):
return core.radian_warp(img, self.formula, self.antialias, self.empty_color)
try:
return core.radian_warp(img, self.formula, self.antialias, self.empty_color)
except:
pass

def radian_formula(x, y):
'''transform formula
Expand Down Expand Up @@ -290,20 +293,23 @@ def __init__(self):
class GlobalWaveEffect(Effect):
'''全局波浪效果,使用sin进行变换
'''
def __init__(self, dw=1, dh=0.1, antialias=2):
def __init__(self, dw=1, dh=0.1, xoffset=0, antialias=2):
self.dw = dw
self.dh = dh
self.antialias = antialias
self.xoffset = xoffset

def transform(self, x, y, width, height, delta_w, delta_h):
radian = 2 * math.pi * x / float(width) * delta_w
radian = 2 * math.pi * (x + self.xoffset) / float(width) * delta_w
offset = 0.5 * sin(radian) * height * delta_h

return x, y + offset

def filter(self, img):
return core.wave_warp(img, self.dw, self.dh, self.antialias, self.empty_color)

try:
return core.wave_warp(img, self.dw, self.dh, self.xoffset, self.antialias, self.empty_color)
except:
pass

width, height = img.size
f = lambda x, y: self.transform(x, y, width, height, self.dw, self.dh)
Expand Down
5 changes: 3 additions & 2 deletions EffectLab/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ static PyObject* wave_warp(PyObject *self, PyObject *args)
double radian;
double offset;
int er, eg, eb, ea;
double xoffset;

if (!PyArg_ParseTuple(args, "OddiO", &image, &dw, &dh, &antialias, &empty_color))
if (!PyArg_ParseTuple(args, "OdddiO", &image, &dw, &dh, &xoffset, &antialias, &empty_color))
{
return NULL;
}
Expand Down Expand Up @@ -322,7 +323,7 @@ static PyObject* wave_warp(PyObject *self, PyObject *args)
yy = j + aj / (double)antialias;

/* ------------------------- */
radian = 2 * 3.14159265 * xx / (double)width * dw;
radian = 2 * 3.14159265 * (xx + xoffset) / (double)width * dw;
offset = 0.5 * sin(radian) * height * dh;

xnew = xx;
Expand Down

0 comments on commit ddc28a0

Please sign in to comment.