Advertisement
imk0tter

Untitled

Jul 25th, 2011
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 40.20 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;       GeoSketch            ;
  3. ;     Coded by: Imk0tter     ;
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. ; Usage: To start GeoSketch, right click a window and click GeoSketch  ;
  6. ;                                                                      ;
  7. ; * To bring up the arm parameters, press "s" or "w"                   ;
  8. ;                                                                      ;
  9. ; * To generate a random drawing, press 1 through 6                    ;
  10. ;                                                                      ;
  11. ; * To start or stop drawing, press "d"                                ;
  12. ;                                                                      ;
  13. ; * To toggle the export label, press "L"                              ;
  14. ;                                                                      ;
  15. ; * To apply a sketch to the background, hold "shift" and click        ;
  16. ; where you would like to place your drawing                           ;
  17. ;                                                                      ;
  18. ; * To clear the drawing buffer, press "c"                             ;
  19. ;                                                                      ;
  20. ; * You can zoom in using the "up" and "down" arrows                   ;
  21. ;                                                                      ;
  22. ; * To take a screenshot of the drawing buffer, press Enter            ;
  23. ;                                                                      ;
  24. ; * To toggle the drawing arms, press "h"                              ;
  25. ;                                                                      ;
  26. ; * You can pan around the background by holding left click and        ;
  27. ; dragging the mouse                                                   ;
  28. ;                                                                      ;
  29. ; * Many more options can be found in the menu                         ;
  30. ;                                                                      ;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32.  
  33. ;;;;;;;;;
  34. ; Input ;
  35. ;;;;;;;;;
  36.  
  37. alias GeoSketch.PromptImport {
  38.   if !$dialog(geoImport) { dialog -dm geoImport Import }
  39.   else { did -f geoImport 2 }
  40. }
  41.  
  42. alias GeoSketch.PromptExport {
  43.   if !$dialog(geoExport) { dialog -dm geoExport Export }
  44.   else { did -f geoExport 2 }
  45. }
  46. on 1:keydown:@GeoSketch:*: {
  47.  
  48.   if $keyChar == s || $keyChar == w {
  49.     if (!$dialog(ArmParameters)) {
  50.       var %x $dialog(ArmParameters,armp,@GeoSketch)
  51.     }
  52.     else {
  53.       did -f ArmParameters 1
  54.     }
  55.   }
  56.  
  57.   if $isalias(GeoSketch.Gen $+ $keyChar) {
  58.     if $hget(GeoSketch,Drawing) {
  59.       GeoSketch.HandleDraw
  60.     }
  61.     GeoSketch.Gen $+ $keyChar
  62.     GeoSketch.HandleDraw
  63.   }
  64.   ;Generate Random
  65.   if $keyChar == r {
  66.     GeoSketch.Rand3 $hget(GeoSketch,ArmCount)
  67.     if $hget(GeoSketch,Drawing) {
  68.       GeoSketch.HandleDraw
  69.     }
  70.     GeoSketch.HandleDraw
  71.   }
  72.  
  73.   ;Generate Structured Random
  74.   else if $keyChar == t {
  75.     GeoSketch.Rand2 $hget(GeoSketch,ArmCount)
  76.     if $hget(GeoSketch,Drawing) {
  77.       GeoSketch.HandleDraw
  78.     }
  79.     GeoSketch.HandleDraw
  80.   }
  81.  
  82.   ;Export current Drawing
  83.   else if $keyChar == e {
  84.     GeoSketch.PromptExport
  85.   }
  86.  
  87.   ;Bring up import dialog
  88.   else if $keyChar == i {
  89.     GeoSketch.PromptImport
  90.   }
  91.  
  92.   ;Start/stop drawing
  93.   else if $keyChar == d {
  94.     GeoSketch.HandleDraw
  95.   }
  96.  
  97.   ;Toggle Export label below drawing
  98.   else if $keyChar == l {
  99.     hadd -m GeoSketch DrawLabel $iif($hget(GeoSketch,DrawLabel),0,1)
  100.   }
  101.  
  102.   ;Toggle arm drawing
  103.   else if $keyChar == h {
  104.     hadd -m GeoSketch DrawArms $iif($hget(GeoSketch,DrawArms),0,1)
  105.   }
  106.   ;Clear drawing buffer
  107.   else if $keyChar == c {
  108.     if $hget(GeoSketch,Drawing) {
  109.       GeoSketch.HandleDraw
  110.     }
  111.     clear @GeoSketchDrawBuff
  112.   }
  113.  
  114.   ;Zoom out (Down Arrow)
  115.   else if $keyVal == 40 {
  116.     return $GeoSketch.Zoom(1)
  117.   }
  118.  
  119.   ;Zoom in (Up Arrow)
  120.   else if $keyVal == 38 {
  121.     return $GeoSketch.Zoom(0)
  122.   }
  123.  
  124.   ;Save screenshot to mirc directory (Enter)
  125.   else if $keyVal == 13 {
  126.     var %z $ticks
  127.     var %saveDir $mircdirSketches
  128.     var %saveFile $+(GeoSketch,-,%z,.jpg)
  129.     var %savepath $+(%saveDir,\,%saveFile)
  130.     var %w $hget(GeoSketch,DrawBuff.w)
  131.     var %h $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * 30)) + 20
  132.     while $window(@GeoSketchSaveBuff).h != %h {
  133.       window -hp @GeoSketchSaveBuff -1 -1 %w %h
  134.     }
  135.     drawCopy -n @GeoSketchDrawBuff 0 0 %w %h @GeoSketchSaveBuff 0 0
  136.     if !$exists(%saveDir) {
  137.       mkdir $qt(%saveDir)
  138.     }
  139.     drawSave -b32q100 @GeoSketchSaveBuff $qt(%savePath)
  140.     run mspaint.exe $qt(%savePath)
  141.     window -c @GeoSketchSaveBuff
  142.   }
  143.  
  144.   ;unhandled
  145.   else {
  146.   }
  147. }
  148.  
  149.  
  150. ;;;;;;;;;;;;;;;;;;;;;;
  151. ; Gametime rendering ;
  152. ;;;;;;;;;;;;;;;;;;;;;;
  153. alias GeoSketch.renderScene {
  154.   var %scale $hget(GeoSketch,Scale)
  155.   var %armCount $hget(GeoSketch,ArmCount)
  156.   var %x 1
  157.   var %totalLength
  158.   var %totalAngle
  159.   while %x <= %armCount {
  160.     var %armAngle $+ %x $hget(GeoSketch,Arm $+ %x $+ Angle)
  161.     var %totalAngle %totalAngle $round($calc(%armAngle [ $+ [ %x ] ] % 360),1)
  162.     var %armLength $+ %x $hget(GeoSketch,Arm $+ %x $+ Length)
  163.     inc %totalLength %armLength [ $+ [ %x ] ]
  164.     var %armSpeed $+ %x $hget(GeoSketch,Arm $+ %x $+ Speed)
  165.     inc %x
  166.   }
  167.   if $hget(GeoSketch,HasInit) == 2 {
  168.     if $hget(GeoSketch,Drawing) {
  169.       GeoSketch.HandleDraw
  170.       ;echo @Debug Total Sides: $hget(GeoSketch,Sides)
  171.     }
  172.   }
  173.   else if $hget(GeoSketch,Drawing) && $hget(GeoSketch,HasInit) == 1 {
  174.     hinc -m GeoSketch Sides
  175.   }
  176.   if (%totalAngle == $hget(GeoSketch,startAngle) || $hget(GeoSketch,Sides) == $hget(GeoSketch,SideMax)) && $hget(GeoSketch,Drawing) {
  177.     if $hget(GeoSketch,HasInit) == 1 {
  178.       hinc -m GeoSketch HasInit
  179.     }
  180.     else {
  181.       hadd -m GeoSketch HasInit 1
  182.       hadd -m GeoSketch Sides 0
  183.     }
  184.   }
  185.   var %window.w $window(@GeoSketch).w
  186.   var %window.h $window(@GeoSketch).h
  187.  
  188.   var %scorePadding.w 2
  189.   var %scorePadding.h $hget(GeoSketch,Scorepadding.H)
  190.  
  191.   var %template $hget(GeoSketch,Template)
  192.   var %fontSize 10
  193.  
  194.   ;var %boxCount %armCount * 2
  195.   var %boxCount 4
  196.  
  197.   var %score.w $int($calc((%window.w - ((%boxCount + 1) * %scorePadding.w)) / %boxCount) )
  198.   var %score.h $hget(GeoSketch,Score.H)
  199.  
  200.  
  201.   var %m.x $iif($hget(GeoSketch,MouseLock),$hget(GeoSketch,Mouse.X),$mouse.x)
  202.   var %m.y $iif($hget(GeoSketch,MouseLock),$hget(GeoSketch,Mouse.Y),$mouse.y)
  203.  
  204.   if (%m.x != $null && %m.y != $null) {
  205.     if $hget(GeoSketch,Moving) {
  206.       var %mouse.x $calc((%m.x - $hget(GeoSketch,Mouse.X)) * %scale)
  207.       var %mouse.y $calc((%m.y - $hget(GeoSketch,Mouse.Y)) * %scale)
  208.  
  209.       var %newX $iif($calc($hget(GeoSketch,Buffer.X) - %mouse.x) > 0,$v1,0)
  210.       var %newY $iif($calc($hget(GeoSketch,Buffer.Y) - %mouse.y) > 0,$v1,0)
  211.  
  212.       if %newX < $calc($window(@GeoSketchBuffer).w - 2 - $window(@GeoSketch).w * %scale) {
  213.         hadd -m GeoSketch Buffer.X $v1
  214.       }
  215.       else {
  216.         hadd -m GeoSketch Buffer.X $v2
  217.       }
  218.  
  219.       if %newY < $calc($window(@GeoSketchBuffer).h - 2 -  (($window(@GeoSketch).h - %score.h - %scorePadding.h * 2) * %scale)) {
  220.         hadd -m GeoSketch Buffer.Y $v1
  221.       }
  222.       else {
  223.         hadd -m GeoSketch Buffer.Y $v2
  224.       }
  225.     }
  226.     hadd -m GeoSketch Mouse.X %m.x
  227.     hadd -m GeoSketch Mouse.Y %m.y
  228.   }
  229.   drawCopy -n @GeoSketchBuffer $hget(GeoSketch,Buffer.X) $hget(GeoSketch,Buffer.Y) $calc(%window.w * %scale) $calc((%window.h - (%score.h + %scorePadding.h * 2)) * %scale) @GeoSketch 0 $calc(%score.h + %scorePadding.h * 2) %window.w $calc(%window.h - (%score.h + %scorePadding.h * 2))
  230.   var %buff.w $hget(GeoSketch,DrawBuff.W)
  231.   var %buff.h $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * $hget(GeoSketch,DrawBuff.lh)))
  232.  
  233.   drawCopy -nt @GeoSketchDrawBuff $rgb(255,255,255) 0 0 %buff.w %buff.h @GeoSketch $calc($iif(%m.x,$v1,$hget(GeoSketch,Mouse.X)) - ($hget(GeoSketch,DrawBuff.x) / %scale)) $calc($iif(%m.y,$v1,$hget(GeoSketch,Mouse.Y))- ($hget(GeoSketch,DrawBuff.Y) / %scale)) $calc(%buff.w / %scale) $calc(%buff.h / %scale)
  234.  
  235.   var %box.x %score.w + %scorePadding.w
  236.   var %currBox.x %window.w - %box.x
  237.   dec %currBox.x 10
  238.   var %text.h $calc(%score.h / 2 + %scorePadding.h - ($height(T,Tahoma,%fontSize) / 2))
  239.  
  240.   var %boxColor $rgb(220,220,220)
  241.   var %borderColor $rgb(100,100,100)
  242.   var %textColor $rgb(0,0,0)
  243.  
  244.   var %x 1
  245.  
  246.   var %arm.x $iif(%m.x,$v1,$hget(GeoSketch,Mouse.X))
  247.   var %arm.y $iif(%m.y,$v1,$hget(GeoSketch,Mouse.Y))
  248.  
  249.   var %mouse.x %arm.x
  250.   var %mouse.y %arm.y
  251.  
  252.   var %degPerFrame $iif(%template,360 / %template,%armSpeed1)
  253.   var %drawArms $hget(GeoSketch,DrawArms)
  254.   var %drawArm.X %arm.x
  255.   var %drawArm.Y %arm.Y
  256.   while %x <= %armCount {
  257.     var %color $hget(GeoSketch,Arm $+ %x $+ Color)
  258.     var %color2 $hget(GeoSketch,Arm $+ %x $+ Color2)
  259.     var %lastX.X %drawArm.x
  260.     var %lastX.Y %drawArm.y
  261.  
  262.     var %zzz $calc(%armSpeed [ $+ [ %x ] ] / %armSpeed1)
  263.  
  264.     var %armSin $cos(%armAngle [ $+ [ %x ] ]).deg
  265.     var %armCos $sin(%armAngle [ $+ [ %x ] ]).deg
  266.  
  267.     var %arm.x $calc(%armSin * %armLength [ $+ [ %x ] ] + %arm.x)
  268.     var %arm.y $calc(%armCos * %armLength [ $+ [ %x ] ] + %arm.y)
  269.  
  270.     var %diff.x %arm.x - %mouse.x
  271.     var %diff.y %arm.y - %mouse.y
  272.  
  273.     if $hget(GeoSketch,Arm $+ %x $+ Last.X) != $null {
  274.       var %distanceRatio $sqrt($calc($abs(%diff.x) ^ 2 + $abs(%diff.y) ^ 2)) / %totalLength
  275.       var %armColor $color2colorratio(%color,%color2,%distanceRatio)
  276.  
  277.     }
  278.     else {
  279.       var %armColor %color
  280.     }
  281.  
  282.     var %drawArm.x $calc(%armSin * (%armLength [ $+ [ %x ] ] / %scale) + %drawArm.x)
  283.     var %drawArm.y $calc(%armCos * (%armLength [ $+ [ %x ] ] / %scale) + %drawArm.y)
  284.     hinc GeoSketch Arm $+ %x $+ Angle $calc(%zzz * %degPerFrame)
  285.  
  286.     ;If Arm.Show == 1
  287.     if $hget(GeoSketch,Arm $+ %x $+ Show) && %drawArms {
  288.       drawLine -nr @GeoSketch %armColor 2 %lastX.X %lastX.Y %drawArm.x %drawArm.y
  289.     }
  290.  
  291.     ;If Drawing && Arm.Draw == 1
  292.     if $hget(GeoSketch,Drawing) && $hget(GeoSketch,Arm $+ %x $+ Draw) {
  293.       if $hget(GeoSketch,Arm $+ %x $+ Last.X) != $null {
  294.         drawLine -nr @GeoSketchDrawBuff %armColor $hget(GeoSketch,Arm $+ %x $+ Width) $calc($hget(GeoSketch,DrawBuff.x) + $v1) $calc($hget(GeoSketch,DrawBuff.y) + $hget(GeoSketch,Arm $+ %x $+ Last.Y)) $calc($hget(GeoSketch,DrawBuff.x) + %diff.x) $calc($hget(GeoSketch,DrawBuff.y) + %diff.y)
  295.       }
  296.     }
  297.     hadd -m GeoSketch Arm $+ %x $+ Last.X %diff.x
  298.     hadd -m GeoSketch Arm $+ %x $+ Last.Y %diff.y
  299.  
  300.     inc %x
  301.   }
  302.   if %drawArms {
  303.     drawDot -n @GeoSketch 4 4 $calc(%drawArm.x + 2) $calc(%drawArm.y + 2)
  304.   }
  305.   drawRect -nf @GeoSketch 0 1 0 0 %window.w $hget(GeoSketch,scorePad)
  306.   var %x %armCount
  307.  
  308.   GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Template: $hget(GeoSketch,Template)
  309.   dec %currBox.x %box.x
  310.  
  311.   GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Side Count: $hget(GeoSketch,Sides)
  312.   dec %currBox.x %box.x
  313.  
  314.   GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Arm Count: %armCount
  315.   dec %currBox.x %box.x
  316.  
  317.   GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Status: $iif($hget(GeoSketch,Drawing),Drawing,Stopped)
  318.   dec %currBox.x %box.x
  319.  
  320.   drawDot @GeoSketch
  321. }
  322.  
  323.  
  324. ;;;;;;;;;;;;;;;
  325. ; Draw
  326. ;;;;;;;;;;;;;;;;
  327. ; HUD Drawing  ;
  328. ;;;;;;;;;;;;;;;;
  329. alias GeoSketch.DrawTextBox {
  330.   ;params <ID> <BOX.X> <BOX.Y> <BOX.W> <BOX.H> <TEXT.Y> <FONTSIZE> <BOX COLOR> <BORDER COLOR> <TEXT COLOR> <TEXT>
  331.   var %id $1
  332.  
  333.   ;Draw Box
  334.   drawrect -nrf @ $+ $1 $8 1 $2 $3 $4 $5
  335.  
  336.   ;Draw Border
  337.   drawrect -nr @ $+ $1 $9 1 $2 $3 $4 $5
  338.  
  339.   ;Draw Text
  340.   drawtext -norf @ $+ $1 $10 "Arial" $7 $calc($4 / 2 + $2 - ($width($11-,Tahoma,$7) / 2)) $6 $11-
  341. }
  342.  
  343. ;;;;;;;;;;;;;;;;;
  344. ; Square adding ;
  345. ;;;;;;;;;;;;;;;;;
  346. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  347. ; Window/Hash initialization ;
  348. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  349. alias GeoSketch.InitGUI {
  350.   ; Window Width
  351.   ; NOTE: If windows prevents a window this size from being created, lower these numbers
  352.   hadd -m GeoSketch Alive 1
  353.   if !$window(@GeoSketchBuffer) { var %flag 1 }
  354.  
  355.   var %windowWidth 4000
  356.   var %windowHeight 3000
  357.   while ($window(@GeoSketchBuffer).w != %windowWidth) {
  358.     window -hp @GeoSketchBuffer -1 -1 %windowWidth %windowHeight
  359.   }
  360.   var %windowWidthb 1200
  361.   var %windowHeights 1200
  362.   while ($window(@GeoSketchDrawBuff).w != %windowWidthb) {
  363.     window -hp @GeoSketchDrawBuff -1 -1 %windowWidthb %windowHeights
  364.   }
  365.   ;Score Padding
  366.   var %scorePad 30
  367.  
  368.   var %board.x 0
  369.   var %board.y %scorePad
  370.  
  371.   hadd -m GeoSketch scorePad %scorePad
  372.  
  373.   hadd -m GeoSketch board.x %board.x
  374.   hadd -m GeoSketch board.y %board.y
  375.  
  376.   var %armCount 4
  377.   while %armCount {
  378.     GeoSketch.InitArm
  379.     dec %armCount
  380.   }
  381.  
  382.   GeoSketch.Gen2
  383.  
  384.   hadd -m GeoSketch Template 0
  385.   hadd -m GeoSketch Scale 1
  386.  
  387.   window -Bdp @GeoSketch -1 -1 800 600
  388.  
  389.   hadd -m GeoSketch Buffer.X $calc(%windowWidth / 2 - 800 / 2)
  390.   hadd -m GeoSketch Buffer.Y $calc(%windowHeight / 2 - 600 / 2)
  391.  
  392.   hadd -m GeoSketch DrawBuff.X 0
  393.   hadd -m GeoSketch DrawBuff.Y 0
  394.   hadd -m GeoSketch DrawBuff.W 0
  395.   hadd -m GeoSketch DrawBuff.H 0
  396.  
  397.   hadd -m GeoSketch Score.H 20
  398.   hadd -m GeoSketch ScorePadding.H 5
  399.  
  400.   hadd -m GeoSketch BGColor $rgb(255,255,255)
  401.  
  402.   hadd -m GeoSketch DrawArms 1
  403.   var %m1 Welcome to GeoSketch by Imk0tter!
  404.   var %m3 Drag the mouse to pan through the background
  405.   var %m2 To start drawing $+ $chr(44) press "d"
  406.   var %m4 To apply the drawing to the background $+ $chr(44) hold shift and click where you would like it placed
  407.   var %m5 To bring up the arm options $+ $chr(44) press "w" or "s"
  408.   if %flag {
  409.     drawtext -norf @GeoSketchBuffer 0 "Arial" 15 $calc($hget(GeoSketch,Buffer.X) + ($window(@GeoSketch).w / 2) - ($width(%m1,Arial,15) / 2)) $calc($hget(GeoSketch,Buffer.Y) + 265) %m1
  410.     drawtext -norf @GeoSketchBuffer 0 "Arial" 12 $calc($hget(GeoSketch,Buffer.X) + ($window(@GeoSketch).w / 2) - ($width(%m2,Arial,12) / 2)) $calc($hget(GeoSketch,Buffer.Y) + 285) %m2
  411.     drawtext -norf @GeoSketchBuffer 0 "Arial" 12 $calc($hget(GeoSketch,Buffer.X) + ($window(@GeoSketch).w / 2) - ($width(%m3,Arial,12) / 2)) $calc($hget(GeoSketch,Buffer.Y) + 295) %m3
  412.     drawtext -norf @GeoSketchBuffer 0 "Arial" 12 $calc($hget(GeoSketch,Buffer.X) + ($window(@GeoSketch).w / 2) - ($width(%m4,Arial,12) / 2)) $calc($hget(GeoSketch,Buffer.Y) + 305) %m4  
  413.     drawtext -norf @GeoSketchBuffer 0 "Arial" 12 $calc($hget(GeoSketch,Buffer.X) + ($window(@GeoSketch).w / 2) - ($width(%m5,Arial,12) / 2)) $calc($hget(GeoSketch,Buffer.Y) + 315) %m5
  414.   }
  415.   .timerGeoSketch 0 0 GeoSketch.renderScene
  416. }
  417.  
  418. alias GeoSketch.Clear {
  419.   clear @GeoSketchBuffer
  420.   drawFill -nrs @GeoSketchBuffer $hget(GeoSketch,BGColor) $rgb(255,255,255) 0 0
  421. }
  422. ;;;;;;;;;;;;;;;;;;;;;;
  423. ; Pre-game rendering ;
  424. ;;;;;;;;;;;;;;;;;;;;;;
  425. ;;;;;;;;;;;;;;;
  426. ; Click alias ;
  427. ;;;;;;;;;;;;;;;
  428. alias GeoSketch.Click {
  429.   if ($mouse.key & 4) {
  430.     GeoSketch.ApplyDraw
  431.     if $hget(GeoSketch,Drawing) {
  432.       GeoSketch.HandleDraw
  433.     }
  434.   }
  435.   else {
  436.     hadd -m GeoSketch Moving 1
  437.   }
  438. }
  439.  
  440. alias GeoSketch.UClick {
  441.   if ($hget(GeoSketch,Drawing) == 1) {
  442.     hadd -m GeoSketch Drawing 0
  443.     hdel -m GeoSketch Last.X
  444.     hdel -m GeoSketch Last.Y
  445.   }
  446.   hadd -m GeoSketch Moving 0
  447. }
  448.  
  449. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  450. ;            Mouse Events           ;
  451. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  452. menu @GeoSketch {
  453.   sclick: GeoSketch.Click
  454.   uclick: GeoSketch.UClick
  455. }
  456. menu @GeoSketch {
  457.   Arm Parameters: {
  458.     ;if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  459.     if (!$dialog(ArmParameters)) {
  460.       var %x $dialog(ArmParameters,armp,@GeoSketch)
  461.     }
  462.     else {
  463.       did -f ArmParameters 1
  464.     }
  465.   }
  466. }
  467. alias GeoSketch.SetTemplate {
  468.   if $1 != $null {
  469.     hadd -m GeoSketch Template $1
  470.   }
  471.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  472.   var %x $hget(GeoSketch,ArmCount)
  473.   while %x {
  474.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  475.     dec %x
  476.   }
  477. }
  478.  
  479. menu @GeoSketch {
  480.   Import Sketch: GeoSketch.PromptImport
  481.   Export Sketch: GeoSketch.PromptExport
  482.   Calculate Ratios: DegToSide
  483.   Clear Scene: GeoSketch.Clear
  484.   Change Background: {
  485.     if !$dialog(geoBg) { dialog -dm geoBg bgcolor }
  486.     else {
  487.       did -f geoBg 2
  488.     }
  489.   }
  490. }
  491. menu @GeoSketch {
  492.   .Drawing Sides
  493.   ..Set Custom: GeoSketch.SetTemplate $Input(Enter the number of sides for the template,eo,Template Sides)
  494.   ..Set 0: GeoSketch.SetTemplate 0
  495.   ..Set 2: GeoSketch.SetTemplate 2
  496.   ..Set 3: GeoSketch.SetTemplate 3
  497.   ..Set 4: GeoSketch.SetTemplate 4
  498.   ..Set 5: GeoSketch.SetTemplate 5
  499.   ..Set 6: GeoSketch.SetTemplate 6
  500. }
  501. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  502. ;            Closing Events           ;
  503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  504. on 1:close:@GeoSketch: {
  505.   if $hget(GeoSketch) { hfree GeoSketch }
  506.   if ($window(@GeoSketchBuffer)) window -c @GeoSketchbuffer
  507.   .timerGeoSketch off
  508. }
  509.  
  510. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  511. ; General GeoSketch Functions ;
  512. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  513. alias GeoSketch.InitDrawing {
  514.   if $hget(GeoSketch,Drawing) {
  515.     GeoSketch.HandleDraw
  516.   }
  517.   clear @GeoSketchDrawBuff
  518.   var %x $hget(GeoSketch,ArmCount)
  519.   while %x {
  520.     hadd -m GeoSketch Arm $+ %x $+ Angle $hget(GeoSketch,Arm $+ %x $+ StartAngle))
  521.     dec %x
  522.   }
  523.   GeoSketch.HandleDraw
  524. }
  525.  
  526. alias GeoSketch.initArm {
  527.   hinc -m GeoSketch ArmCount
  528.  
  529.   var %armCount $hget(GeoSketch,ArmCount)
  530.  
  531.   hadd -m GeoSketch $+(Arm,%armCount,Length) 50
  532.   hadd -m GeoSketch $+(Arm,%armCount,Speed) 0
  533.   hadd -m GeoSketch $+(Arm,%armCount,Width) 1
  534.   hadd -m GeoSketch $+(Arm,%armCount,StartAngle) 90
  535.   hadd -m GeoSketch $+(Arm,%armCount,Color) $r(0,$rgb(255,255,255))
  536.   hadd -m GeoSketch $+(Arm,%armCount,Color2) $r(0,$rgb(255,255,255))
  537.   hadd -m GeoSketch $+(Arm,%armCount,Draw) 1
  538.   hadd -m GeoSketch $+(Arm,%armCount,Show) 1
  539.   hadd -m GeoSketch $+(Arm,$calc(%armCount - 1),Draw) 0
  540. }
  541. alias Color2ColorRatio {
  542.   var %color1 $rgb($1)
  543.   var %color2 $rgb($2)
  544.   var %color2Ratio $3
  545.   var %color1Ratio 1 - $3
  546.  
  547.   var %red $calc($token(%color1,1,44) * %color1Ratio + $token(%color2,1,44) * %color2Ratio)
  548.   var %green $calc($token(%color1,2,44) * %color1Ratio + $token(%color2,2,44) * %color2Ratio)
  549.   var %blue $calc($token(%color1,3,44) * %color1Ratio + $token(%color2,3,44) * %color2Ratio)
  550.  
  551.   return $rgb(%red,%green,%blue)
  552. }
  553.  
  554. alias GeoSketch.HandleDraw {
  555.   hadd -m GeoSketch Drawing $iif($hget(GeoSketch,Drawing),0,2)
  556.   if !$hget(GeoSketch,Drawing) {
  557.     var %x $hget(GeoSketch,ArmCount)
  558.     while %x {
  559.       hdel -m GeoSketch Arm $+ %x $+ Last.X
  560.       hdel -m GeoSketch Arm $+ %x $+ Last.Y
  561.       dec %x
  562.     }
  563.   }
  564.   else {
  565.     var %x $hget(GeoSketch,ArmCount),%y,%z
  566.     while %x {
  567.       hdel -m GeoSketch Arm $+ %x $+ Last.X
  568.       hdel -m GeoSketch Arm $+ %x $+ Last.Y
  569.       inc %y $hget(GeoSketch,Arm $+ %x $+ Length)
  570.       var %z $round($calc($hget(GeoSketch,Arm $+ %x $+ Angle) % 360),1) %z
  571.       dec %x
  572.     }
  573.     clear @GeoSketchDrawBuff
  574.  
  575.     hadd -m GeoSketch StartAngle %z
  576.     hadd -m GeoSketch HasInit 0
  577.  
  578.     var %w $calc(%y * 2),%h %w
  579.     var %export $GeoSketch.export
  580.     var %x $wrap(%export,Arial,12,$calc(%w - 50),0)
  581.     var %h2 $calc(%h + (%x * $height(%export,Arial,12)))
  582.     ;if $width(%export,Arial,12) > %w { var %w $width(%export,Arial,12) }
  583.     while %x {
  584.       var %txt $wrap(%export,Arial,12,$calc(%w - 50),%x)
  585.       drawtext -norf @GeoSketchDrawBuff 0 "Arial" 12 $calc((%w / 2) - ($width(%txt,Arial,12) / 2)) $calc(%h + $height(%txt,Arial,12) * (%x - 1)) %txt
  586.       dec %x
  587.     }
  588.  
  589.     ;drawtext -norf @GeoSketchDrawBuff 0 "Arial" 12 $calc((%w / 2) - ($width(%export,Arial,12) / 2)) %h %export
  590.     hadd -m GeoSketch DrawBuff.x $calc(%w / 2)
  591.     hadd -m GeoSketch DrawBuff.y $calc(%h / 2)
  592.     hadd -m GeoSketch DrawBuff.w %w
  593.     hadd -m GeoSketch DrawBuff.h %h
  594.     hadd -m GeoSketch DrawBuff.lh $calc(%h2 - %h)
  595.   }
  596. }
  597.  
  598. alias GeoSketch.ApplyDraw {
  599.   var %scale $hget(GeoSketch,Scale)
  600.   var %base.x $calc($hget(GeoSketch,Buffer.X) + ($mouse.x * %scale) - $hget(GeoSketch,DrawBuff.X))
  601.   var %base.Y $calc($hget(GeoSketch,Buffer.Y) + (($mouse.y - $hget(GeoSketch,Score.H) - $hget(GeoSketch,Scorepadding.H) * 2) * %scale) - $hget(GeoSketch,DrawBuff.Y))
  602.   drawCopy -nt @GeoSketchDrawBuff $rgb(255,255,255) 0 0 $hget(GeoSketch,DrawBuff.W) $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * $hget(GeoSketch,DrawBuff.lh))) @GeoSketchBuffer %base.x %base.y
  603.   ;drawCopy -n @GeoSketchDrawBuff 0 0 $hget(GeoSketch,DrawBuff.W) $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * 20)) @GeoSketchBuffer %base.x %base.y
  604.  
  605. }
  606.  
  607. alias GeoSketch.Zoom {
  608.   var %zoomRatio 0.125
  609.   if $1 {
  610.     hinc -m GeoSketch Scale %zoomRatio
  611.  
  612.     var %newX $iif($calc($hget(GeoSketch,Buffer.X) - $window(@GeoSketch).w * (%zoomRatio / 2)) > 0,$v1,0)
  613.     var %newY $iif($calc($hget(GeoSketch,Buffer.Y) - (($window(@GeoSketch).h - $hget(GeoSketch,Score.h) - $hget(GeoSketch,ScorePadding.h) * 2) * (%zoomRatio / 2))) > 0,$v1,0)
  614.  
  615.     if %newX > $calc($window(@GeoSketchBuffer).w - 2 - ($window(@GeoSketch).w  * $hget(GeoSketch,Scale))) $&
  616.       || %newY > $calc($window(@GeoSketchBuffer).h - 2 - (($window(@GeoSketch).h - $hget(GeoSketch,Score.h) - $hget(GeoSketch,Scorepadding.h) * 2) * $hget(GeoSketch,Scale))) {
  617.       hdec -m GeoSketch Scale %zoomRatio
  618.     }
  619.     else {
  620.       hadd -m GeoSketch Buffer.X %newX
  621.       hadd -m GeoSketch Buffer.Y %newY
  622.     }
  623.   }
  624.   else {
  625.     if $hget(GeoSketch,Scale) > %zoomRatio {
  626.       var %newX $iif($calc($hget(GeoSketch,Buffer.X) + $window(@GeoSketch).w * (%zoomRatio / 2)) > 0,$v1,0)
  627.       var %newY $iif($calc($hget(GeoSketch,Buffer.Y) + (($window(@GeoSketch).h - $hget(GeoSketch,Score.h) - $hget(GeoSketch,ScorePadding.h) * 2) * (%zoomRatio / 2))) > 0,$v1,0)
  628.  
  629.       hdec -m GeoSketch Scale %zoomRatio
  630.       hadd -m GeoSketch Buffer.X %newX
  631.       hadd -m GeoSketch Buffer.Y %newY
  632.     }
  633.   }
  634. }
  635.  
  636. ;;;;;;;;;;;;;;;;
  637. ;    Random    ;
  638. ;;;;;;;;;;;;;;;;
  639. alias GeoSketch.Rand2 {
  640.   hdel -m GeoSketch SideMax
  641.   hdel -m GeoSketch Last.X
  642.   hdel -m GeoSketch Last.Y
  643.   hadd -m GeoSketch ArmCount $1
  644.   hadd -m GeoSketch Color $r(0,16777215)
  645.   hadd -m GeoSketch Color2 $r(0,16777215)
  646.   var %x $1,%y,%z
  647.   while %x {
  648.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc(360 / $iif($r(0,2),$r(2,30),(2 * $r(1,5) - 1) / 2) * $iif($r(0,1),1,-1))
  649.     hinc -m GeoSketch Arm $+ %x $+ Speed $iif($r(0,1),0.5,0)
  650.     hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
  651.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  652.     dec %x
  653.   }
  654. }
  655. alias GeoSketch.Rand3 {
  656.   hdel -m GeoSketch SideMax
  657.   hdel -m GeoSketch Last.X
  658.   hdel -m GeoSketch Last.Y
  659.   var %x $1
  660.   var %y,%z
  661.   while %x {
  662.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc($r(0,1000) - 500)
  663.     hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
  664.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  665.     dec %x
  666.   }
  667.   hadd -m GeoSketch Color $r(0,16777215)
  668.   hadd -m GeoSketch Color2 $r(0,16777215)
  669.   hadd -m GeoSketch ArmCount $1
  670. }
  671.  
  672. alias GeoSketch.Gen2 {
  673.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  674.   hdel -m GeoSketch Last.X
  675.   hdel -m GeoSketch Last.Y
  676.   tokenize 32 $1-
  677.   var %x $hget(GeoSketch,ArmCount),%y %x
  678.   var %sideCount $iif($1,$1,$r(1500,6000))
  679.   if $calc(%sideCount % 2) { dec %sideCount }
  680.   var %flutterSides $iif(%sideCount > 1500,$iif(%sideCount > 3000,8,6),4)
  681.   var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
  682.  
  683.   var %length $r(5,12)
  684.  
  685.   hadd GeoSketch Arm $+ %x $+ Speed $calc((%speed + 180) * $iif($r(0,1),1,-1))
  686.   hadd GeoSketch Arm $+ %x $+ Length $r(22,28)
  687.   hadd GeoSketch Arm $+ %x $+ Angle 90
  688.  
  689.   dec %x
  690.  
  691.   hadd -m GeoSketch Arm $+ %x $+ Speed %speed
  692.   hadd -m GeoSketch Arm $+ %x $+ Length %length
  693.   hadd -m GeoSketch Arm $+ %x $+ Angle 90
  694.  
  695.   dec %x
  696.   dec %y 2
  697.   GeoSketch.GenDefault %sideCount %x $2-
  698. }
  699.  
  700. alias GeoSketch.Gen5 {
  701.   var %m $r(2,4)
  702.   return $GeoSketch.Gen1($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
  703. }
  704. alias GeoSketch.Gen1 {
  705.   tokenize 32 $1-
  706.   var %y $hget(GeoSketch,ArmCount),%x 1,%z
  707.   while %x <= %y {
  708.     var %r $iif($ [ $+ [ $calc(%x + 1) ] ] != $null,$v1,$int($calc($r(4,104) / 4)))
  709.     ;var %r $iif($ [ $+ [ $calc(%x + 1) ] ],$v1,$r(4,180))
  710.     var %tn $v1
  711.     var %r $iif($regex($prop,/(m)+(\d+)/),$calc(%r + (1 / $iif($regml(2),$v1,2))),%r)
  712.  
  713.     if !%tn {
  714.       var %r $calc(%r * ($r(0,1) * 2 - 1))
  715.     }
  716.     var %z %z %r
  717.     inc %x
  718.   }
  719.   GeoSketch.GenDefault $iif($1,$1,$calc($r(20,50) + (1 / $r(8,20)))) %y %z
  720. }
  721. alias GeoSketch.Gen6 {
  722.   var %m $r(4,6)
  723.   return $GeoSketch.Gen1($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
  724. }
  725. alias GeoSketch.Gen4 {
  726.   return $geoSketch.Gen3($calc($r(36,130) + (1 / $r(6,12))))
  727.   ;return $geoSketch.Gen3($r(36,130))
  728. }
  729. alias GeoSketch.Gen3 {
  730.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  731.   hdel -m GeoSketch Last.X
  732.   hdel -m GeoSketch Last.Y
  733.   tokenize 32 $1-
  734.   var %flutterSides 6
  735.   var %x $hget(GeoSketch,ArmCount),%y %x
  736.   var %sideCount $iif($1,$1,$r(36,2000))
  737.   var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
  738.  
  739.   var %length $r(10,15)
  740.  
  741.   hadd -m GeoSketch Arm $+ %x $+ Speed %speed
  742.   hadd -m GeoSketch Arm $+ %x $+ Length %length
  743.   hadd -m GeoSketch Arm $+ %x $+ Angle 90
  744.  
  745.   dec %x
  746.   dec %y
  747.  
  748.   if t isin $prop {
  749.     hadd -m GeoSketch Arm $+ %x $+ Length $r(15,40)
  750.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc((360 / %sideCount ) / $r(11,22))
  751.     dec %x
  752.     dec %y
  753.   }
  754.  
  755.   GeoSketch.GenDefault %sideCount %x $2-
  756. }
  757.  
  758. alias GeoSketch.GenDefault {
  759.   tokenize 32 $1-
  760.   var %maxLength 400,%minLength 50
  761.   var %sideCount $1,%x $2,%y %x
  762.   tokenize 32 $3-
  763.   while %x {
  764.     var %rand $iif($ [ $+ [ %x ] ] != $null,$v1,$int($calc($r(11,121) / 11)))
  765.     if $v1 == $null {
  766.       var %rand $calc(%rand * ($r(0,1) * 2 - 1)))
  767.     }
  768.     var %k $calc(360 / (%sideCount / %rand)) %k
  769.     hadd -m GeoSketch Arm $+ %x $+ Length $r($int($calc((%maxLength / %y) / 3)),$calc(%maxLength / %y))
  770.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc(360 / (%sideCount / %rand))
  771.  
  772.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  773.     dec %x
  774.   }
  775.   var %y $hget(GeoSketch,ArmCount),%x %y,%z
  776.   while %y {
  777.     var %a $hget(GeoSketch,Arm $+ %y $+ Speed)
  778.     var %z $round($calc(%sideCount / (360 / %a)),4) %z
  779.     var %k %a %k
  780.     dec %y
  781.   }
  782.   hadd -m GeoSketch SideMax $round($iif(%sideCount != $int(%sideCount),$calc($v1 / ($v1 % 1)),$v1),0)
  783.   if $window(@Debug) {
  784.     echo @Debug Sides: %sideCount - Ratios: %z - Speeds: %k - Tube: $iif(%tube,Yes,No)
  785.     ; clipboard $RotatixEnc(%sideCount,%z)
  786.   }
  787. }
  788. alias DegToSide {
  789.   var %x $hget(GeoSketch,ArmCount),%z
  790.   while %x {
  791.     var %z $hget(GeoSketch,Arm $+ %x $+ Speed) %z
  792.     dec %x
  793.   }
  794.   tokenize 32 %z
  795.   var %sideCount $lcm($regsubex($1-,/(\d+\.*\d*)/g,$calc(360 / \1)))
  796.   var %armRatio $regsubex($1-,/(\d+\.*\d*)/g,$round($calc(%sideCount / (360 / \1)),1))
  797.   if !$dialog(GeoESides) { dialog -dm geoESides export }
  798.   else { did -f geoESides 2 }
  799.   did -a geoESides 2 Side Count: %sideCount - Ratios: %armRatio - Speeds: $1-
  800. }
  801. alias Lcm {
  802.   var %maxIter 5000
  803.   tokenize 32 $sorttok($1-,32,n)
  804.   var %tolerance 0.5
  805.   while (($abs($calc($token($1,1,58) - $token($token($1-,-1,32),1,58))) > %tolerance) || ($calc($round($token($1,1,58),2) % 1))) && %maxIter > 0   {
  806.     tokenize 32 $sorttok($+($abs($calc($replace($1,:,+))),:,$iif($token($1,2,58),$v1,$abs($1))) $2-,32,n)
  807.     dec %maxIter
  808.   }
  809.   return $round($iif(%maxIter > 0,$token($1,1,58),360),0)
  810. }
  811. dialog bgcolor {
  812.   title "Background Color"
  813.   size -1 -1 119 26
  814.   option dbu
  815.   icon 1, 5 6 15 15
  816.   edit "FFFFFF", 2, 25 12 50 10
  817.   text "Background Color:", 3, 25 4 52 8
  818.   button "Change Color", 4, 79 4 37 18
  819. }
  820.  
  821. dialog armp {
  822.   title "Arm Options"
  823.   size -1 -1 236 252
  824.   option dbu
  825.   list 1, 1 17 59 209, size extsel vsbar
  826.   check "Draw Selected Arms", 2, 68 25 62 10
  827.   check "Show Selected Arms", 3, 68 13 60 10
  828.   button "Set All To This Value", 4, 168 10 54 12
  829.   button "Set All To This Value", 7, 168 24 54 12
  830.   box "Display Options", 8, 64 2 170 38
  831.   box "Arm Colors", 9, 64 42 171 65
  832.   icon 10, 68 58 15 15
  833.   edit "FFFFFF", 11, 86 62 50 11
  834.   box "Arm Parameters", 12, 64 107 171 90
  835.   icon 13, 68 83 15 15
  836.   edit "FFFFFF", 14, 86 88 50 10
  837.   text "Color I:", 15, 87 54 25 8
  838.   text "Color II:", 16, 87 80 25 8
  839.   text "Length:", 17, 68 122 19 8, right
  840.   edit "", 18, 86 121 50 10
  841.   text "Width:", 19, 70 136 17 8, right
  842.   edit "", 20, 86 135 50 10
  843.   text "Speed:", 21, 69 164 18 8, right
  844.   text "Angle:", 22, 69 178 18 8, right
  845.   button "Set All To This Value", 23, 168 60 54 12
  846.   button "Set All To This Value", 24, 168 86 54 12
  847.   button "Set All To This Value", 25, 168 120 54 12
  848.   button "Set All To This Value", 26, 168 134 54 12
  849.   text "Arms:", 27, 8 7 15 8
  850.   button "+", 28, 44 7 7 7
  851.   button "-", 29, 28 7 7 7
  852.   button "Accept", 30, 2 230 58 19
  853.   edit "", 31, 86 163 50 10
  854.   edit "", 32, 86 177 50 10
  855.   button "Set All To This Value", 33, 168 161 54 12
  856.   button "Set All To This Value", 34, 168 175 54 12
  857.   box "Random", 35, 64 197 171 54
  858.   combo 36, 86 208 50 58, size vsbar drop
  859.   text "Type:", 37, 69 210 17 8, right
  860.   button "Generate", 38, 168 212 54 28
  861.   edit "", 5, 86 222 50 10
  862.   edit "", 6, 86 235 50 10, autohs
  863.   text "Sides:", 39, 62 223 25 8, right
  864.   text "Params:", 40, 62 236 25 8, right
  865. }
  866.  
  867. dialog export {
  868.   title "Export Drawing"
  869.   size -1 -1 236 62
  870.   option dbu
  871.   text "Your Export Has been printed below:", 1, 67 4 97 8, center
  872.   edit "", 2, 5 17 228 29, read multi vsbar
  873.   button "Copy", 3, 100 48 37 12
  874. }
  875.  
  876. dialog import {
  877.   title "Import Drawing"
  878.   size -1 -1 236 62
  879.   option dbu
  880.   text "Enter string to import:", 1, 67 4 97 8, center
  881.   edit "", 2, 5 17 228 29, multi vsbar
  882.   button "Import", 3, 100 48 37 12
  883. }
  884.  
  885. on 1:dialog:geoBg:init:0: {
  886.   GeoSketch.Dialog.BGEdit
  887. }
  888. on 1:dialog:geoBg:edit:2 {
  889.   GeoSketch.Dialog.BGEdit
  890. }
  891. on 1:dialog:geoBg:sclick:4: {
  892.   if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
  893.     var %oldc $hget(GeoSketch,BGColor)
  894.     hadd -m GeoSketch BGColor $base($regml(1),16,10)
  895.     drawFill -nrs @GeoSketchBuffer $base($regml(1),16,10) %oldc 0 0
  896.   }
  897.   dialog -c $dname
  898. }
  899. alias GeoSketch.Dialog.BGEdit {
  900.   var %id $iif($1,$1,$did)
  901.   if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
  902.     window -hp @Armc -1 -1 200 200
  903.     drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
  904.     drawsave -b32 @Armc Armc.bmp
  905.     window -c @Armc
  906.     did -g $dname 1 Armc.bmp
  907.   }
  908. }
  909.  
  910.  
  911. on 1:dialog:geoExport:init:0: { did -a $dname 2 $GeoSketch.export }
  912. on 1:dialog:geoE*:sclick:3: {
  913.   var %x $did($dname,2).lines,%z
  914.   while %x {
  915.     var %z $did($dname,2,%x) $+ %z
  916.     dec %x
  917.   }
  918.   clipboard %z
  919.   dialog -c $dname
  920. }
  921.  
  922. on 1:dialog:geoImport:sclick:3: {
  923.   var %x $did($dname,2).lines,%z
  924.   while %x {
  925.     var %z $did($dname,2,%x) $+ %z
  926.     dec %x
  927.   }
  928.   GeoSketch.Import %z
  929.   dialog -c $dname
  930.   GeoSketch.InitDrawing
  931. }
  932. ;;;;;;;;;;;;;;;;;;;;;
  933. ;    Dialog Init    ;
  934. ;;;;;;;;;;;;;;;;;;;;;
  935. on 1:dialog:arm*:init:0: {
  936.   if $window(@Armc) { clear @Armc }
  937.   else {  window -hp @Armc -1 -1 200 200 }
  938.   drawsave -b32 @Armc Armc.bmp
  939.   window -c @Armc
  940.   did -g $dname 10 Armc.bmp
  941.   did -g $dname 13 Armc.bmp
  942.  
  943.   var %x $hget(GeoSketch,ArmCount),%y 1
  944.   while %y <= %x {
  945.     did -a $dname 1 %y
  946.     inc %y
  947.   }
  948.   did -c $dname 1 1
  949.   if %x > 0 {
  950.     GeoSketch.Dialog.ArmSelect 1
  951.   }
  952.   var %x 1
  953.   while $isalias(GeoSketch.Gen $+ %x) {
  954.     did -a $dname 36 Gen $+ %x
  955.     inc %x
  956.   }
  957.   did -c $dname 36 1
  958.   did -o $dname 5 1 $hget(GeoSketch,RandSides)
  959.   did -o $dname 6 1 $hget(GeoSketch,RandParams)
  960.   hadd -m GeoSketch MouseLock 1
  961.   hadd -m GeoSketch Mouse.X $calc($window(@GeoSketch).w / 2)
  962.   hadd -m GeoSketch Mouse.Y $calc(($window(@GeoSketch).h - $hget(GeoSketch,ScorePadding) * 2 - $hget(GeoSketch,Score.h)) / 2)
  963. }
  964. on 1:dialog:arm*:close:0: {  hadd -m GeoSketch MouseLock 0 | GeoSketch.InitDrawing }
  965. on 1:dialog:arm*:sclick:2-3: { GeoSketch.Dialog.ChangeDisplay |  GeoSketch.InitDrawing }
  966. on 1:dialog:arm*:edit:11,14: { GeoSketch.Dialog.ColorEdit |  GeoSketch.InitDrawing }
  967. on 1:dialog:arm*:sclick:1: { GeoSketch.Dialog.ArmSelect }
  968. on 1:dialog:arm*:edit:18,20,31,32: { GeoSketch.Dialog.ArmEdit | GeoSketch.InitDrawing }
  969. on 1:dialog:arm*:edit:5,6: { GeoSketch.Dialog.RandEdit }
  970. on 1:dialog:arm*:sclick:25,26,33,34,23,24,4,7: { GeoSketch.Dialog.SetAll |  GeoSketch.InitDrawing }
  971. on 1:dialog:arm*:sclick:28-29: { GeoSketch.Dialog.ChangeArm |  GeoSketch.InitDrawing }
  972. on 1:dialog:arm*:sclick:38: { GeoSketch.Dialog.GenRand |  GeoSketch.InitDrawing }
  973. on 1:dialog:arm*:sclick:30: {
  974.   dialog -c $dname
  975.   hadd -m GeoSketch MouseLock 0
  976.   GeoSketch.InitDrawing
  977. }
  978. alias GeoSketch.Dialog.RandEdit {
  979.   hadd -m GeoSketch RandSides $did($dname,5)
  980.   hadd -m GeoSketch RandParams $did($dname,6)
  981. }
  982. alias GeoSketch.Dialog.GenRand {
  983.   GeoSketch. $+ $did($dname,36).seltext $did($dname,5) $did($dname,6)
  984.   GeoSketch.Dialog.ArmSelect
  985.   GeoSketch.InitDrawing
  986. }
  987. alias GeoSketch.Dialog.ChangeDisplay {
  988.   var %state $did($dname,$did).state
  989.   if $did == 3 {
  990.     GeoSketch.Dialog.ModifyVar Show %state 1
  991.   }
  992.   else {
  993.     GeoSketch.Dialog.ModifyVar Draw %state 1
  994.   }
  995. }
  996. alias GeoSketch.Dialog.ChangeArm {
  997.   var %id $iif($1,$1,$did)
  998.   if %id == 28 {
  999.     GeoSketch.InitArm
  1000.     did -a $dname 1 $hget(GeoSketch,ArmCount)
  1001.     did -c $dname 1 $hget(GeoSketch,ArmCount)
  1002.     GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
  1003.  
  1004.   }
  1005.   else if $hget(GeoSketch,ArmCount) > 1 {
  1006.     hdec -m GeoSketch ArmCount
  1007.     hadd -m GeoSketch Arm $+ $calc($v1 - 1) $+ Draw 1
  1008.     hdel -w GeoSketch Arm $+ $v1 $+ *
  1009.     did -d $dname 1 $v1
  1010.     did -c $dname 1 $hget(GeoSketch,ArmCount)
  1011.     GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
  1012.   }
  1013.  
  1014. }
  1015. alias GeoSketch.Dialog.SetAll {
  1016.   var %id $iif($1,$1,$did)
  1017.   goto %id 0
  1018.   :4
  1019.   GeoSketch.Dialog.ModifyVar Show $did($dname,3).state
  1020.   return
  1021.   :7
  1022.   GeoSketch.Dialog.ModifyVar Draw $did($dname,2).state
  1023.   return
  1024.   :23
  1025.   GeoSketch.Dialog.ModifyVar Color $calc($base($did($dname,11),16,10))
  1026.   return
  1027.   :24
  1028.   GeoSketch.Dialog.ModifyVar Color2 $calc($base($did($dname,14),16,10))
  1029.   return
  1030.   :25
  1031.   GeoSketch.Dialog.ModifyVar Length $calc($did($dname,18))
  1032.   return
  1033.   :26
  1034.   GeoSketch.Dialog.ModifyVar Width $calc($did($dname,20))
  1035.   return
  1036.   :33
  1037.   GeoSketch.Dialog.ModifyVar Speed $calc($did($dname,31))
  1038.   return
  1039.   :34
  1040.   GeoSketch.Dialog.ModifyVar StartAngle $calc($did($dname,32))
  1041.   return
  1042.   :%id
  1043.   :0
  1044.   return
  1045. }
  1046. alias GeoSketch.Dialog.ArmEdit {
  1047.   var %id $iif($1,$1,$did),%val $calc($did($dname,%id))
  1048.   goto %id 0
  1049.   :18
  1050.   GeoSketch.Dialog.ModifyVar Length %val 1
  1051.   return
  1052.   :20
  1053.   GeoSketch.Dialog.ModifyVar Width %val 1
  1054.   return
  1055.   :31
  1056.   GeoSketch.Dialog.ModifyVar Speed %val 1
  1057.   return
  1058.   :32
  1059.   GeoSketch.Dialog.ModifyVar StartAngle %val 1
  1060.   return
  1061.   :%id
  1062.   :0
  1063.   return
  1064. }
  1065. alias GeoSketch.Dialog.ArmSelect {
  1066.   var %select $iif($1,$1,$did($dname,1,$did($dname,1,0).sel).sel)
  1067.  
  1068.   did -o $dname 11 1 $base($hget(GeoSketch,Arm $+ %select $+ Color),10,16,6)
  1069.   did -o $dname 14 1 $base($hget(GeoSketch,Arm $+ %select $+ Color2),10,16,6)
  1070.  
  1071.   did -o $dname 18 1 $hget(GeoSketch,Arm $+ %select $+ Length)
  1072.   did -o $dname 20 1 $hget(GeoSketch,Arm $+ %select $+ Width)
  1073.  
  1074.   did -o $dname 31 1 $hget(GeoSketch,Arm $+ %select $+ Speed)
  1075.   did -o $dname 32 1 $hget(GeoSketch,Arm $+ %select $+ StartAngle)
  1076.  
  1077.   did $iif($hget(GeoSketch,Arm $+ %select $+ Draw),-c,-u) $dname 2
  1078.   did $iif($hget(GeoSketch,Arm $+ %select $+ Show),-c,-u) $dname 3
  1079.  
  1080.   GeoSketch.Dialog.ColorEdit 11
  1081.   GeoSketch.Dialog.ColorEdit 14
  1082. }
  1083.  
  1084. alias GeoSketch.Dialog.ColorEdit {
  1085.   var %id $iif($1,$1,$did)
  1086.   if $regex($did(%id),/([0-9A-Fa-f]{6})/) {
  1087.     window -hp @Armc -1 -1 200 200
  1088.     drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
  1089.     drawsave -b32 @Armc Armc.bmp
  1090.     window -c @Armc
  1091.     if %id == 11 {
  1092.       did -g $dname 10 Armc.bmp
  1093.     }
  1094.     else {
  1095.       did -g $dname 13 Armc.bmp
  1096.     }
  1097.   }
  1098.   if (!$1) {
  1099.     GeoSketch.Dialog.ModifyVar $iif(%id == 11,Color,Color2) $calc($base($regml(1),16,10)) 1
  1100.   }
  1101. }
  1102.  
  1103. alias GeoSketch.Dialog.ModifyVar {
  1104.   var %var $1,%val $2,%select $3
  1105.   var %x $iif(%select,$did($dname,1,0).sel,$hget(GeoSketch,ArmCount))
  1106.   while %x {
  1107.     hadd -m GeoSketch $+(Arm,$iif(%select,$did($dname,1,%x).sel,%x),%var) %val
  1108.     dec %x
  1109.   }
  1110.   if %var == speed {
  1111.     hdel -m GeoSketch SideMax
  1112.   }
  1113. }
  1114.  
  1115. alias GeoSketch.Export {
  1116.   var %x $hget(GeoSketch,ArmCount)
  1117.   while %x {
  1118.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ StartAngle),$v1,0)
  1119.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Speed),$v1,0)
  1120.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Length),$v1,0)
  1121.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Width),$v1,0)
  1122.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color),$v1,0)
  1123.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color2),$v1,0)
  1124.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Show),$v1,0)
  1125.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Draw),$v1,0)
  1126.     var %z $+(%y,:,%z)
  1127.     var %y
  1128.     dec %x
  1129.   }
  1130.   bset -t &Data 1 $+(%z,;,$iif($hget(GeoSketch,Template),$v1,0),;,$iif($hget(GeoSketch,RandSides),$v1,0),;,$hget(GeoSketch,RandParams))
  1131.   var %x $compress(&Data,b)
  1132.   var %x $encode(&Data,bm)
  1133.   var %output $bvar(&Data,1-).text
  1134.   return %output
  1135. }
  1136.  
  1137. alias GeoSketch.Import {
  1138.   bset -t &Data 1 $1-
  1139.   var %x $decode(&Data,bm)
  1140.   var %x $decompress(&Data,bm)
  1141.   var %x $token($bvar(&Data,1-).text,1,59)
  1142.   var %template $token($bvar(&Data,1-).text,2,59)
  1143.   var %sides $token($bvar(&Data,1-).text,3,59)
  1144.   var %params $token($bvar(&Data,1-).text,4,59)
  1145.   var %y 1
  1146.   if ($dialog(ArmParameters)) dialog -c ArmParameters
  1147.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  1148.   while $token(%x,%y,58) != $null {
  1149.     tokenize 32 $v1
  1150.     hadd -m GeoSketch Arm $+ %y $+ StartAngle $1
  1151.     hadd -m GeoSketch Arm $+ %y $+ Speed $2
  1152.     hadd -m GeoSketch Arm $+ %y $+ Length $3
  1153.     hadd -m GeoSketch Arm $+ %y $+ Width $4
  1154.     hadd -m GeoSketch Arm $+ %y $+ Color $5
  1155.     hadd -m GeoSketch Arm $+ %y $+ Color2 $6
  1156.     hadd -m GeoSketch Arm $+ %y $+ Show $7
  1157.     hadd -m GeoSketch Arm $+ %y $+ Draw $8
  1158.     hadd -m GeoSketch Arm $+ %y $+ Angle $1
  1159.     hdel -m GeoSketch Arm $+ %y $+ Last.X
  1160.     hdel -m GeoSketch Arm $+ %y $+ Last.Y
  1161.     inc %y
  1162.   }
  1163.   hadd -m GeoSketch RandSides $iif(%sides,$v1,0)
  1164.   hadd -m GeoSketch RandParams %params
  1165.   dec %y
  1166.   hadd -m GeoSketch ArmCount %y
  1167.   hadd -m GeoSketch Template %template
  1168.   GeoSketch.HandleDraw
  1169. }
  1170.  
  1171. alias GeoSketch.ExportRotatix {
  1172.   var %color $rgb(15,15,15)
  1173.   var %bgColor 0
  1174.   var %glowColor $rgb(255,255,255)
  1175.   var %glowStrength 2
  1176.   var %glowBlurX 6
  1177.   var %glowBlurY 6
  1178.   var %glowAlpha 40
  1179.   var %y $hget(GeoSketch,ArmCount),%x 1
  1180.   bset -t &Data 1 $+($chr(40),%bgColor)
  1181.   var %arm1Speed $hget(GeoSketch,Arm1Speed)
  1182.  
  1183.   while %x <= %y {
  1184.     var %template $iif($hget(GeoSketch,Template),360 / $v1,%arm1speed)
  1185.     var %armSpeed $calc(($hget(GeoSketch,Arm $+ %x $+ Speed) / %arm1Speed) * %template)
  1186.     bset -t &Data $calc($bvar(&Data,0) + 1) $+($chr(40),$iif(%x == %y,d,0),v_,%armSpeed,_,%color,_,$hget(GeoSketch,Arm $+ %x $+ Length),_1_0,%glowColor,_,%glowAlpha,_,%glowBlurX,_,%glowBlurY,_,%glowStrength,_0_0_) $+ %str
  1187.     inc %x
  1188.   }
  1189.   bset &Data $calc($bvar(&Data,0) + 1) 41 13 13
  1190.   var %x $compress(&Data,b)
  1191.   var %z $encode(&Data,mb)
  1192.   return &Data
  1193. }
  1194.  
  1195.  
  1196. alias GenRand {
  1197.   var %id $ticks
  1198.   var %x $1
  1199.   tokenize 32 $2-
  1200.   var %file Export $+ %id $+ .txt
  1201.   .fopen -no %id %file
  1202.   while %x {
  1203.     var %rand $ [ $+ [ $r(1,$0) ] ]
  1204.     var %armCount $r(18,27)
  1205.     hadd -m GeoSketch ArmCount %armcount
  1206.     echo -a Generating Image with $+(,%armCount,) arms using: %rand
  1207.     %rand
  1208.     GeoSketch.ExportRotatix
  1209.     .fwrite -bn %id &Data
  1210.     .fwrite -n %id $crlf
  1211.     ;echo -a Wrote $qt($bvar(&Data,0)) bytes
  1212.     bunset &Data
  1213.     dec %x
  1214.   }
  1215.   run %file
  1216.   .fclose %id
  1217. }
  1218.  
  1219. alias rotatixEnc {
  1220.   tokenize 32 $1-
  1221.   var %str 360 / (sideCount / (key - (((floor(x / (2^(b*(n-1)))) / (2^b)) - floor(floor(x / (2^(b*(n-1)))) / (2^b))) * (2^b))))
  1222.   var %bits 8
  1223.   var %key $calc(2^ (%bits - 1) - 1)
  1224.   var %sideCount $1
  1225.   tokenize 32 $2-
  1226.   var %x 1,%y
  1227.   while %x <= $0 {
  1228.     var %deg $ [ $+ [ %x ] ] % %key
  1229.     var %offset $calc((%key - %deg) * 2^(%bits * (%x - 1)))
  1230.     inc %y %offset
  1231.     inc %x
  1232.   }
  1233.   return $replace(%str,x,%y,key,%key,sideCount,%sideCount,b,%bits)
  1234. }
  1235.  
  1236. ;;;;;;;;
  1237. ; Menu ;
  1238. ;;;;;;;;
  1239.  
  1240. menu * {
  1241.   -
  1242.   GeoSketch: /GeoSketch.InitGui
  1243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement