Advertisement
imk0tter

Untitled

Apr 10th, 2020
1,556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 39.83 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) {
  174.     hinc -m GeoSketch Sides
  175.   }
  176.   if %totalAngle == $hget(GeoSketch,startAngle) && $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.Gen1
  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 Last.X
  641.   hdel -m GeoSketch Last.Y
  642.   hadd -m GeoSketch ArmCount $1
  643.   hadd -m GeoSketch Color $r(0,16777215)
  644.   hadd -m GeoSketch Color2 $r(0,16777215)
  645.   var %x $1,%y,%z
  646.   while %x {
  647.     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))
  648.     hinc -m GeoSketch Arm $+ %x $+ Speed $iif($r(0,1),0.5,0)
  649.     hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
  650.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  651.     dec %x
  652.   }
  653. }
  654. alias GeoSketch.Rand3 {
  655.   hdel -m GeoSketch Last.X
  656.   hdel -m GeoSketch Last.Y
  657.   var %x $1
  658.   var %y,%z
  659.   while %x {
  660.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc($r(0,1000) - 500)
  661.     hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
  662.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  663.     dec %x
  664.   }
  665.   hadd -m GeoSketch Color $r(0,16777215)
  666.   hadd -m GeoSketch Color2 $r(0,16777215)
  667.   hadd -m GeoSketch ArmCount $1
  668. }
  669.  
  670. alias GeoSketch.Gen1 {
  671.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  672.   hdel -m GeoSketch Last.X
  673.   hdel -m GeoSketch Last.Y
  674.   tokenize 32 $1-
  675.   var %x $hget(GeoSketch,ArmCount),%y %x
  676.   var %sideCount $iif($1,$1,$r(1500,6000))
  677.   if $calc(%sideCount % 2) { dec %sideCount }
  678.   var %flutterSides $iif(%sideCount > 1500,$iif(%sideCount > 3000,8,6),4)
  679.   var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
  680.  
  681.   var %length $r(5,12)
  682.  
  683.   hadd GeoSketch Arm $+ %x $+ Speed $calc((%speed + 180) * $iif($r(0,1),1,-1))
  684.   hadd GeoSketch Arm $+ %x $+ Length $r(22,28)
  685.   hadd GeoSketch Arm $+ %x $+ Angle 90
  686.  
  687.   dec %x
  688.  
  689.   hadd -m GeoSketch Arm $+ %x $+ Speed %speed
  690.   hadd -m GeoSketch Arm $+ %x $+ Length %length
  691.   hadd -m GeoSketch Arm $+ %x $+ Angle 90
  692.  
  693.   dec %x
  694.   dec %y 2
  695.   GeoSketch.GenDefault %sideCount %x $2-
  696. }
  697.  
  698. alias GeoSketch.Gen5 {
  699.   var %m $r(2,4)
  700.   return $GeoSketch.Gen2($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
  701. }
  702. alias GeoSketch.Gen2 {
  703.   tokenize 32 $1-
  704.   var %y $hget(GeoSketch,ArmCount),%x 1,%z
  705.   while %x <= %y {
  706.     var %r $iif($ [ $+ [ $calc(%x + 1) ] ] != $null,$v1,$int($calc($r(4,104) / 4)))
  707.     ;var %r $iif($ [ $+ [ $calc(%x + 1) ] ],$v1,$r(4,180))
  708.     var %tn $v1
  709.     var %r $iif($regex($prop,/(m)+(\d+)/),$calc(%r + (1 / $iif($regml(2),$v1,2))),%r)
  710.  
  711.     if !%tn {
  712.       var %r $calc(%r * ($r(0,1) * 2 - 1))
  713.     }
  714.     var %z %z %r
  715.     inc %x
  716.   }
  717.   GeoSketch.GenDefault $iif($1,$1,$calc($r(20,50) + (1 / $r(8,20)))) %y %z
  718. }
  719. alias GeoSketch.Gen6 {
  720.   var %m $r(4,6)
  721.   return $GeoSketch.Gen2($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
  722. }
  723. alias GeoSketch.Gen4 {
  724.   return $geoSketch.Gen3($calc($r(36,130) + (1 / $r(6,12))))
  725.   ;return $geoSketch.Gen3($r(36,130))
  726. }
  727. alias GeoSketch.Gen3 {
  728.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  729.   hdel -m GeoSketch Last.X
  730.   hdel -m GeoSketch Last.Y
  731.   tokenize 32 $1-
  732.   var %flutterSides 6
  733.   var %x $hget(GeoSketch,ArmCount),%y %x
  734.   var %sideCount $iif($1,$1,$r(36,2000))
  735.   var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
  736.  
  737.   var %length $r(10,15)
  738.  
  739.   hadd -m GeoSketch Arm $+ %x $+ Speed %speed
  740.   hadd -m GeoSketch Arm $+ %x $+ Length %length
  741.   hadd -m GeoSketch Arm $+ %x $+ Angle 90
  742.  
  743.   dec %x
  744.   dec %y
  745.  
  746.   if t isin $prop {
  747.     hadd -m GeoSketch Arm $+ %x $+ Length $r(15,40)
  748.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc((360 / %sideCount ) / $r(11,22))
  749.     dec %x
  750.     dec %y
  751.   }
  752.  
  753.   GeoSketch.GenDefault %sideCount %x $2-
  754. }
  755.  
  756. alias GeoSketch.GenDefault {
  757.   tokenize 32 $1-
  758.   var %maxLength 400,%minLength 50
  759.   var %sideCount $1,%x $2,%y %x
  760.   tokenize 32 $3-
  761.   while %x {
  762.     var %rand $iif($ [ $+ [ %x ] ] != $null,$v1,$int($calc($r(11,121) / 11)))
  763.     if $v1 == $null {
  764.       var %rand $calc(%rand * ($r(0,1) * 2 - 1)))
  765.     }
  766.     var %k $calc(360 / (%sideCount / %rand)) %k
  767.     hadd -m GeoSketch Arm $+ %x $+ Length $r($int($calc((%maxLength / %y) / 3)),$calc(%maxLength / %y))
  768.     hadd -m GeoSketch Arm $+ %x $+ Speed $calc(360 / (%sideCount / %rand))
  769.  
  770.     hadd -m GeoSketch Arm $+ %x $+ Angle 90
  771.     dec %x
  772.   }
  773.   var %y $hget(GeoSketch,ArmCount),%x %y,%z
  774.   while %y {
  775.     var %a $hget(GeoSketch,Arm $+ %y $+ Speed)
  776.     var %z $round($calc(%sideCount / (360 / %a)),4) %z
  777.     var %k %a %k
  778.     dec %y
  779.   }
  780.   if $window(@Debug) {
  781.     echo @Debug Sides: %sideCount - Ratios: %z - Speeds: %k - Tube: $iif(%tube,Yes,No)
  782.     ; clipboard $RotatixEnc(%sideCount,%z)
  783.   }
  784. }
  785. alias DegToSide {
  786.   var %x $hget(GeoSketch,ArmCount),%z
  787.   while %x {
  788.     var %z $hget(GeoSketch,Arm $+ %x $+ Speed) %z
  789.     dec %x
  790.   }
  791.   tokenize 32 %z
  792.   var %sideCount $lcmzz($regsubex($1-,/(\d+\.*\d*)/g,$calc(360 / \1)))
  793.   var %armRatio $regsubex($1-,/(\d+\.*\d*)/g,$calc(%sideCount / (360 / \1)))
  794.   if !$dialog(GeoESides) { dialog -dm geoESides export }
  795.   else { did -f geoESides 2 }
  796.   did -a geoESides 2 Side Count: %sideCount - Ratios: %armRatio - Speeds: $1-
  797. }
  798. alias Lcmzz {
  799.   var %maxIter 2000
  800.   tokenize 32 $sorttok($1-,32,n)
  801.   var %tolerance 0.5
  802.   while $abs($calc($token($1,1,58) - $token($token($1-,-1,32),1,58))) > %tolerance && %maxIter > 0 {
  803.     tokenize 32 $sorttok($+($abs($calc($replace($1,:,+))),:,$iif($token($1,2,58),$v1,$abs($1))) $2-,32,n)
  804.     dec %maxIter
  805.   }
  806.   return $iif(%maxIter > 0,$token($1,1,58),360)
  807. }
  808. dialog bgcolor {
  809.   title "Background Color"
  810.   size -1 -1 119 26
  811.   option dbu
  812.   icon 1, 5 6 15 15
  813.   edit "FFFFFF", 2, 25 12 50 10
  814.   text "Background Color:", 3, 25 4 52 8
  815.   button "Change Color", 4, 79 4 37 18
  816. }
  817.  
  818. dialog armp {
  819.   title "Arm Options"
  820.   size -1 -1 236 252
  821.   option dbu
  822.   list 1, 1 17 59 209, size extsel vsbar
  823.   check "Draw Selected Arms", 2, 68 25 62 10
  824.   check "Show Selected Arms", 3, 68 13 60 10
  825.   button "Set All To This Value", 4, 168 10 54 12
  826.   button "Set All To This Value", 7, 168 24 54 12
  827.   box "Display Options", 8, 64 2 170 38
  828.   box "Arm Colors", 9, 64 42 171 65
  829.   icon 10, 68 58 15 15
  830.   edit "FFFFFF", 11, 86 62 50 11
  831.   box "Arm Parameters", 12, 64 107 171 90
  832.   icon 13, 68 83 15 15
  833.   edit "FFFFFF", 14, 86 88 50 10
  834.   text "Color I:", 15, 87 54 25 8
  835.   text "Color II:", 16, 87 80 25 8
  836.   text "Length:", 17, 68 122 19 8, right
  837.   edit "", 18, 86 121 50 10
  838.   text "Width:", 19, 70 136 17 8, right
  839.   edit "", 20, 86 135 50 10
  840.   text "Speed:", 21, 69 164 18 8, right
  841.   text "Angle:", 22, 69 178 18 8, right
  842.   button "Set All To This Value", 23, 168 60 54 12
  843.   button "Set All To This Value", 24, 168 86 54 12
  844.   button "Set All To This Value", 25, 168 120 54 12
  845.   button "Set All To This Value", 26, 168 134 54 12
  846.   text "Arms:", 27, 8 7 15 8
  847.   button "+", 28, 44 7 7 7
  848.   button "-", 29, 28 7 7 7
  849.   button "Accept", 30, 2 230 58 19
  850.   edit "", 31, 86 163 50 10
  851.   edit "", 32, 86 177 50 10
  852.   button "Set All To This Value", 33, 168 161 54 12
  853.   button "Set All To This Value", 34, 168 175 54 12
  854.   box "Random", 35, 64 197 171 54
  855.   combo 36, 86 208 50 58, size vsbar drop
  856.   text "Type:", 37, 69 210 17 8, right
  857.   button "Generate", 38, 168 212 54 28
  858.   edit "", 5, 86 222 50 10
  859.   edit "", 6, 86 235 50 10
  860.   text "Sides:", 39, 62 223 25 8, right
  861.   text "Params:", 40, 62 236 25 8, right
  862. }
  863.  
  864. dialog export {
  865.   title "Export Drawing"
  866.   size -1 -1 236 62
  867.   option dbu
  868.   text "Your Export Has been printed below:", 1, 67 4 97 8, center
  869.   edit "", 2, 5 17 228 29, read multi vsbar
  870.   button "Copy", 3, 100 48 37 12
  871. }
  872.  
  873. dialog import {
  874.   title "Import Drawing"
  875.   size -1 -1 236 62
  876.   option dbu
  877.   text "Enter string to import:", 1, 67 4 97 8, center
  878.   edit "", 2, 5 17 228 29, multi vsbar
  879.   button "Import", 3, 100 48 37 12
  880. }
  881.  
  882. on 1:dialog:geoBg:init:0: {
  883.   GeoSketch.Dialog.BGEdit
  884. }
  885. on 1:dialog:geoBg:edit:2 {
  886.   GeoSketch.Dialog.BGEdit
  887. }
  888. on 1:dialog:geoBg:sclick:4: {
  889.   if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
  890.     var %oldc $hget(GeoSketch,BGColor)
  891.     hadd -m GeoSketch BGColor $base($regml(1),16,10)
  892.     drawFill -nrs @GeoSketchBuffer $base($regml(1),16,10) %oldc 0 0
  893.   }
  894.   dialog -c $dname
  895. }
  896. alias GeoSketch.Dialog.BGEdit {
  897.   var %id $iif($1,$1,$did)
  898.   if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
  899.     window -hp @Armc -1 -1 200 200
  900.     drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
  901.     drawsave -b32 @Armc Armc.bmp
  902.     window -c @Armc
  903.     did -g $dname 1 Armc.bmp
  904.   }
  905. }
  906.  
  907.  
  908. on 1:dialog:geoExport:init:0: { did -a $dname 2 $GeoSketch.export }
  909. on 1:dialog:geoE*:sclick:3: {
  910.   var %x $did($dname,2).lines,%z
  911.   while %x {
  912.     var %z $did($dname,2,%x) $+ %z
  913.     dec %x
  914.   }
  915.   clipboard %z
  916.   dialog -c $dname
  917. }
  918.  
  919. on 1:dialog:geoImport:sclick:3: {
  920.   var %x $did($dname,2).lines,%z
  921.   while %x {
  922.     var %z $did($dname,2,%x) $+ %z
  923.     dec %x
  924.   }
  925.   GeoSketch.Import %z
  926.   dialog -c $dname
  927.   GeoSketch.InitDrawing
  928. }
  929. ;;;;;;;;;;;;;;;;;;;;;
  930. ;    Dialog Init    ;
  931. ;;;;;;;;;;;;;;;;;;;;;
  932. on 1:dialog:arm*:init:0: {
  933.   if $window(@Armc) { clear @Armc }
  934.   else {  window -hp @Armc -1 -1 200 200 }
  935.   drawsave -b32 @Armc Armc.bmp
  936.   window -c @Armc
  937.   did -g $dname 10 Armc.bmp
  938.   did -g $dname 13 Armc.bmp
  939.  
  940.   var %x $hget(GeoSketch,ArmCount),%y 1
  941.   while %y <= %x {
  942.     did -a $dname 1 %y
  943.     inc %y
  944.   }
  945.   did -c $dname 1 1
  946.   if %x > 0 {
  947.     GeoSketch.Dialog.ArmSelect 1
  948.   }
  949.   var %x 1
  950.   while $isalias(GeoSketch.Gen $+ %x) {
  951.     did -a $dname 36 Gen $+ %x
  952.     inc %x
  953.   }
  954.   did -c $dname 36 1
  955.   did -o $dname 5 1 $hget(GeoSketch,RandSides)
  956.   did -o $dname 6 1 $hget(GeoSketch,RandParams)
  957.   hadd -m GeoSketch MouseLock 1
  958.   hadd -m GeoSketch Mouse.X $calc($window(@GeoSketch).w / 2)
  959.   hadd -m GeoSketch Mouse.Y $calc(($window(@GeoSketch).h - $hget(GeoSketch,ScorePadding) * 2 - $hget(GeoSketch,Score.h)) / 2)
  960. }
  961. on 1:dialog:arm*:close:0: {  hadd -m GeoSketch MouseLock 0 | GeoSketch.InitDrawing }
  962. on 1:dialog:arm*:sclick:2-3: { GeoSketch.Dialog.ChangeDisplay |  GeoSketch.InitDrawing }
  963. on 1:dialog:arm*:edit:11,14: { GeoSketch.Dialog.ColorEdit |  GeoSketch.InitDrawing }
  964. on 1:dialog:arm*:sclick:1: { GeoSketch.Dialog.ArmSelect }
  965. on 1:dialog:arm*:edit:18,20,31,32: { GeoSketch.Dialog.ArmEdit | GeoSketch.InitDrawing }
  966. on 1:dialog:arm*:edit:5,6: { GeoSketch.Dialog.RandEdit }
  967. on 1:dialog:arm*:sclick:25,26,33,34,23,24,4,7: { GeoSketch.Dialog.SetAll |  GeoSketch.InitDrawing }
  968. on 1:dialog:arm*:sclick:28-29: { GeoSketch.Dialog.ChangeArm |  GeoSketch.InitDrawing }
  969. on 1:dialog:arm*:sclick:38: { GeoSketch.Dialog.GenRand |  GeoSketch.InitDrawing }
  970. on 1:dialog:arm*:sclick:30: {
  971.   dialog -c $dname
  972.   hadd -m GeoSketch MouseLock 0
  973.   GeoSketch.InitDrawing
  974. }
  975. alias GeoSketch.Dialog.RandEdit {
  976.   hadd -m GeoSketch RandSides $did($dname,5)
  977.   hadd -m GeoSketch RandParams $did($dname,6)
  978. }
  979. alias GeoSketch.Dialog.GenRand {
  980.   GeoSketch. $+ $did($dname,36).seltext $did($dname,5) $did($dname,6)
  981.   GeoSketch.Dialog.ArmSelect
  982.   GeoSketch.InitDrawing
  983. }
  984. alias GeoSketch.Dialog.ChangeDisplay {
  985.   var %state $did($dname,$did).state
  986.   if $did == 3 {
  987.     GeoSketch.Dialog.ModifyVar Show %state 1
  988.   }
  989.   else {
  990.     GeoSketch.Dialog.ModifyVar Draw %state 1
  991.   }
  992. }
  993. alias GeoSketch.Dialog.ChangeArm {
  994.   var %id $iif($1,$1,$did)
  995.   if %id == 28 {
  996.     GeoSketch.InitArm
  997.     did -a $dname 1 $hget(GeoSketch,ArmCount)
  998.     did -c $dname 1 $hget(GeoSketch,ArmCount)
  999.     GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
  1000.  
  1001.   }
  1002.   else if $hget(GeoSketch,ArmCount) > 1 {
  1003.     hdec -m GeoSketch ArmCount
  1004.     hadd -m GeoSketch Arm $+ $calc($v1 - 1) $+ Draw 1
  1005.     hdel -w GeoSketch Arm $+ $v1 $+ *
  1006.     did -d $dname 1 $v1
  1007.     did -c $dname 1 $hget(GeoSketch,ArmCount)
  1008.     GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
  1009.   }
  1010.  
  1011. }
  1012. alias GeoSketch.Dialog.SetAll {
  1013.   var %id $iif($1,$1,$did)
  1014.   goto %id 0
  1015.   :4
  1016.   GeoSketch.Dialog.ModifyVar Show $did($dname,3).state
  1017.   return
  1018.   :7
  1019.   GeoSketch.Dialog.ModifyVar Draw $did($dname,2).state
  1020.   return
  1021.   :23
  1022.   GeoSketch.Dialog.ModifyVar Color $calc($base($did($dname,11),16,10))
  1023.   return
  1024.   :24
  1025.   GeoSketch.Dialog.ModifyVar Color2 $calc($base($did($dname,14),16,10))
  1026.   return
  1027.   :25
  1028.   GeoSketch.Dialog.ModifyVar Length $calc($did($dname,18))
  1029.   return
  1030.   :26
  1031.   GeoSketch.Dialog.ModifyVar Width $calc($did($dname,20))
  1032.   return
  1033.   :33
  1034.   GeoSketch.Dialog.ModifyVar Speed $calc($did($dname,31))
  1035.   return
  1036.   :34
  1037.   GeoSketch.Dialog.ModifyVar StartAngle $calc($did($dname,32))
  1038.   return
  1039.   :%id
  1040.   :0
  1041.   return
  1042. }
  1043. alias GeoSketch.Dialog.ArmEdit {
  1044.   var %id $iif($1,$1,$did),%val $calc($did($dname,%id))
  1045.   goto %id 0
  1046.   :18
  1047.   GeoSketch.Dialog.ModifyVar Length %val 1
  1048.   return
  1049.   :20
  1050.   GeoSketch.Dialog.ModifyVar Width %val 1
  1051.   return
  1052.   :31
  1053.   GeoSketch.Dialog.ModifyVar Speed %val 1
  1054.   return
  1055.   :32
  1056.   GeoSketch.Dialog.ModifyVar StartAngle %val 1
  1057.   return
  1058.   :%id
  1059.   :0
  1060.   return
  1061. }
  1062. alias GeoSketch.Dialog.ArmSelect {
  1063.   var %select $iif($1,$1,$did($dname,1,$did($dname,1,0).sel).sel)
  1064.  
  1065.   did -o $dname 11 1 $base($hget(GeoSketch,Arm $+ %select $+ Color),10,16,6)
  1066.   did -o $dname 14 1 $base($hget(GeoSketch,Arm $+ %select $+ Color2),10,16,6)
  1067.  
  1068.   did -o $dname 18 1 $hget(GeoSketch,Arm $+ %select $+ Length)
  1069.   did -o $dname 20 1 $hget(GeoSketch,Arm $+ %select $+ Width)
  1070.  
  1071.   did -o $dname 31 1 $hget(GeoSketch,Arm $+ %select $+ Speed)
  1072.   did -o $dname 32 1 $hget(GeoSketch,Arm $+ %select $+ StartAngle)
  1073.  
  1074.   did $iif($hget(GeoSketch,Arm $+ %select $+ Draw),-c,-u) $dname 2
  1075.   did $iif($hget(GeoSketch,Arm $+ %select $+ Show),-c,-u) $dname 3
  1076.  
  1077.   GeoSketch.Dialog.ColorEdit 11
  1078.   GeoSketch.Dialog.ColorEdit 14
  1079. }
  1080.  
  1081. alias GeoSketch.Dialog.ColorEdit {
  1082.   var %id $iif($1,$1,$did)
  1083.   if $regex($did(%id),/([0-9A-Fa-f]{6})/) {
  1084.     window -hp @Armc -1 -1 200 200
  1085.     drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
  1086.     drawsave -b32 @Armc Armc.bmp
  1087.     window -c @Armc
  1088.     if %id == 11 {
  1089.       did -g $dname 10 Armc.bmp
  1090.     }
  1091.     else {
  1092.       did -g $dname 13 Armc.bmp
  1093.     }
  1094.   }
  1095.   if (!$1) {
  1096.     GeoSketch.Dialog.ModifyVar $iif(%id == 11,Color,Color2) $calc($base($regml(1),16,10)) 1
  1097.   }
  1098. }
  1099.  
  1100. alias GeoSketch.Dialog.ModifyVar {
  1101.   var %var $1,%val $2,%select $3
  1102.   var %x $iif(%select,$did($dname,1,0).sel,$hget(GeoSketch,ArmCount))
  1103.   while %x {
  1104.     hadd -m GeoSketch $+(Arm,$iif(%select,$did($dname,1,%x).sel,%x),%var) %val
  1105.     dec %x
  1106.   }
  1107. }
  1108.  
  1109. alias GeoSketch.Export {
  1110.   var %x $hget(GeoSketch,ArmCount)
  1111.   while %x {
  1112.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ StartAngle),$v1,0)
  1113.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Speed),$v1,0)
  1114.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Length),$v1,0)
  1115.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Width),$v1,0)
  1116.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color),$v1,0)
  1117.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color2),$v1,0)
  1118.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Show),$v1,0)
  1119.     var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Draw),$v1,0)
  1120.     var %z $+(%y,:,%z)
  1121.     var %y
  1122.     dec %x
  1123.   }
  1124.   bset -t &Data 1 $+(%z,;,$iif($hget(GeoSketch,Template),$v1,0),;,$iif($hget(GeoSketch,RandSides),$v1,0),;,$hget(GeoSketch,RandParams))
  1125.   var %x $compress(&Data,b)
  1126.   var %x $encode(&Data,bm)
  1127.   var %output $bvar(&Data,1-).text
  1128.   return %output
  1129. }
  1130.  
  1131. alias GeoSketch.Import {
  1132.   bset -t &Data 1 $1-
  1133.   var %x $decode(&Data,bm)
  1134.   var %x $decompress(&Data,bm)
  1135.   var %x $token($bvar(&Data,1-).text,1,59)
  1136.   var %template $token($bvar(&Data,1-).text,2,59)
  1137.   var %sides $token($bvar(&Data,1-).text,3,59)
  1138.   var %params $token($bvar(&Data,1-).text,4,59)
  1139.   var %y 1
  1140.   if ($dialog(ArmParameters)) dialog -c ArmParameters
  1141.   if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
  1142.   while $token(%x,%y,58) != $null {
  1143.     tokenize 32 $v1
  1144.     hadd -m GeoSketch Arm $+ %y $+ StartAngle $1
  1145.     hadd -m GeoSketch Arm $+ %y $+ Speed $2
  1146.     hadd -m GeoSketch Arm $+ %y $+ Length $3
  1147.     hadd -m GeoSketch Arm $+ %y $+ Width $4
  1148.     hadd -m GeoSketch Arm $+ %y $+ Color $5
  1149.     hadd -m GeoSketch Arm $+ %y $+ Color2 $6
  1150.     hadd -m GeoSketch Arm $+ %y $+ Show $7
  1151.     hadd -m GeoSketch Arm $+ %y $+ Draw $8
  1152.     hadd -m GeoSketch Arm $+ %y $+ Angle $1
  1153.     hdel -m GeoSketch Arm $+ %y $+ Last.X
  1154.     hdel -m GeoSketch Arm $+ %y $+ Last.Y
  1155.     inc %y
  1156.   }
  1157.   hadd -m GeoSketch RandSides $iif(%sides,$v1,0)
  1158.   hadd -m GeoSketch RandParams %params
  1159.   dec %y
  1160.   hadd -m GeoSketch ArmCount %y
  1161.   hadd -m GeoSketch Template %template
  1162.   GeoSketch.HandleDraw
  1163. }
  1164.  
  1165. alias GeoSketch.ExportRotatix {
  1166.   var %color $rgb(15,15,15)
  1167.   var %bgColor 0
  1168.   var %glowColor $rgb(255,255,255)
  1169.   var %glowStrength 2
  1170.   var %glowBlurX 6
  1171.   var %glowBlurY 6
  1172.   var %glowAlpha 40
  1173.   var %y $hget(GeoSketch,ArmCount),%x 1
  1174.   bset -t &Data 1 $+($chr(40),%bgColor)
  1175.   var %arm1Speed $hget(GeoSketch,Arm1Speed)
  1176.  
  1177.   while %x <= %y {
  1178.     var %template $iif($hget(GeoSketch,Template),360 / $v1,%arm1speed)
  1179.     var %armSpeed $calc(($hget(GeoSketch,Arm $+ %x $+ Speed) / %arm1Speed) * %template)
  1180.     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
  1181.     inc %x
  1182.   }
  1183.   bset &Data $calc($bvar(&Data,0) + 1) 41 13 13
  1184.   var %x $compress(&Data,b)
  1185.   var %z $encode(&Data,mb)
  1186.   return &Data
  1187. }
  1188.  
  1189.  
  1190. alias GenRand {
  1191.   var %id $ticks
  1192.   var %x $1
  1193.   tokenize 32 $2-
  1194.   var %file Export $+ %id $+ .txt
  1195.   .fopen -no %id %file
  1196.   while %x {
  1197.     var %rand $ [ $+ [ $r(1,$0) ] ]
  1198.     var %armCount $r(18,27)
  1199.     hadd -m GeoSketch ArmCount %armcount
  1200.     echo -a Generating Image with $+(,%armCount,) arms using: %rand
  1201.     %rand
  1202.     GeoSketch.ExportRotatix
  1203.     .fwrite -bn %id &Data
  1204.     .fwrite -n %id $crlf
  1205.     ;echo -a Wrote $qt($bvar(&Data,0)) bytes
  1206.     bunset &Data
  1207.     dec %x
  1208.   }
  1209.   run %file
  1210.   .fclose %id
  1211. }
  1212.  
  1213. alias rotatixEnc {
  1214.   tokenize 32 $1-
  1215.   var %str 360 / (sideCount / (key - (((floor(x / (2^(b*(n-1)))) / (2^b)) - floor(floor(x / (2^(b*(n-1)))) / (2^b))) * (2^b))))
  1216.   var %bits 8
  1217.   var %key $calc(2^ (%bits - 1) - 1)
  1218.   var %sideCount $1
  1219.   tokenize 32 $2-
  1220.   var %x 1,%y
  1221.   while %x <= $0 {
  1222.     var %deg $ [ $+ [ %x ] ] % %key
  1223.     var %offset $calc((%key - %deg) * 2^(%bits * (%x - 1)))
  1224.     inc %y %offset
  1225.     inc %x
  1226.   }
  1227.   return $replace(%str,x,%y,key,%key,sideCount,%sideCount,b,%bits)
  1228. }
  1229.  
  1230. ;;;;;;;;
  1231. ; Menu ;
  1232. ;;;;;;;;
  1233.  
  1234. menu * {
  1235.   -
  1236.   GeoSketch: /GeoSketch.InitGui
  1237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement