Turtle graphics

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Turtle graphics

Post 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

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

Re: Turtle graphics

Post by Mr. Kibernetik »

Very nice ornament!

Image

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

Re: Turtle graphics

Post 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

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Turtle graphics

Post by Henko »

Of course. After all it is a turtle! :)

Dalede
Posts: 131
Joined: Fri Dec 28, 2012 4:00 pm
Location: Grass Valley, CA, USA
Contact:

Re: Turtle graphics

Post by Dalede »

Nice, thanks.

Dale

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Turtle graphics

Post 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
Attachments
display for count=8
display for count=8
count 8.PNG (7.96 KiB) Viewed 5241 times

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

Re: Turtle graphics

Post by Mr. Kibernetik »

Try to add shadows (my favorite option)!

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Turtle graphics

Post by Henko »

Mr. Kibernetik wrote:Try to add shadows (my favorite option)!
I tried, and here you are! :mrgreen:

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

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Turtle graphics

Post 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

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

Re: Turtle graphics

Post by Mr. Kibernetik »

I think "Pro" version could have slider for Dutchman's setting...

Post Reply