2017-09-14 13 views
1

シェイプがワープまたはスケーリングされているかどうかを判断するスクリプトを作成しています。それは、ある形の線のすべての長さのリストを作成することから始まります。AppleScriptを使用してシェイプがワープまたはスケールされているかどうかを確認する

set noofsides to text returned of (display dialog "Enter number of sides:" default answer "") 

set sidevalues to {} 
set repeatnumber to 0 
repeat noofsides times 
    set repeatnumber to repeatnumber + 1 
    set currentsidevalue to text returned of (display dialog "Enter length of line " & repeatnumber & ":" default answer "") 
    set the end of sidevalues to currentsidevalue 
end repeat 

次に、2番目に編集されたシェイプについても同じことが行われます。これは、私に異なる変数を持つ2つのリストを与えます。 2つの図形が似ているかどうかを判断するには、各 'before'線を各 'after'線で分割して同じものにする必要があります。例えば、三角形のために:

try 
    set primevariable1 to first item of primesidevalues 
    set primevariable2 to second item of primesidevalues 
    set primevariable3 to third item of primesidevalues 
    -- ... 
end try 

try 
    set regularvariable1 to first item of sidevalues 
    set regularvariable2 to second item of sidevalues 
    set regularvariable3 to third item of sidevalues 
    -- ... 
end try 

try 
    variable4 
on error 
    set variable4 to "" 
end try 
if (regularvariable1/primevariable1) = (regularvariable2/primevariable2) and (regularvariable3/primevariable3) = (regularvariable1/primevariable1) and (regularvariable3/primevariable3) = (regularvariable2/primevariable2) and variable4 = "" then 
    display dialog "Shape is similar" 
end if 

のみ3角形のためである:

firstline1/secondline1 = firstline2/secondline2 = firstline3/secondline3 

はすぐに次の操作を行うことなく、これを実行する方法はあります。私が5,6面という言葉で何かしたいと思ったら、これはますます長くなるでしょう。おそらく、リスト1のすべての数字をリスト2のすべての数字で割ったものがすべて同じである場合のように、その形は同じですか?誰も助けることができますか?

+0

ループとインデックス付き変数(リスト/配列)は、AppleScriptで表示されていますか? – MBo

+0

はい、しかし、私はこれがどのようにここに実装できるかについてはあまりよく分かりません。 –

+0

'set sidevalues to {}'は 'sidevalues'がインデックスデータ構造であることを示しています – MBo

答えて

0

このように、他の項目の値を比較するためにループを使用して、(最初のリスト内の最初の項目/第二リストの最初の項目)の値を取得する:

set sidevalues to my getSidesValue("Enter number of sides for the first shape:") 
set primesidevalues to my getSidesValue("Enter number of sides for the second shape:") 
set tc to count sidevalues 
if tc = (count primesidevalues) then -- the number of items in the lists is the same 
    set isSimilar to true 
    set thisVal to (item 1 of sidevalues)/(item 1 of primesidevalues) -- Get the value of the first item in the lists 
    repeat with i from 2 to tc -- loop to compare the value of the others items 
     if (item i of sidevalues)/(item i of primesidevalues) is not thisVal then -- not the same value 
      set isSimilar to false 
      exit repeat -- no need to continue 
     end if 
    end repeat 
else 
    set isSimilar to false 
end if 
isSimilar 


on getSidesValue(t) 
    set noofsides to text returned of (display dialog t default answer "") 
    set l to {} 
    repeat with i from 1 to noofsides 
     set currentsidevalue to text returned of (display dialog "Enter length of line " & i & ":" default answer "") 
     set the end of l to currentsidevalue 
    end repeat 
    return l 
end getSidesValue 
関連する問題