All pastes #971748 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-04 23:09 UTC
rendered paste body
set counter to -1
set colour to -1
set themat to ""

set thingToChange to (choose from list {"ambient", "diffuse", "emission", "specular", "shininess"} with prompt "Property to change") as string

if thingToChange is not "shininess" then
	
	repeat
		set colourstart1 to the text returned of (display dialog "Red Chan start" default answer 0)
		if colourstart1 is greater than or equal to 0 and colourstart1 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set colourstart2 to the text returned of (display dialog "Green Chan start" default answer 0)
		if colourstart2 is greater than or equal to 0 and colourstart2 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set colourstart3 to the text returned of (display dialog "Blue Chan start" default answer 0)
		if colourstart3 is greater than or equal to 0 and colourstart3 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	
	repeat
		set colourend1 to the text returned of (display dialog "Red Chan end" default answer 1)
		if colourend1 is greater than or equal to 0 and colourend1 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set colourend2 to the text returned of (display dialog "Green Chan end" default answer 1)
		if colourend2 is greater than or equal to 0 and colourend2 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set colourend3 to the text returned of (display dialog "Blue Chan end" default answer 1)
		if colourend3 is greater than or equal to 0 and colourend3 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	
	if thingToChange is not "diffuse" then
		repeat
			set diff1 to the text returned of (display dialog "Red Chan diffuse constant" default answer 0.5)
			if diff1 is greater than or equal to 0 and diff1 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
		repeat
			set diff2 to the text returned of (display dialog "Green Chan diffuse constant" default answer 0.5)
			if diff2 is greater than or equal to 0 and diff2 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
		repeat
			set diff3 to the text returned of (display dialog "Blue Chan diffuse constant" default answer 0.5)
			if diff3 is greater than or equal to 0 and diff3 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
	end if
else
	repeat
		set colourstart1 to the text returned of (display dialog "Shininess start" default answer 0)
		if colourstart1 is greater than or equal to 0 and colourstart1 is less than or equal to 128 then exit repeat
		display dialog "Needs to be between 0 and 128"
	end repeat
	repeat
		set colourend1 to the text returned of (display dialog "Shininess end" default answer 128)
		if colourend1 is greater than or equal to 0 and colourend1 is less than or equal to 128 then exit repeat
		display dialog "Needs to be between 0 and 128"
	end repeat
	if thingToChange is not "diffuse" then
		repeat
			set diff1 to the text returned of (display dialog "Red Chan diffuse constant" default answer 0.5)
			if diff1 is greater than or equal to 0 and diff1 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
		repeat
			set diff2 to the text returned of (display dialog "Green Chan diffuse constant" default answer 0.5)
			if diff2 is greater than or equal to 0 and diff2 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
		repeat
			set diff3 to the text returned of (display dialog "Blue Chan diffuse constant" default answer 0.5)
			if diff3 is greater than or equal to 0 and diff3 is less than or equal to 1 then exit repeat
			display dialog "Needs to be between 0 and 1"
		end repeat
	end if
end if

if thingToChange is "shininess" then
	repeat
		set spec1 to the text returned of (display dialog "Red Chan specular constant" default answer 0.5)
		if spec1 is greater than or equal to 0 and spec1 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set spec2 to the text returned of (display dialog "Green Chan specular constant" default answer 0.5)
		if spec2 is greater than or equal to 0 and spec2 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
	repeat
		set spec3 to the text returned of (display dialog "Blue Chan specular constant" default answer 0.5)
		if spec3 is greater than or equal to 0 and spec3 is less than or equal to 1 then exit repeat
		display dialog "Needs to be between 0 and 1"
	end repeat
end if


set theOut to ""
set theBoxes to ""
set posx to -400
set posy to -360

repeat 324 times
	set colourstart1 to colourstart1 + (colourend1 / 324)
	if thingToChange is not "shininess" then set colourstart2 to colourstart2 + (colourend2 / 324)
	if thingToChange is not "shininess" then set colourstart3 to colourstart3 + (colourend3 / 324)
	set counter to counter + 1
	
	if thingToChange is not "diffuse" then
		if thingToChange is not "shininess" then
			set themat to themat & "
			
material
  name mat" & counter & "
  diffuse " & diff1 & " " & diff2 & " " & diff3 & "
  " & thingToChange & " " & colourstart1 & " " & colourstart2 & " " & colourstart3 & "
end"
			
		else
			set themat to themat & "
			
material
  name mat" & counter & "
  diffuse " & diff1 & " " & diff2 & " " & diff3 & "
  specular " & spec1 & " " & spec2 & " " & spec3 & "
  " & thingToChange & " " & colourstart1 & "
end"
		end if
	else
		set themat to themat & "
		
material
  name mat" & counter & "
  " & thingToChange & " " & colourstart1 & " " & colourstart2 & " " & colourstart3 & "
end"
	end if
	
	set posx to posx + 40
	if posx is 360 then set posy to posy + 40
	if posx is 360 then set posx to -360
	
	set theBoxes to theBoxes & "

arc
   pos " & posx & " " & posy & " 0
   size 10 10 10
   matref  mat" & counter & "
end
"
end repeat

set theOut to themat & return & return & theBoxes

tell application "TextEdit"
	make new document at front of documents
	set the text of the front document to theOut
end tell