A little program, producing an astonishing graphics variety.
Translated from SPL into SB. The SPL program is at the end of the listing.
The picture has been zoomed in somewhat to displat more details
graphics ! graphics clear 1,1,1
a=1 ! b=3 ! dt=0.2
get screen size w,h
n=0
for i=0 to h/10
for j=0 to w/10
x=j ! y=i
for k=1 to 100
xn=x-sin(y+a*sin(b*y))*dt
yn=y+sin(x+a*sin(b*x))*dt
x=xn ! y=yn
pal(n%360)
draw pixel 10*x,10*y color pal.r, pal.g, pal.b
n+=0.001*w
next k
next j
next i
end
def pal(t)
r=0 ! g=0 ! b=0
if t<120 or t>240 then r=palsub(abs(t-360*floor(t/240)))
if t<240 then g=palsub(abs(t-120))
if t>120 then b=palsub(abs(t-240))
end def
def palsub(e)
f=.5 ' 0<=f<=1 better balance between prim. and sec. colors
if e<60 then c=1 else ! x=(120-e)/60 ! c=x*(1+f-f*x) ! end if
return c
end def
/*
a = 1 ; b = 3 ; dt = 0.1 'change me
w,h = #.scrsize()
n = 0
> i, 0..h/10
> j, 0..w/10
x = j ; y = i
> k, 1..100
x,y = f(x,y)
#.drawpoint(x*10,y*10, #.hsv2rgb(n,1,1):3)
n += 0.001*w
<
<
<
f(x,y) <= x-#.sin(y+.a*#.sin(.b*y))*.dt, y+#.sin(x+.a*#.sin(.b*x))*.dt
*/
Thanks for the translation. I can see where I made errors in mine.
Now that I have your working example, I adapted it to draw in points rather than pixels. The lines are thicker now, but the colors show up more intensely. I adjusted the loop start and end points to fill my iPad screen.
Tapping the screen at any time during the drawing will stop the program.
set toolbar off
graphics ! graphics clear 1,1,1
sz=1
draw size sz
a=1 ! b=6 ! dt=0.1 /*original a=1 ! b=6 ! dt=0.1*/
get screen size w,h
n=0
for i=0 to h/9
for j=0 to w/9
x=j ! y=i
for k=1 to 100
xn=x-sin(y+a*sin(b*y))*dt
yn=y+sin(x+a*sin(b*x))*dt
x=xn ! y=yn
pal(n%360)
draw color pal.r, pal.g, pal.b
draw line 10*x-sz,10*y-sz to 10*x,10*y
n+=0.001*w
next k
next j
GET TOUCH 0 AS tx,ty
if tx<>-1 then end
next i
DO
SLOWDOWN
GET TOUCH 0 AS tx,ty
UNTIL tx<>-1
end
def pal(t)
r=0 ! g=0 ! b=0
if t<120 or t>240 then r=palsub(abs(t-360*floor(t/240)))
if t<240 then g=palsub(abs(t-120))
if t>120 then b=palsub(abs(t-240))
end def
def palsub(e)
f=.5 ' 0<=f<=1 better balance between prim. and sec. colors
if e<60 then c=1 else ! x=(120-e)/60 ! c=x*(1+f-f*x) ! end if
return c
end def
Attachments
58C88F81-84B7-46DE-9163-5CD0DF570156.png (6.66 MiB) Viewed 3203 times
SPL pixel mode (1920 x 1280 pixels)
46 seconds
56 seconds when tap to stop feature added
SPL point mode (960 x 640 Points)
22 seconds
26 seconds when tap to stop feature added
Smart Basic pixel mode (2048 x 1536 pixels)
113 seconds
with tap to stop feature
Smart Basic point mode (1024 x 768 points)
48 seconds
with tap to stop feature
SPL is the clear speed winner, although there are a lot of variables.
- my CHUWI Windows tablet has a slower processor than my iPad. Advantage: iPad/SB
- SPL has a command that Smart Basic has no equivalent for, called #.hsv2rgb. It does the HSV to RGB conversion for every pixel, using compiled code rather than the interpreted code of a function in Smart Basic. Advantage: Windows/SPL
- my CHUWI Windows tablet has a smaller screen to update, containing 2,457,600 pixels. My iPad screen has 3,145,728 pixels, or 1.28 times as many as the Window's tablet's screen. Advantage: Windows/SPL
- detecting a tap at the end of each row of pixels or points (to allow ending the program if partial results are unsatisfactory) slows down both devices. Advantage: none
Regarding the speed test:
The big difference is caused by the use of the pal() function in SB to set the color for each point.
I ran a test commenting out the use of the pal() function and setting the color for each point with the SB command DRAW COLOR 0,0,0. This is comparable (timewise) with the SPL version.
Time with the pal() command: 64 seconds,
Time with the draw color command: 22 seconds.
That's a factor 3
On your (faster) iPad, the adapted SB code should complete the screen in about 48/3= 16 seconds.
Of course this produces a black and white pic.