Kaleidoscope V1

Post Reply
User avatar
rbytes
Posts: 1906
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Kaleidoscope V1

Post by rbytes » Tue Mar 12, 2019 5:52 pm

Here is a simple kaleidoscope program. It cuts a pie segment from an image, makes a sprite from it, then rotates the sprite and stamps it to draw the kaleidoscope. This is the first in a series. I will be adding an interface to allow adjustment of many parameters, and the capability to load source images and save the final results.
3A374A29-ACB8-41EC-BB34-0BADCE049608.png
3A374A29-ACB8-41EC-BB34-0BADCE049608.png (3.32 MiB) Viewed 66 times
For now, you can play with the code and see what variations are available. Uncomment the ALBUM EXPORT line to save your results.

I have attached the source image I used, "pixelfractal.png"
pixelfractal.png
pixelfractal.png (1.71 MiB) Viewed 66 times

Code: Select all

/*
Kaleidoscope V1
rbytes, March 2019
Thanks to Henko for fill segment code
Draws a kaleidoscope from any image
**************************************************
V1 proof of concept, no interface
iPad, iPhone, iPod
*/

SET TOOLBAR OFF
SET ORIENTATION LANDSCAPE
OPTION SPRITE POS CENTRAL
OPTION IMAGE POS CENTRAL
OPTION ANGLE DEGREES
OPTION BASE 1
FILL COLOR 1,0,0
GET SCREEN SIZE sw,sh
GRAPHICS
GRAPHICS CLEAR
pause .1
refresh off

gosub draw

GRAPHICS SAVE 120,0,sw-240,sh to "kaleido.png"
'ALBUM EXPORT "kaleido.png"

wait:SLOWDOWN!GET TOUCH 0 AS tx,ty!IF tx=-1 THEN wait
IF laun$="desktop" THEN
  IF FILE_EXISTS("/launch") THEN
    RUN "/-Launch.sb"
  ELSE
    EXIT
  ENDIF
ENDIF
END

' xc,yc is centre of the circle
' ri,ru are radii of inner and outer circle arcs
' alfo,alfe start and ending angle for segment
'

draw:
fill rect 0,0 to sw,sh
GRAPHICS MODE DESTOUT
xc=sw/2!yc=sh/2!ri=0!ru=380
FILL COLOR 1,0,0
alfo=75!alfe+=105
fill_segment (xc,yc,ri,ru,alfo,alfe)
SPRITE "stamp" SCAN 0,0, sw,sh
SPRITE "stamp" at sw/2,sh/2
GRAPHICS MODE NORMAL
DRAW IMAGE "pixelfractal.png" at SW/2,sh/2 angle angle
refresh on
pause 2
GRAPHICS MODE DESTOUT
SPRITE "stamp" stamp
SPRITE "kal" SCAN sw/2-103,0,206,sh
SPRITE "kal" at sw/2,sh/2
GRAPHICS CLEAR
GRAPHICS MODE NORMAL
SPRITE "kal" FLIP 1
SPRITE "kal" STAMP
SPRITE "lak" SCAN sw/2-103,0,206,sh
SPRITE "lak" at sw/2,sh/2
sprite "lak" show
SPRITE "kal" FLIP 1
SPRITE "kal" hide
SPRITE "lak" HIDE
refresh on
for t=0 to 360 step 30
SPRITE "kal" at sw/2,sh/2 ANGLE t
SPRITE "lak" at sw/2,sh/2 ANGLE t
k=1-k
if k then SPRITE "lak" stamp else SPRITE "kal" stamp
pause .2
next t
refresh on
return


DEF fill_segment (xc,yc,ri,ru,alfo,alfe)
DIM xx(14),yy(14)
xx(1)=xc+ru*COS(alfe) ! yy(1)=yc-ru*SIN(alfe)
xx(2)=xc+ri*COS(alfe) ! yy(2)=yc-ri*SIN(alfe)
xx(3)=xc+ri*COS(alfo) ! yy(3)=yc-ri*SIN(alfo)
i=4
FOR alf=alfo TO alfe STEP (alfe-alfo)/6
  xx(i)=xc+ru*COS(alf) ! yy(i)=yc-ru*SIN(alf) ! i+=1
  NEXT alf
FILL POLY xx,yy COUNT 9
END DEF
Last edited by rbytes on Wed Mar 13, 2019 4:54 am, edited 1 time in total.
####### Living the colorful life #######

User avatar
Mr. Kibernetik
Site Admin
Posts: 4495
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPad, iPhone, MacBook
Location: Russia
Flag: Russia

Re: Kaleidoscope V1

Post by Mr. Kibernetik » Tue Mar 12, 2019 6:03 pm

Looks really caleidoscopic!

User avatar
rbytes
Posts: 1906
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Kaleidoscope V1

Post by rbytes » Tue Mar 12, 2019 6:42 pm

Yes. I have several later versions completed that give larger output sizes.

I think I will add some comments to explain the processing. In a way it is like stamping a vinyl recording. I have to make a negative master first, and then use it to stamp the pie segment from the fractal photograph.
####### Living the colorful life #######

Post Reply