is it possible to write a graphing calculator in applescript?

Im still a bit of an applescript newb and was looking for help. so as you can tell from the topic name i want to know if its possible to write a graphing calculator in applescript. It has to be able to tell the slope of a line with 2 points from -3 to 3 for both X and Y. Thanks a ton. :slight_smile:

In pure AppleScript you can’t but with a little help from cocoa you can write a graphing calculator.

Given 2 points, p1 and p2, this would work…

set p1 to {3, 2}
set p2 to {6, 3}

set m to ((item 2 of p2) - (item 2 of p1)) / ((item 1 of p2) - (item 1 of p1))
set b to (item 2 of p1) - (m * (item 1 of p1))

if b is less than 0 then
	set absB to first word of (b as text)
	set theLine to "y = " & (m as text) & "x - " & absB
else if b is greater than 0 then
	set theLine to "y = " & (m as text) & "x + " & (b as text)
	set theLine to "y = " & (m as text) & "x"
end if

display dialog theLine

Editorial Comment

Since OS X 10.4, every system has included (in /Application/Utilities) a program called Grapher that is capable of producing some lovely graphics from equations and/or tables, understands imaginary numbers, and has a bunch of built-in functions. What a shame that it isn’t scriptable.