Fractaler V1.3

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

Fractaler V1.3

Post by rbytes » Sun Mar 18, 2018 6:29 pm

The original Fractaler worked on all devices. When I modified it to add more options, I hard-coded the x,y positions and sizes of interface objects (sliders, button, fields). That removed compatibility with devices other than iPad.

I have applied my scaling algorithm to all x,y locations, sizes, font sizes, etc. so that version 1.3 is again compatible with all iOS devices. The screen shot is from my iPhone 6. Also shown is the saved fractal image.

Code: Select all

'Fractaler V1.3
'fractal browser
'by Mr.Kibernetik, 2014
'V1.3 Now works on all iOS devices
'V1.2  Additional controls and options by rbytes, March 2018
'V1.1 Palet-function (simplified) added by Dutchman, February 2014
'
'g'---- parameters to change colour palette
REVERSE=0 '0 OR 1
touched.shift=1  ' between 0 and 1 (hue start color)
touched.gain=1 ' larger than 0 (hue step distance)
touched.param1=5 ' 2 to 5 (basic shape of fractal)
touched.param2=80 ' 0 to 80 (iterations of fractal)
''------------------------

SET TOOLBAR OFF
SET BUTTONS CUSTOM
GET SCREEN SIZE sw,sh
dev$=DEVICE_TYPE$()

init
LOOP: DRAWIT
wait: SLOWDOWN!IF touched THEN LOOP ELSE wait

DEF touched
IF SLIDER_CHANGED("hue") THEN
  shift=SLIDER_VALUE("hue")
  touched =1
  RETURN
END IF
IF SLIDER_CHANGED("gain") THEN
  gain=SLIDER_VALUE("gain")*5
  touched =1
  RETURN
END IF
IF SLIDER_CHANGED("param1") THEN
  param1=SLIDER_VALUE("param1")*3+2
  GRAPHICS CLEAR
  touched =1
  RETURN
END IF
IF SLIDER_CHANGED("param2") THEN
  param2=SLIDER_VALUE("param2")*40+40
  GRAPHICS CLEAR
  touched =1
  RETURN
END IF
IF SLIDER_CHANGED("step") AND SLIDER_VALUE("step")<>init.old_slider THEN
  p=0.2
  PAUSE p
  WHILE SLIDER_CHANGED("step") ! PAUSE p ! END WHILE
  GRAPHICS CLEAR
  sv=SLIDER_VALUE("step")
  init.old_slider=sv
  scr.STEP=INT(sv*(scr.maxstep-1))+1
  touched=1
  RETURN
END IF
touched=0
first0=1
first1=1
LOOP: GET TOUCH 0 AS x0,y0
IF BUTTON_PRESSED("Save") THEN
  SPRITE "frac" SAVE "frac.png"
  ALBUM EXPORT "frac.png"
END IF
IF BUTTON_PRESSED("clr") THEN
  BUTTON "clr" TEXT "🔘"
  BUTTON "clr2" TEXT "⚪️"
  BUTTON "clr3" TEXT "⚪️"
  cr=0!BACKER
ENDIF
IF BUTTON_PRESSED("clr2") THEN
  BUTTON "clr" TEXT "⚪️"
  BUTTON "clr2" TEXT "🔘"
  BUTTON "clr3" TEXT "⚪️"
  cr=1!BACKER
ENDIF
IF BUTTON_PRESSED("clr3") THEN
  BUTTON "clr" TEXT "⚪️"
  BUTTON "clr2" TEXT "⚪️"
  BUTTON "clr3" TEXT "🔘"
  cr=2!BACKER
ENDIF
IF BUTTON_PRESSED("Stop") THEN END
IF x0>-1 THEN
  GRAPHICS CLEAR
  IF first0 THEN
    first0=0
    xi0=x0 ! yi0=y0
    ss=1
  END IF
  sx=x0-xi0 ! sy=y0-yi0
  GET TOUCH 1 AS x1,y1
  IF x1>-1 THEN
    GRAPHICS CLEAR
    IF first1 THEN
      first1=0
    disi=dist(x0,y0,x1,y1)
    END IF
    dis=dist(x0,y0,x1,y1)
    ss=dis/disi
  END IF
  SPRITE "frac" AT sx,sy SCALE ss
  GOTO LOOP
END IF
IF first0=0 THEN
  frac.s/=ss
  frac.x-=sx*frac.s
  frac.y-=sy*frac.s
  SPRITE "frac" HIDE
  SPRITE "frac" AT 0,0
  touched=1
END IF
END DEF

DEF calc(x,y,param1,param2)
z=0
c=x+y*1i
COUNT=0
maxcount=param2*LOG10(INT(1/frac.s))
WHILE ABS(z)<2 AND COUNT<=maxcount
  z=z^param1+c    ' was ^2
  COUNT+=1
END WHILE
IF COUNT>maxcount THEN
  fa=0
  col.r=1 ! col.g=1 ! col.b=1
ELSE
  fa=1
'r'
  prop=COUNT/maxcount
  IF .REVERSE THEN prop=1-prop
  CALL Palet(touched.gain*prop+touched.shift)
  col.r=Palet.R ! col.g=Palet.G ! col.b=Palet.B
''
END IF
END DEF

