09-03-2022, 12:26 PM
I expect you all have already seen turtle graphics on other websites.
I decided to try it on NaaLaa. (Good for fighting boredom.)
It involves drawing lines from a start position, using an angle plus a distance.
Feel free to use any code that looks interesting. I have a long way to go, and it may take awhile.
I decided to try it on NaaLaa. (Good for fighting boredom.)
It involves drawing lines from a start position, using an angle plus a distance.
Feel free to use any code that looks interesting. I have a long way to go, and it may take awhile.
Code:
visible p2 = PI * 2.0
visible pen = 0
visible tx = 0 ' turtle x
visible ty = 0
visible anglet = 0.0 ' The angle that the turtle is pointing
visible angletd = 0
visible cost = 0.0
visible sint = 0.0
visible d1 = p2 / 360 ' 1 degree angle
set redraw 0
' 1368,768 my display size
set window " Turtle graphics ",1368,768,1
pen = 0
hexagon(600,400,100)
set color 0,0,255
circle(600,400,200)
wait 5000
startangle = 20 ; clr = 0
for cnt = 1 to 100
spiral1(600,400,startangle)
startangle = startangle + 10
if startangle > 360 then startangle = 0
zcolor (clr)
clr = clr + 1
if clr > 36 then clr = 0
wait 1
cls
next
while not keydown(KEY_ESCAPE) fwait 60
function plotline ( x1,y1,x2,y2,steps )
ct = 1
for cnt = 1 to steps
draw ellipse x1,y1,ct,ct
ct = ct + 1
if ct > 40 then ct = 1
y1=y1 - sin ( anglet )
x1=x1 + cos ( anglet )
next
endfunc
function move ( steps )
x = tx ; y = ty
ty = ty - (sin(anglet) * steps)
tx = tx + (cos(anglet) * steps)
if pen = 1 then plotline (x,y,tx,ty,steps)
endfunc
function rturn ( degrees )
anglet = anglet - degrees * d1
angletd = angletd + degrees
' anglet = anglet + rad(degrees)
sint= sin(anglet)
cost = cos(anglet)
endfunc
function lturn ( degrees )
angletd = angletd + degrees
anglet = anglet + rad(degrees)
sint= sin(anglet)
cost = cos(anglet)
endfunc
function locate ( x,y ,angle )
tx = x
ty = y
angletd = angle
anglet = angletd * d1
sint= sin(anglet)
cost = cos(anglet)
endfunc
function spiral(x,y)
pen = 0; a1 =20.0; a2 = 0.01; a3 = 0.01; m1 = 1.1; m2 = 4.1; m3 = 0.3; locate ( x,y,0 ); pen = 1
z = 1
pen = 0; a2 = 0.01; a3 = 0.01; m1 = 1.1; m2 = 4.1; m3 = 0.3; locate ( x,y,0 )
pen = 1
for cnt = 1 to 1200
zcolor(z)
move(m1 + m2)
lturn(a1-a2)
a2 = a2 + a3
m2 = m2 + 0.1
if ty < 0 then break
z = z + 1
if z > 38 then z = 1
next
redraw
endfunc
function spiral2(x,y)
angle =60
subangle = 0.01
m1=20.0
c3 = 0.01
pen = 0
locate ( x,y,0 )
pen = 1
for cnt = 1 to 400
move(m1)
lturn(angle - subangle)
m1 = m1 + 0.001
if cnt > 20 then subangle = subangle + 0.1
if cnt< 10 then subangle = subangle + 01.1
redraw
next
endfunc
function spiral1(x,y,a1)
pen = 0; a2 = 0.01; a3 = 0.01; m1 = 1.1; m2 = 4.1; m3 = 0.3; locate ( x,y,0 ); pen = 1
z = 1
pen = 0; a2 = 0.01; a3 = 0.01; m1 = 1.1; m2 = 4.1; m3 = 0.3; locate ( x,y,0 )
pen = 1
for cnt = 1 to 1200
zcolor(z)
move(m1 + m2)
lturn(a1-a2)
a2 = a2 + a3
m2 = m2 + 0.1
if ty < 0 then break
z = z + 1
if z > 38 then z = 1
next
redraw
endfunc
function circle(x,y,radius)
x = x - radius/2
z = radius/ 57.0
z2 = radius / 57.6
set caret 10,20
set color 255,255,255
wln " Turtle Graphics function test. Hit Escape key to exit"
set color 0,0,255
pen = 0
locate ( x,y,0 ); draw pixel tx,ty ;draw pixel tx-1,ty ;draw pixel tx+1,ty ;draw pixel tx,ty-1 ;draw pixel tx,ty+1
' set color 255,255,255
move(radius)
pen = 1
lturn(90)
for cnt = 1 to 360
lturn(1)
move(z)
next
redraw
endfunc
function hexagon(x,y,size)
set caret 10,20
set color 255,255,255
wln " Turtle Graphics function test. Hit Escape key to exit"
set color 0,0,255
pen = 0
angletd = 90
anglet = rad( angletd )
locate ( 500,400,90 ); draw pixel tx,ty ;draw pixel tx-1,ty ;draw pixel tx+1,ty ;draw pixel tx,ty-1 ;draw pixel tx,ty+1
move(size)
lturn(120)
pen = 1
move(size)
lturn(60)
move(size)
lturn(60)
move(size)
lturn(60)
move(size)
lturn(60)
move(size)
lturn(60)
move(size)
redraw
endfunc
function zcolor(clr)
if clr = 0 then set color 0,0,0 ' black
if clr = 1 then set color 255,255,255 ' white
if clr = 2 then set color 255,0,0 ' red
if clr = 3 then set color 0,0,255 ' blue
if clr = 4 then set color 0,255,0 ' green
if clr = 5 then set color 255,255,0 ' yellow
if clr = 6 then set color 0,255,255 ' blue green
if clr = 7 then set color 255,0,255 ' violet
if clr = 8 then set color 255,0,200 ' red violet
if clr = 9 then set color 200,0,255 ' blue violet
if clr = 10 then set color 0,0,240 ' blue2
if clr = 11 then set color 0,0,220 ' blue3
if clr = 12 then set color 0,0,200 ' blue4
if clr = 13 then set color 0,0,180 ' blue5
if clr = 14 then set color 0,0,160 ' blue6
if clr = 15 then set color 0,0,140 ' blue7
if clr = 16 then set color 0,0,120 ' blue8
if clr = 17 then set color 0,0,100 ' blue9
if clr = 18 then set color 0,0,80 ' blue10
if clr = 19 then set color 0,0,60 ' blue11
if clr = 20 then set color 0,240,0 ' green2
if clr = 21 then set color 0,220,0 ' green3
if clr = 22 then set color 0,200,0 ' green4
if clr = 23 then set color 0,180,0 ' green5
if clr = 24 then set color 0,160,0 ' green6
if clr = 25 then set color 0,140,0 ' green7
if clr = 26 then set color 0,120,0 ' green8
if clr = 27 then set color 0,100,0 ' green9
if clr = 28 then set color 0,80,0 ' green10
if clr = 29 then set color 0,60,0 ' green11
if clr = 30 then set color 240,0,0 ' red2
if clr = 31 then set color 220,0,0 ' red3
if clr = 32 then set color 200,0,0 ' red4
if clr = 33 then set color 180,0,0 ' red5
if clr = 34 then set color 160,0,0 ' red6
if clr = 35 then set color 140,0,0 ' red7
if clr = 36 then set color 120,0,0 ' red8
if clr = 37 then set color 100,0,0 ' red9
if clr = 38 then set color 80,0,0 ' red10
if clr = 39 then set color 60,0,0 ' red11
endfunc