Page 1 of 3
Turtle graphics
Posted: Fri Sep 26, 2014 8:44 am
by Henko
Code: Select all
' Turtle graphics
'
if device_type$()="iPad" then
t_init(0,50,100,100,600,600,.8,.8,.8,1,0,0)
else
t_init(0,30,20,20,300,300,.8,.8,.8,1,0,0)
end if
for i=1 to 12
for j=1 to 12 ! t_right(30) ! next j
t_turn(30,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def
Re: Turtle graphics
Posted: Fri Sep 26, 2014 9:12 am
by Mr. Kibernetik
Very nice ornament!
Re: Turtle graphics
Posted: Fri Sep 26, 2014 11:46 am
by Mr. Kibernetik
This is my modification:
Code: Select all
' Slow Turtle graphics
'
if device_type$()="iPad" then
t_init(0,50,100,100,600,600,.8,.8,.8,1,0,0)
else
t_init(0,30,20,20,300,300,.8,.8,.8,1,0,0)
end if
for i=1 to 12
for j=1 to 12 ! t_right(30) ! pause .05 ! next j
t_turn(30,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def
Re: Turtle graphics
Posted: Fri Sep 26, 2014 2:51 pm
by Henko
Of course. After all it is a turtle!
Re: Turtle graphics
Posted: Fri Sep 26, 2014 8:32 pm
by Dalede
Nice, thanks.
Dale
Re: Turtle graphics
Posted: Mon Sep 29, 2014 5:29 pm
by Dutchman
I added multimode.
I could not test it on iPhone, so I hope it is OK.
The screenshot is for count=8.
Code: Select all
' Turtle graphics 20140928
' Coded for Smart Basic by Henko
' Slow Turtle modification by Mr.K
' Multimode settings by Dutchman
'===== settings ======
delay=0.02
count=8
'---------------------
angle=360/count
if device_type$()="iPad" then
t_init(0,5/3*angle,100,100,600,600,.8,.8,.8,1,0,0)
else
t_init(0,angle,20,20,300,300,.8,.8,.8,1,0,0)
end if
for i=1 to count
for j=1 to count ! t_right(angle) ! pause delay ! next j
t_turn(angle,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def
Re: Turtle graphics
Posted: Mon Sep 29, 2014 5:38 pm
by Mr. Kibernetik
Try to add shadows (my favorite option)!
Re: Turtle graphics
Posted: Tue Sep 30, 2014 6:37 am
by Henko
Mr. Kibernetik wrote:Try to add shadows (my favorite option)!
I tried, and here you are!
Code: Select all
' Turtle graphics 20140928
' Coded for Smart Basic by Henko
' Slow Turtle modification by Mr.K
' Multimode settings by Dutchman
' Shadow added by Henko (on special request by Mr.K)
'===== settings ======
delay=0.02
count=8
'---------------------
angle=360/count
if device_type$()="iPad" then
t_init(0,5/3*angle,100,100,600,600,.8,.8,.8,1,0,0)
else
t_init(0,angle,20,20,300,300,.8,.8,.8,1,0,0)
end if
for i=1 to count
for j=1 to count ! t_right(angle) ! pause delay ! next j
t_turn(angle,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
shadow on
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def
Re: Turtle graphics
Posted: Tue Sep 30, 2014 6:47 am
by Henko
Or, better still, following the "settings" method of Dutchman :
Code: Select all
' Turtle graphics 20140928
' Coded for Smart Basic by Henko
' Slow Turtle modification by Mr.K
' Multimode settings by Dutchman
' Shadow added by Henko (on special request by Mr.K)
'===== settings ======
delay=0.01
count=12
shadow$="yes"
'---------------------
angle=360/count
if device_type$()="iPad" then
t_init(0,5/3*angle,100,100,600,600,.8,.8,.8,1,0,0,shadow$)
else
t_init(0,angle,20,20,300,300,.8,.8,.8,1,0,0,shadow$)
end if
for i=1 to count
for j=1 to count ! t_right(angle) ! pause delay ! next j
t_turn(angle,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt,s$)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
if s$="yes" then shadow on
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def
Re: Turtle graphics
Posted: Tue Sep 30, 2014 6:53 am
by Mr. Kibernetik
I think "Pro" version could have slider for Dutchman's setting...