svlad

Check-in [ec96a535f1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First working turtle mode for plot.
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:ec96a535f1a83801d5ec11de15efa1af90a72d07
User & Date: Hry 2012-09-01 22:04:33
Context
2012-09-01
22:04
First working turtle mode for plot. Leaf check-in: ec96a535f1 user: Hry tags: trunk
21:27
Changed plot app to enable turtle mode. check-in: 8136db8529 user: Hry tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added plot.lua.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--turtle console
dofile("turtle.lua")
wintitle("Zelva")
maxx,maxy=getwidth()
while true do
	locate(maxx-1,1)
	write(string.rep(" ",maxy-1))
	locate(maxx-1,1)
	local zz=read()
	local f=loadstring(zz)
	local ok,msg=pcall(f)
	if not ok then
		locate(maxx-2,1)
		write(string.rep(" ",maxy-1))
		locate(maxx-2,1)
		color(255,0,0)
		write(msg)
		color(255,255,255)
	end
end

Added turtle.lua.





















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
protoTurtle={
	x=320,
	y=240,
	angle=0,
	penIsDown=true,
	fd=function(self,len)
		local prevX=self.x
		local prevY=self.y
		if self.penIsDown then
			self.y=(math.sin(math.rad(self.angle))*len)+prevY
			self.x=(math.cos(math.rad(self.angle))*len)+prevX	
			line(prevX,prevY,self.x,self.y)
		end
	end,
	left=function(self,angle)
		self.angle=self.angle+angle
	end,
	right=function(self,angle)
		self.angle=self.angle-angle
	end,
	home=function(self)
		self.x=320
		self.y=240
		self.angle=0
		self.penIsDown=true
	end,
	penUp=function(self)
		self.penIsDown=false
	end,
	penDown=function(self)
		self.penIsDown=true
	end
}

function newTurtle()
	local nt={}
	setmetatable(nt,{__index=protoTurtle})
	return nt
end

turtle=newTurtle()
exit=os.exit