DEF DRAWIT
maxxs=scr.width ! maxys=scr.height
xc=maxxs/2 ! yc=maxys/2
SPRITE "frac" BEGIN
again: GRAPHICS CLEAR
REFRESH
SPRITE "frac" SHOW
BACKER
FOR ys=0 TO maxys STEP scr.STEP
  IF BUTTON_PRESSED("Stop") THEN END
  y=frac.y+(ys-yc)*frac.s
  FOR xs=0 TO maxxs STEP scr.STEP
    IF touched THEN again
    x=frac.x+(xs-xc)*frac.s
      calc(x,y,touched.param1,touched.param2)
      FILL ALPHA calc.fa
      FILL COLOR col.r,col.g,col.b
      FILL RECT xs,ys TO xs+scr.STEP,ys+scr.STEP
    NEXT xs
  NEXT ys
SPRITE "frac" END
END DEF
  
DEF BACKER
  IF touched.cr=0 THEN GRAPHICS CLEAR
  IF touched.cr=1 THEN GRAPHICS CLEAR 1,1,1
  IF touched.cr=2 THEN GRAPHICS CLEAR 0,0,0
END DEF

DEF init
PRINT "Pan and pinch..."
PAUSE 1
GRAPHICS
GRAPHICS CLEAR
DRAW FONT SIZE 20*rw
scr.width=SCREEN_WIDTH()
scr.height=SCREEN_HEIGHT()
IF .dev$="iPad" THEN vshift=0 ELSE vshift=10
rw=scr.width/1024! rh=scr.height/768
scr.maxstep=scr.width/40
scr.STEP=scr.maxstep
frac.x=-0.5 ! frac.y=0 ! frac.s=3/scr.width
SPRITE "frac" BEGIN scr.width,scr.height
SPRITE "frac" END
SLIDER "step" VALUE 1 AT 120*rw,scr.height-60*rh-vshift SIZE scr.width-160*rw
SLIDER "hue" VALUE 1 AT 120*rw,scr.height-100*rh-vshift SIZE scr.width/2-150*rw
SLIDER "gain" VALUE 1 AT scr.width/2 + 110*rw,scr.height-100*rh-vshift SIZE scr.width/2-150*rw
SLIDER "param1" VALUE 3 AT 120*rw,scr.height-140*rh-vshift SIZE scr.width/2-150*rw
SLIDER "param2" VALUE 3 AT scr.width/2 + 110*rw,scr.height-140*rh-vshift SIZE scr.width/2-150*rw
FIELD "step" TEXT " DET" AT 50*rw, scr.height-60*rh SIZE 50*rw,30*rh RO
FIELD "step" FONT SIZE 18*rw
FIELD "hue" TEXT " HUE" AT 50*rw, scr.height-100*rh SIZE 50*rw,30*rh RO
FIELD "hue" FONT SIZE 18*rw
FIELD "gain" TEXT " GAIN" AT scr.width/2 + 50*rw, scr.height-100*rh SIZE 50*rw,30*rh RO
FIELD "gain" FONT SIZE 18*rw
FIELD "prm1" TEXT " SHP" AT 50*rw, scr.height-140*rh SIZE 50*rw,30*rh RO
FIELD "prm1" FONT SIZE 18*rw
FIELD "prm2" TEXT " DEP" AT scr.width/2 + 50*rw, scr.height-140*rh SIZE 50*rw,30*rh RO
FIELD "prm2" FONT SIZE 18*rw
FIELD "bg" TEXT " BG  Clear          White           Black" AT 50*rw, scr.height-190*rh SIZE 330*rw,40*rh RO
FIELD "bg" FONT SIZE 18*rw
DRAW COLOR 0,0,0
SET BUTTONS FONT SIZE 18*rw
BUTTON "Save" TEXT "SAVE" AT scr.width-220*rw,580*rh SIZE 85*rw,35*rw
BUTTON "clr" TEXT "🔘" AT 140*rw,580*rh  SIZE 35*rw,35*rh
BUTTON "clr2" TEXT "⚪️" AT 240*rw,580*rh SIZE 35*rw,35*rh
BUTTON "clr3" TEXT "⚪️" AT 340*rw,580*rh SIZE 35*rw,35*rh
BUTTON "Stop" TEXT "STOP" AT scr.width-120*rw,580*rh SIZE 85*rw,35*rw
FILL ALPHA 1
R = 255/255 ! G = 210/255 ! B = 190/255 'coloring
old_slider=-1
END DEF

DEF dist(x0,y0,x1,y1)=SQR((x0-x1)^2+(y0-y1)^2)

'r' ===== Simplified Palette-function
DEF Palet(Tint) ' simplified
REM parameter should be between zero and 1.
tint%=1
' ---- divide in 6 sections
tint*=6 ! section=INT(0.5+tint) ! tint%=1
ON Section GOTO S1,S2,S3,S4,S5,S6
S1: ! B=1 ! R=0 ! G=tint ! GOTO Sat
S2: ! G=1 ! R=0 ! B=1-tint ! GOTO Sat
S3: ! G=1 ! B=0 ! R=tint ! GOTO Sat
S4: ! R=1 ! B=0 ! G=1-tint ! GOTO Sat
S5: ! R=1 ! G=0 ! B=tint ! GOTO Sat
S6: ! B=1 ! G=0 ! R=1-tint
Sat:
END DEF ' Palet
''
Attachments
19346CC9-2A13-4316-8FB7-411E18C19796.jpeg
19346CC9-2A13-4316-8FB7-411E18C19796.jpeg (156.2 KiB) Viewed 1532 times
B8910E3F-D409-439D-93D4-6502420F19E8.jpeg
B8910E3F-D409-439D-93D4-6502420F19E8.jpeg (89.58 KiB) Viewed 1532 times
####### Living the colorful life #######

Post Reply