programs/swirls.toby
author Ryan C. Gordon <icculus@icculus.org>
Tue, 18 Mar 2008 02:05:22 +0000
changeset 499 96e88f292dc8
parent 1 d7cb562e4e24
permissions -rw-r--r--
Updated Lua from 5.1.1 to 5.1.3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
number r = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
number g = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
number b = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
function main() returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
	//doTopLeftFan()
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
	doDragon()
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
function doTopLeftFan() returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
	setTurtleXY(10, 100)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
	setAngle(90)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
	fanLeft(175, 10)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
function fanLeft(number distance, number angle) returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
	if (distance >= 0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
		goForward(distance)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
		goBackward(distance - 10)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
		turnLeft(angle)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
		fanLeft(distance - 5, angle)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
	endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
function doDragon() returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
	rightDragon(20, 3)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
function leftDragon(number iteration, number dist) returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
	r = r + 0.001
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
	if (r > 1.0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
		r = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
	endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
	setPenColorRGB(r, g, b)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
	if (iteration == 0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
		g = g + 0.01
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
		if (g > 1.0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
			g = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
		endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
		goForward(dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
	else
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
		leftDragon(iteration - 1, dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
		turnLeft(90)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
		rightDragon(iteration - 1, dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
	endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
function rightDragon(number iteration, number dist) returns nothing
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
	b = b + 0.001
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
	if (b > 1.0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
		b = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
	endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
	setPenColorRGB(r, g, b)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
	if (iteration == 0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
		g = g + 0.01
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
		if (g > 1.0)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
			g = 0.0
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
		endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
		goForward(dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
	else
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
		leftDragon(iteration - 1, dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
		turnRight(90)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
		rightDragon(iteration - 1, dist)
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
	endif
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
endfunction
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
d7cb562e4e24 Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69