Vulpes

new_paulstretch

Feb 13th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on make_numlist(charlist)
  2.     set numlist to {}
  3.     repeat with i1 from 1 to (count of charlist)
  4.         set numlist to numlist & (ASCII number (item i1 of charlist))
  5.     end repeat
  6.     return numlist
  7. end make_numlist
  8.  
  9. on make_string(numlist)
  10.     set charlist to ""
  11.     repeat with i1 from 1 to (count of numlist)
  12.         set charlist to charlist & (ASCII character (item i1 of numlist))
  13.     end repeat
  14.     return charlist
  15. end make_string
  16.  
  17. on window_shift(numlist, tol, int)
  18.    
  19.     set idx1 to 1
  20.     set idx2 to 10
  21.     set temp to 0
  22.     if (int < 1) then
  23.         set int to 1
  24.     end if
  25.     repeat
  26.         --display dialog (idx1 as string)
  27.        
  28.         set idx2 to idx1 + (random number from -tol to tol)
  29.        
  30.         if ((idx2 > (count of numlist)) or (idx2 ≤ 0)) then
  31.             -- invalid, do nothing
  32.         else
  33.             set temp to (item idx1 of numlist)
  34.             set (item idx1 of numlist) to (item idx2 of numlist)
  35.             set (item idx2 of numlist) to temp
  36.         end if
  37.        
  38.        
  39.         if (idx1 = (count of numlist)) then
  40.             exit repeat
  41.         else
  42.             if ((random number from 1 to int)1) then
  43.                 set idx1 to idx1 + 1
  44.             end if
  45.         end if
  46.     end repeat
  47.    
  48.    
  49.     return numlist
  50. end window_shift
  51.  
  52. on paulstretch(pre_stretch)
  53.     --send_debug("~ps " & (pre_stretch as string))
  54.     set pre_stretch to remove_html_code(pre_stretch)
  55.     set repeat_size to repeat_amount(count of pre_stretch)
  56.     set post_stretch to ""
  57.     set pre_stretch_val to (string_char_value(pre_stretch))
  58.     set sum1 to 0
  59.     if repeat_size < 1 then
  60.         return ""
  61.     end if
  62.     repeat with i1 from 1 to (count of pre_stretch)
  63.         set add1 to (pre_stretch_val) / (repeat_size * (string_char_value(item i1 of pre_stretch)))
  64.         repeat while sum1 < 1
  65.             set post_stretch to post_stretch & (item i1 of pre_stretch)
  66.             set sum1 to sum1 + add1
  67.         end repeat
  68.         set sum1 to sum1 - (1 + add1)
  69.     end repeat
  70.     set num_stretch to make_numlist(post_stretch)
  71.     set num_stretch to window_shift(num_stretch, 5, 2)
  72.     set post_stretch to make_string(num_stretch)
  73.    
  74.     return post_stretch
  75. end paulstretch
  76.  
  77. on remove_html_code(html_)
  78.     --http://www.ascii.cl/htmlcodes.htm
  79.     set txtout to ""
  80.     set html_list to {¬
  81.         {"quot;", "\""}, ¬
  82.         {"apos;", "'"}, ¬
  83.         {"lt;", "<"}, ¬
  84.         {"gt;", ">"}, ¬
  85.         {"amp;", "&"}}
  86.     set check to ""
  87.     set i to 1
  88.     repeat while i ≤ (count of html_)
  89.         if (item i of html_ is "&") then
  90.             --display dialog "found something at " & (i as string)
  91.             repeat while ((item i of html_ is not ";") and (i < (count of html_)))
  92.                 set i to i + 1
  93.                 set check to (check & (item i of html_))
  94.             end repeat
  95.             --display dialog "check is " & check
  96.             repeat with j from 1 to (count of html_list)
  97.                 if (item 1 of (item j of html_list)) is check then
  98.                     --display dialog "found it at " & (j as string) & " which is " & (item 2 of (item j of html_list))
  99.                    
  100.                     set txtout to txtout & (item 2 of (item j of html_list))
  101.                     exit repeat
  102.                 end if
  103.             end repeat
  104.             set check to ""
  105.         else
  106.             set txtout to txtout & (item i of html_)
  107.         end if
  108.         set i to i + 1
  109.     end repeat
  110.     return txtout
  111. end remove_html_code
  112.  
  113. on repeat_amount(size1)
  114.     set botmax to 453
  115.     set total_length to upper_circle((botmax - size1), botmax)
  116.     if total_length < 0 then
  117.         return -1
  118.     else
  119.         return total_length
  120.     end if
  121. end repeat_amount
  122.  
  123. on abs1(in1)
  124.     if in1 ≥ 0 then
  125.         return in1
  126.     else
  127.         return -in1
  128.     end if
  129. end abs1
  130.  
  131. on upper_circle(x, r)
  132.     if abs1(x) > r then
  133.         return -1
  134.     end if
  135.     return (-(x ^ 2) + r ^ 2) ^ 0.5
  136. end upper_circle
  137.  
  138. on string_char_value(string1)
  139.     set return_val to 0
  140.     set cvlist to {¬
  141.         {"A", 8}, ¬
  142.         {"B", 3}, ¬
  143.         {"C", 3}, ¬
  144.         {"D", 3}, ¬
  145.         {"E", 10}, ¬
  146.         {"F", 3}, ¬
  147.         {"G", 3}, ¬
  148.         {"H", 3}, ¬
  149.         {"I", 7}, ¬
  150.         {"J", 3}, ¬
  151.         {"K", 3}, ¬
  152.         {"L", 4}, ¬
  153.         {"M", 4}, ¬
  154.         {"N", 3}, ¬
  155.         {"O", 8}, ¬
  156.         {"P", 5}, ¬
  157.         {"Q", 2}, ¬
  158.         {"R", 5}, ¬
  159.         {"S", 6}, ¬
  160.         {"T", 5}, ¬
  161.         {"U", 8}, ¬
  162.         {"V", 3}, ¬
  163.         {"W", 4}, ¬
  164.         {"X", 2}, ¬
  165.         {"Y", 6}, ¬
  166.         {"Z", 2}, ¬
  167.         {" ", 1}}
  168.     --set foundswitch to false
  169.     repeat with i1 from 1 to (count of string1)
  170.         repeat with i2 from 1 to (count of cvlist)
  171.             if (item 1 of (item i2 of cvlist)) = (item i1 of string1) then
  172.                 set return_val to return_val + (item 2 of (item i2 of cvlist))
  173.                 exit repeat
  174.             end if
  175.         end repeat
  176.     end repeat
  177.     if return_val > 0 then
  178.         return return_val
  179.     else
  180.         --error here
  181.         return 1
  182.     end if
  183. end string_char_value
Advertisement
Add Comment
Please, Sign In to add comment