Turtle graphics

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 »

Slow Shadow Turtle Graphics screenshot:

Image

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:I think "Pro" version could have slider for Dutchman's setting...
Действительно! И Владимир Фант можно добавить хорошую графику. Пример: черепаха спрайт и хороший поле трава с некоторыми препятствиями, черепахи, которые затем будут запрограммированной случайное блуждание с обнаружением коллизий. (Г-н Фант, ты с нами?)

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 »

ДА! :D

User avatar
Фант
Posts: 1363
Joined: Sat Nov 30, 2013 10:01 am
My devices: iPad 4 (iOS 9.3), iMac (MAC OS 11.03)
Location: Россия,Санкт-Петербург
Flag: Russia
Contact:

Re: Turtle graphics

Post by Фант »

Henko wrote:
Mr. Kibernetik wrote:I think "Pro" version could have slider for Dutchman's setting...
Действительно! И Владимир Фант можно добавить хорошую графику. Пример: черепаха спрайт и хороший поле трава с некоторыми препятствиями, черепахи, которые затем будут запрограммированной случайное блуждание с обнаружением коллизий. (Г-н Фант, ты с нами?)
Ik ben met u alleen een beetje later! :D

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 »

Now with slider and automatic scaling for different devices.
What is next :?: :D

Code: Select all

' Turtle graphics 20141001
' Coded for Smart Basic by Henko
' Slow Turtle modification by Mr.K
' Dutchman added settings, slider and auto-scaling
' Shadow added by Henko (on special request by Mr.K)
'===== settings ======
delay=0.0
shadows=0 ' 1 or 0
direction=1 ' 1=ClockWise, -1=counterCW
bcolor(1,1,0) ' background r,g,b
dcolor(1,0,0) ' drawing color
border=4 ' size of edge
'---------------------
sw=screen_width()
sh=screen_height()
size=min(sw,sh)/2.5
dy=size/20 'offset for slider
t_init(shadows)
count=countvalue
begin:
angle=-direction*360/count
t.s=3*size/count
for i=1 to count
  for j=1 to count ! t_step(angle) ! pause delay ! next j
  t_turn(angle,0)
  next i
' wait for slider change
wait:
if button_pressed("stop") then end
if slider_changed("count") then
  do ! until slider_changed("count")<>1
  newcount=countvalue
else ! goto wait
endif
if newcount=count then wait
count=newcount
clearcanvas(border)
goto begin
end

def countvalue
countvalue=3+int(18*slider_value("count"))
end def

def t
x=0 ! y=0 ! s=0 ! a=0
end def

def t_move(continue)
dis=continue*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_step(angle)
t.a+=angle ! t_move(1)
end def

def t_turn(angle,continue)
t.a+=angle ! t_move(continue)
end def

def bcolor(r,g,b)
.rb=r ! .gb=g ! .bb=b
end def

def dcolor(r,g,b)
.rt=r ! .gt=g ! .bt=b
end def

def clearcanvas(edge)
graphics clear 0,0,0
fill color .rb,.gb,.bb
fill rect edge,edge to 2*.size-edge,2*.size-edge
end def

def t_init(withshadow)
graphics ! graphics clear ! option angle degrees
.xc=.size ! .yc=.size
t.x=.xc ! t.y=.yc ! t.a=0
sprite "turtle" begin 2*.size,2*.size
clearcanvas(.border)
sprite end
option sprite pos central
sprite "turtle" at .sw/2,.sh/2-.dy
sprite "turtle" show
sprite "turtle" begin
iy=.sh/2+.size ! bwidth=.size/4 ! bx=.sw/2+.size-bwidth
slider "count" value 0.5 at .sw/2-.size,iy hsize 2*.size-bwidth
set buttons custom ! draw color 1,1,0 ! fill color 1,0,0
button "stop" title "STOP" at bx,iy-dy size bwidth,dy
draw color .rt,.gt,.bt ! draw size 2
if withshadow then shadow on
draw to t.x,t.y
end def
Attachments
screenshot with slider and stop button
screenshot with slider and stop button
turtle.PNG (199.01 KiB) Viewed 4948 times
Last edited by Dutchman on Wed Oct 01, 2014 8:09 pm, edited 1 time in total.

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 »

Cool! This is real Pro version.
There is WITHSHADOW mistype in the very end of a program.

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 »

Sorry and thanks for testing :!:
The code is corrected now.

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 »

What is next ?

I know what is next on my side.

1st extention:
I will give the turtle a "personality" (intelligent behaviour) by using a Markov chain. The entire behaviour of the turtle is then "packed" in a matrix with certain properties.
The turtle itself will be shown in the area, not its path. In my program the turtle will be a simple little square, as I am not interested in high level graphics and sprites (I will happily leave that to our "king of graphics"). I will use a function to draw the turtle in order that it can easily be replaced by a nice sprite turtle.
The field will have black circles as obstructions an green circles where the turtle can feed.

2nd extention:
More than 1 turtle. An array of turtles :lol: the Markov chain will be extended to contain mating and birth of new turtles on the geen islands. Death due to aging and fights (when colliding) will be introduced. So, a turtle population can be simulated and be studied, making variations in the transition probabilities in the Markov matrix.
But again, don't expect any nice graphics from my side.

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 »

Sounds very academic :!:

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 would only suggest that Tutle Life simulator will be a separate project - it differs greatly from this ornament generator.

Post Reply