Turtle graphics
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Turtle graphics
Slow Shadow Turtle Graphics screenshot:
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Turtle graphics
Действительно! И Владимир Фант можно добавить хорошую графику. Пример: черепаха спрайт и хороший поле трава с некоторыми препятствиями, черепахи, которые затем будут запрограммированной случайное блуждание с обнаружением коллизий. (Г-н Фант, ты с нами?)Mr. Kibernetik wrote:I think "Pro" version could have slider for Dutchman's setting...
- Фант
- Posts: 1363
- Joined: Sat Nov 30, 2013 10:01 am
- My devices: iPad 4 (iOS 9.3), iMac (MAC OS 11.03)
- Location: Россия,Санкт-Петербург
- Flag:
- Contact:
Re: Turtle graphics
Ik ben met u alleen een beetje later!Henko wrote:Действительно! И Владимир Фант можно добавить хорошую графику. Пример: черепаха спрайт и хороший поле трава с некоторыми препятствиями, черепахи, которые затем будут запрограммированной случайное блуждание с обнаружением коллизий. (Г-н Фант, ты с нами?)Mr. Kibernetik wrote:I think "Pro" version could have slider for Dutchman's setting...
- Dutchman
- Posts: 851
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Turtle graphics
Now with slider and automatic scaling for different devices.
What is next
What is next
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
- turtle.PNG (199.01 KiB) Viewed 4941 times
Last edited by Dutchman on Wed Oct 01, 2014 8:09 pm, edited 1 time in total.
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Turtle graphics
Cool! This is real Pro version.
There is WITHSHADOW mistype in the very end of a program.
There is WITHSHADOW mistype in the very end of a program.
- Dutchman
- Posts: 851
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Turtle graphics
Sorry and thanks for testing
The code is corrected now.
The code is corrected now.
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Turtle graphics
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 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.
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 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.
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Turtle graphics
Sounds very academic
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Turtle graphics
I would only suggest that Tutle Life simulator will be a separate project - it differs greatly from this ornament generator.