Code: Select all
REM Swirl Effect
REM ported out of: http://www.petesqbsite.com/sections/express/issue24/index.html#swirl
REM sB 5.3 / iPhone 4 / iOS 6.1 / by Operator
REM a bit slow...
OPTION IMAGE POS CENTRAL
OPTION ANGLE DEGREES
GRAPHICS
GRAPHICS CLEAR 0,0,0
scw.h = SCREEN_WIDTH()/2
sch.h = SCREEN_HEIGHT()/2
angle_inc = 30 'swirl-factor
rr = 100 '+/- HALF range/radius of
'picture-pixels to be swirled,
sc.x1 = scw.h 'x-centre of source image
sc.y1 = 120 'y-centre of source image
tc.x1 = scw.h 'x-centre of target image
tc.y1 = 300 'y-centre of target image
FIELD "info" TEXT "" AT 0,0 SIZE 200,20 RO
FIELD "info" FONT COLOR 1,1,1
FIELD "info" BACK ALPHA 0
'draw rect over source data, scale fac. 2
DRAW COLOR 1,1,1
DRAW RECT sc.x1,sc.y1 SIZE 5+rr/2,5+rr/2
DRAW COLOR 1,0,0
DRAW SIZE 3
DRAW LINE sc.x1,sc.y1-rr/2 TO sc.x1,sc.y1+rr/2
IMAGE$ = "/Examples/Graphics/images/snowflake.png"
DRAW IMAGE IMAGE$ AT sc.x1, sc.y1 SCALE 0.95 ANGLE 30
FIELD "info" TEXT "Data to be acquiered"
'color r g b -> cr, cg, cb array for the pixels
maxx = (2*(rr+1))^2
DIM cr(maxx) ! DIM cg(maxx) ! DIM cb(maxx)
'sin cos look up tables -> st / ct arrays
pi = ATN(1)*4
range = 359
DIM st(range+1) ! DIM ct(range+1)
FOR x = 0 TO range
st(x) = SIN(x)
ct(x) = COS(x)
NEXT x
'distance lookup-table
DIM distance_lut(rr+1,rr+1)
FOR x = 0 TO rr
FOR y = 0 TO rr
distance_lut(x,y) = SQRT(x^2 + y^2)
NEXT y
NEXT x
'store picture color data, scale factor = 2
FOR x = -rr TO rr
FOR y = -rr TO rr
i = i+1
GET PIXEL x+2*sc.x1,y+2*sc.y1 COLOR r,g,b
cr(i)=r ! cg(i)=g ! cb(i)=b
' get pixel can't store into array (?)
NEXT y
NEXT x
'draw rect of target (swirled data)
DRAW COLOR 1,1,1
DRAW SIZE 1
DRAW RECT tc.x1,tc.y1 SIZE 5+rr/2,5+rr/2
FIELD "info" TEXT "Swirling Data..."
REFRESH OFF
LOOP:
a = (a + angle_inc)%range
i=0
FOR x = -rr TO rr
FOR y = -rr TO rr
i=i+1
'limit swirl to circular shape
distance = distance_lut(ABS(x),ABS(y))
IF distance <= rr THEN
ANGLE = INT(a*(rr-distance)/rr)
rotatedx = x*ct(ANGLE) - y*st(ANGLE)
rotatedy = x*st(ANGLE) + y*ct(ANGLE)
DRAW PIXEL rotatedx+2*tc.x1, rotatedy+2*tc.y1 COLOR cr(i),cg(i),cb(i)
END IF
NEXT y
REFRESH
NEXT x
GOTO LOOP