Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; GeoSketch ;
- ; Coded by: Imk0tter ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Usage: To start GeoSketch, right click a window and click GeoSketch ;
- ; ;
- ; * To bring up the arm parameters, press "s" or "w" ;
- ; ;
- ; * To generate a random drawing, press 1 through 6 ;
- ; ;
- ; * To start or stop drawing, press "d" ;
- ; ;
- ; * To toggle the export label, press "L" ;
- ; ;
- ; * To apply a sketch to the background, hold "shift" and click ;
- ; where you would like to place your drawing ;
- ; ;
- ; * To clear the drawing buffer, press "c" ;
- ; ;
- ; * You can zoom in using the "up" and "down" arrows ;
- ; ;
- ; * To take a screenshot of the drawing buffer, press Enter ;
- ; ;
- ; * To toggle the drawing arms, press "h" ;
- ; ;
- ; * You can pan around the background by holding left click and ;
- ; dragging the mouse ;
- ; ;
- ; * Many more options can be found in the menu ;
- ; ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;
- ; Input ;
- ;;;;;;;;;
- alias GeoSketch.PromptImport {
- if !$dialog(geoImport) { dialog -dm geoImport Import }
- else { did -f geoImport 2 }
- }
- alias GeoSketch.PromptExport {
- if !$dialog(geoExport) { dialog -dm geoExport Export }
- else { did -f geoExport 2 }
- }
- on 1:keydown:@GeoSketch:*: {
- if $keyChar == s || $keyChar == w {
- if (!$dialog(ArmParameters)) {
- var %x $dialog(ArmParameters,armp,@GeoSketch)
- }
- else {
- did -f ArmParameters 1
- }
- }
- if $isalias(GeoSketch.Gen $+ $keyChar) {
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- GeoSketch.Gen $+ $keyChar
- GeoSketch.HandleDraw
- }
- ;Generate Random
- if $keyChar == r {
- GeoSketch.Rand3 $hget(GeoSketch,ArmCount)
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- GeoSketch.HandleDraw
- }
- ;Generate Structured Random
- else if $keyChar == t {
- GeoSketch.Rand2 $hget(GeoSketch,ArmCount)
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- GeoSketch.HandleDraw
- }
- ;Export current Drawing
- else if $keyChar == e {
- GeoSketch.PromptExport
- }
- ;Bring up import dialog
- else if $keyChar == i {
- GeoSketch.PromptImport
- }
- ;Start/stop drawing
- else if $keyChar == d {
- GeoSketch.HandleDraw
- }
- ;Toggle Export label below drawing
- else if $keyChar == l {
- hadd -m GeoSketch DrawLabel $iif($hget(GeoSketch,DrawLabel),0,1)
- }
- ;Toggle arm drawing
- else if $keyChar == h {
- hadd -m GeoSketch DrawArms $iif($hget(GeoSketch,DrawArms),0,1)
- }
- ;Clear drawing buffer
- else if $keyChar == c {
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- clear @GeoSketchDrawBuff
- }
- ;Zoom out (Down Arrow)
- else if $keyVal == 40 {
- return $GeoSketch.Zoom(1)
- }
- ;Zoom in (Up Arrow)
- else if $keyVal == 38 {
- return $GeoSketch.Zoom(0)
- }
- ;Save screenshot to mirc directory (Enter)
- else if $keyVal == 13 {
- var %z $ticks
- var %saveDir $mircdirSketches
- var %saveFile $+(GeoSketch,-,%z,.jpg)
- var %savepath $+(%saveDir,\,%saveFile)
- var %w $hget(GeoSketch,DrawBuff.w)
- var %h $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * 30)) + 20
- while $window(@GeoSketchSaveBuff).h != %h {
- window -hp @GeoSketchSaveBuff -1 -1 %w %h
- }
- drawCopy -n @GeoSketchDrawBuff 0 0 %w %h @GeoSketchSaveBuff 0 0
- if !$exists(%saveDir) {
- mkdir $qt(%saveDir)
- }
- drawSave -b32q100 @GeoSketchSaveBuff $qt(%savePath)
- run mspaint.exe $qt(%savePath)
- window -c @GeoSketchSaveBuff
- }
- ;unhandled
- else {
- }
- }
- ;;;;;;;;;;;;;;;;;;;;;;
- ; Gametime rendering ;
- ;;;;;;;;;;;;;;;;;;;;;;
- alias GeoSketch.renderScene {
- var %scale $hget(GeoSketch,Scale)
- var %armCount $hget(GeoSketch,ArmCount)
- var %x 1
- var %totalLength
- var %totalAngle
- while %x <= %armCount {
- var %armAngle $+ %x $hget(GeoSketch,Arm $+ %x $+ Angle)
- var %totalAngle %totalAngle $round($calc(%armAngle [ $+ [ %x ] ] % 360),1)
- var %armLength $+ %x $hget(GeoSketch,Arm $+ %x $+ Length)
- inc %totalLength %armLength [ $+ [ %x ] ]
- var %armSpeed $+ %x $hget(GeoSketch,Arm $+ %x $+ Speed)
- inc %x
- }
- if $hget(GeoSketch,HasInit) == 2 {
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- ;echo @Debug Total Sides: $hget(GeoSketch,Sides)
- }
- }
- else if $hget(GeoSketch,Drawing) {
- hinc -m GeoSketch Sides
- }
- if %totalAngle == $hget(GeoSketch,startAngle) && $hget(GeoSketch,Drawing) {
- if $hget(GeoSketch,HasInit) == 1 {
- hinc -m GeoSketch HasInit
- }
- else {
- hadd -m GeoSketch HasInit 1
- hadd -m GeoSketch Sides 0
- }
- }
- var %window.w $window(@GeoSketch).w
- var %window.h $window(@GeoSketch).h
- var %scorePadding.w 2
- var %scorePadding.h $hget(GeoSketch,Scorepadding.H)
- var %template $hget(GeoSketch,Template)
- var %fontSize 10
- ;var %boxCount %armCount * 2
- var %boxCount 4
- var %score.w $int($calc((%window.w - ((%boxCount + 1) * %scorePadding.w)) / %boxCount) )
- var %score.h $hget(GeoSketch,Score.H)
- var %m.x $iif($hget(GeoSketch,MouseLock),$hget(GeoSketch,Mouse.X),$mouse.x)
- var %m.y $iif($hget(GeoSketch,MouseLock),$hget(GeoSketch,Mouse.Y),$mouse.y)
- if (%m.x != $null && %m.y != $null) {
- if $hget(GeoSketch,Moving) {
- var %mouse.x $calc((%m.x - $hget(GeoSketch,Mouse.X)) * %scale)
- var %mouse.y $calc((%m.y - $hget(GeoSketch,Mouse.Y)) * %scale)
- var %newX $iif($calc($hget(GeoSketch,Buffer.X) - %mouse.x) > 0,$v1,0)
- var %newY $iif($calc($hget(GeoSketch,Buffer.Y) - %mouse.y) > 0,$v1,0)
- if %newX < $calc($window(@GeoSketchBuffer).w - 2 - $window(@GeoSketch).w * %scale) {
- hadd -m GeoSketch Buffer.X $v1
- }
- else {
- hadd -m GeoSketch Buffer.X $v2
- }
- if %newY < $calc($window(@GeoSketchBuffer).h - 2 - (($window(@GeoSketch).h - %score.h - %scorePadding.h * 2) * %scale)) {
- hadd -m GeoSketch Buffer.Y $v1
- }
- else {
- hadd -m GeoSketch Buffer.Y $v2
- }
- }
- hadd -m GeoSketch Mouse.X %m.x
- hadd -m GeoSketch Mouse.Y %m.y
- }
- 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))
- var %buff.w $hget(GeoSketch,DrawBuff.W)
- var %buff.h $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * $hget(GeoSketch,DrawBuff.lh)))
- 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)
- var %box.x %score.w + %scorePadding.w
- var %currBox.x %window.w - %box.x
- dec %currBox.x 10
- var %text.h $calc(%score.h / 2 + %scorePadding.h - ($height(T,Tahoma,%fontSize) / 2))
- var %boxColor $rgb(220,220,220)
- var %borderColor $rgb(100,100,100)
- var %textColor $rgb(0,0,0)
- var %x 1
- var %arm.x $iif(%m.x,$v1,$hget(GeoSketch,Mouse.X))
- var %arm.y $iif(%m.y,$v1,$hget(GeoSketch,Mouse.Y))
- var %mouse.x %arm.x
- var %mouse.y %arm.y
- var %degPerFrame $iif(%template,360 / %template,%armSpeed1)
- var %drawArms $hget(GeoSketch,DrawArms)
- var %drawArm.X %arm.x
- var %drawArm.Y %arm.Y
- while %x <= %armCount {
- var %color $hget(GeoSketch,Arm $+ %x $+ Color)
- var %color2 $hget(GeoSketch,Arm $+ %x $+ Color2)
- var %lastX.X %drawArm.x
- var %lastX.Y %drawArm.y
- var %zzz $calc(%armSpeed [ $+ [ %x ] ] / %armSpeed1)
- var %armSin $cos(%armAngle [ $+ [ %x ] ]).deg
- var %armCos $sin(%armAngle [ $+ [ %x ] ]).deg
- var %arm.x $calc(%armSin * %armLength [ $+ [ %x ] ] + %arm.x)
- var %arm.y $calc(%armCos * %armLength [ $+ [ %x ] ] + %arm.y)
- var %diff.x %arm.x - %mouse.x
- var %diff.y %arm.y - %mouse.y
- if $hget(GeoSketch,Arm $+ %x $+ Last.X) != $null {
- var %distanceRatio $sqrt($calc($abs(%diff.x) ^ 2 + $abs(%diff.y) ^ 2)) / %totalLength
- var %armColor $color2colorratio(%color,%color2,%distanceRatio)
- }
- else {
- var %armColor %color
- }
- var %drawArm.x $calc(%armSin * (%armLength [ $+ [ %x ] ] / %scale) + %drawArm.x)
- var %drawArm.y $calc(%armCos * (%armLength [ $+ [ %x ] ] / %scale) + %drawArm.y)
- hinc GeoSketch Arm $+ %x $+ Angle $calc(%zzz * %degPerFrame)
- ;If Arm.Show == 1
- if $hget(GeoSketch,Arm $+ %x $+ Show) && %drawArms {
- drawLine -nr @GeoSketch %armColor 2 %lastX.X %lastX.Y %drawArm.x %drawArm.y
- }
- ;If Drawing && Arm.Draw == 1
- if $hget(GeoSketch,Drawing) && $hget(GeoSketch,Arm $+ %x $+ Draw) {
- if $hget(GeoSketch,Arm $+ %x $+ Last.X) != $null {
- 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)
- }
- }
- hadd -m GeoSketch Arm $+ %x $+ Last.X %diff.x
- hadd -m GeoSketch Arm $+ %x $+ Last.Y %diff.y
- inc %x
- }
- if %drawArms {
- drawDot -n @GeoSketch 4 4 $calc(%drawArm.x + 2) $calc(%drawArm.y + 2)
- }
- drawRect -nf @GeoSketch 0 1 0 0 %window.w $hget(GeoSketch,scorePad)
- var %x %armCount
- GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Template: $hget(GeoSketch,Template)
- dec %currBox.x %box.x
- GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Side Count: $hget(GeoSketch,Sides)
- dec %currBox.x %box.x
- GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Arm Count: %armCount
- dec %currBox.x %box.x
- GeoSketch.DrawTextBox GeoSketch %currBox.x %scorePadding.h %score.w %score.h %text.h %fontSize %boxColor %borderColor %textColor Status: $iif($hget(GeoSketch,Drawing),Drawing,Stopped)
- dec %currBox.x %box.x
- drawDot @GeoSketch
- }
- ;;;;;;;;;;;;;;;
- ; Draw
- ;;;;;;;;;;;;;;;;
- ; HUD Drawing ;
- ;;;;;;;;;;;;;;;;
- alias GeoSketch.DrawTextBox {
- ;params <ID> <BOX.X> <BOX.Y> <BOX.W> <BOX.H> <TEXT.Y> <FONTSIZE> <BOX COLOR> <BORDER COLOR> <TEXT COLOR> <TEXT>
- var %id $1
- ;Draw Box
- drawrect -nrf @ $+ $1 $8 1 $2 $3 $4 $5
- ;Draw Border
- drawrect -nr @ $+ $1 $9 1 $2 $3 $4 $5
- ;Draw Text
- drawtext -norf @ $+ $1 $10 "Arial" $7 $calc($4 / 2 + $2 - ($width($11-,Tahoma,$7) / 2)) $6 $11-
- }
- ;;;;;;;;;;;;;;;;;
- ; Square adding ;
- ;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Window/Hash initialization ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias GeoSketch.InitGUI {
- ; Window Width
- ; NOTE: If windows prevents a window this size from being created, lower these numbers
- hadd -m GeoSketch Alive 1
- if !$window(@GeoSketchBuffer) { var %flag 1 }
- var %windowWidth 4000
- var %windowHeight 3000
- while ($window(@GeoSketchBuffer).w != %windowWidth) {
- window -hp @GeoSketchBuffer -1 -1 %windowWidth %windowHeight
- }
- var %windowWidthb 1200
- var %windowHeights 1200
- while ($window(@GeoSketchDrawBuff).w != %windowWidthb) {
- window -hp @GeoSketchDrawBuff -1 -1 %windowWidthb %windowHeights
- }
- ;Score Padding
- var %scorePad 30
- var %board.x 0
- var %board.y %scorePad
- hadd -m GeoSketch scorePad %scorePad
- hadd -m GeoSketch board.x %board.x
- hadd -m GeoSketch board.y %board.y
- var %armCount 4
- while %armCount {
- GeoSketch.InitArm
- dec %armCount
- }
- GeoSketch.Gen1
- hadd -m GeoSketch Template 0
- hadd -m GeoSketch Scale 1
- window -Bdp @GeoSketch -1 -1 800 600
- hadd -m GeoSketch Buffer.X $calc(%windowWidth / 2 - 800 / 2)
- hadd -m GeoSketch Buffer.Y $calc(%windowHeight / 2 - 600 / 2)
- hadd -m GeoSketch DrawBuff.X 0
- hadd -m GeoSketch DrawBuff.Y 0
- hadd -m GeoSketch DrawBuff.W 0
- hadd -m GeoSketch DrawBuff.H 0
- hadd -m GeoSketch Score.H 20
- hadd -m GeoSketch ScorePadding.H 5
- hadd -m GeoSketch BGColor $rgb(255,255,255)
- hadd -m GeoSketch DrawArms 1
- var %m1 Welcome to GeoSketch by Imk0tter!
- var %m3 Drag the mouse to pan through the background
- var %m2 To start drawing $+ $chr(44) press "d"
- var %m4 To apply the drawing to the background $+ $chr(44) hold shift and click where you would like it placed
- var %m5 To bring up the arm options $+ $chr(44) press "w" or "s"
- if %flag {
- 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
- 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
- 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
- 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
- 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
- }
- .timerGeoSketch 0 0 GeoSketch.renderScene
- }
- alias GeoSketch.Clear {
- clear @GeoSketchBuffer
- drawFill -nrs @GeoSketchBuffer $hget(GeoSketch,BGColor) $rgb(255,255,255) 0 0
- }
- ;;;;;;;;;;;;;;;;;;;;;;
- ; Pre-game rendering ;
- ;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;
- ; Click alias ;
- ;;;;;;;;;;;;;;;
- alias GeoSketch.Click {
- if ($mouse.key & 4) {
- GeoSketch.ApplyDraw
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- }
- else {
- hadd -m GeoSketch Moving 1
- }
- }
- alias GeoSketch.UClick {
- if ($hget(GeoSketch,Drawing) == 1) {
- hadd -m GeoSketch Drawing 0
- hdel -m GeoSketch Last.X
- hdel -m GeoSketch Last.Y
- }
- hadd -m GeoSketch Moving 0
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Mouse Events ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- menu @GeoSketch {
- sclick: GeoSketch.Click
- uclick: GeoSketch.UClick
- }
- menu @GeoSketch {
- Arm Parameters: {
- ;if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
- if (!$dialog(ArmParameters)) {
- var %x $dialog(ArmParameters,armp,@GeoSketch)
- }
- else {
- did -f ArmParameters 1
- }
- }
- }
- alias GeoSketch.SetTemplate {
- if $1 != $null {
- hadd -m GeoSketch Template $1
- }
- if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
- var %x $hget(GeoSketch,ArmCount)
- while %x {
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- }
- }
- menu @GeoSketch {
- Import Sketch: GeoSketch.PromptImport
- Export Sketch: GeoSketch.PromptExport
- Calculate Ratios: DegToSide
- Clear Scene: GeoSketch.Clear
- Change Background: {
- if !$dialog(geoBg) { dialog -dm geoBg bgcolor }
- else {
- did -f geoBg 2
- }
- }
- }
- menu @GeoSketch {
- .Drawing Sides
- ..Set Custom: GeoSketch.SetTemplate $Input(Enter the number of sides for the template,eo,Template Sides)
- ..Set 0: GeoSketch.SetTemplate 0
- ..Set 2: GeoSketch.SetTemplate 2
- ..Set 3: GeoSketch.SetTemplate 3
- ..Set 4: GeoSketch.SetTemplate 4
- ..Set 5: GeoSketch.SetTemplate 5
- ..Set 6: GeoSketch.SetTemplate 6
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Closing Events ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- on 1:close:@GeoSketch: {
- if $hget(GeoSketch) { hfree GeoSketch }
- if ($window(@GeoSketchBuffer)) window -c @GeoSketchbuffer
- .timerGeoSketch off
- }
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; General GeoSketch Functions ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- alias GeoSketch.InitDrawing {
- if $hget(GeoSketch,Drawing) {
- GeoSketch.HandleDraw
- }
- clear @GeoSketchDrawBuff
- var %x $hget(GeoSketch,ArmCount)
- while %x {
- hadd -m GeoSketch Arm $+ %x $+ Angle $hget(GeoSketch,Arm $+ %x $+ StartAngle))
- dec %x
- }
- GeoSketch.HandleDraw
- }
- alias GeoSketch.initArm {
- hinc -m GeoSketch ArmCount
- var %armCount $hget(GeoSketch,ArmCount)
- hadd -m GeoSketch $+(Arm,%armCount,Length) 50
- hadd -m GeoSketch $+(Arm,%armCount,Speed) 0
- hadd -m GeoSketch $+(Arm,%armCount,Width) 1
- hadd -m GeoSketch $+(Arm,%armCount,StartAngle) 90
- hadd -m GeoSketch $+(Arm,%armCount,Color) $r(0,$rgb(255,255,255))
- hadd -m GeoSketch $+(Arm,%armCount,Color2) $r(0,$rgb(255,255,255))
- hadd -m GeoSketch $+(Arm,%armCount,Draw) 1
- hadd -m GeoSketch $+(Arm,%armCount,Show) 1
- hadd -m GeoSketch $+(Arm,$calc(%armCount - 1),Draw) 0
- }
- alias Color2ColorRatio {
- var %color1 $rgb($1)
- var %color2 $rgb($2)
- var %color2Ratio $3
- var %color1Ratio 1 - $3
- var %red $calc($token(%color1,1,44) * %color1Ratio + $token(%color2,1,44) * %color2Ratio)
- var %green $calc($token(%color1,2,44) * %color1Ratio + $token(%color2,2,44) * %color2Ratio)
- var %blue $calc($token(%color1,3,44) * %color1Ratio + $token(%color2,3,44) * %color2Ratio)
- return $rgb(%red,%green,%blue)
- }
- alias GeoSketch.HandleDraw {
- hadd -m GeoSketch Drawing $iif($hget(GeoSketch,Drawing),0,2)
- if !$hget(GeoSketch,Drawing) {
- var %x $hget(GeoSketch,ArmCount)
- while %x {
- hdel -m GeoSketch Arm $+ %x $+ Last.X
- hdel -m GeoSketch Arm $+ %x $+ Last.Y
- dec %x
- }
- }
- else {
- var %x $hget(GeoSketch,ArmCount),%y,%z
- while %x {
- hdel -m GeoSketch Arm $+ %x $+ Last.X
- hdel -m GeoSketch Arm $+ %x $+ Last.Y
- inc %y $hget(GeoSketch,Arm $+ %x $+ Length)
- var %z $round($calc($hget(GeoSketch,Arm $+ %x $+ Angle) % 360),1) %z
- dec %x
- }
- clear @GeoSketchDrawBuff
- hadd -m GeoSketch StartAngle %z
- hadd -m GeoSketch HasInit 0
- var %w $calc(%y * 2),%h %w
- var %export $GeoSketch.export
- var %x $wrap(%export,Arial,12,$calc(%w - 50),0)
- var %h2 $calc(%h + (%x * $height(%export,Arial,12)))
- ;if $width(%export,Arial,12) > %w { var %w $width(%export,Arial,12) }
- while %x {
- var %txt $wrap(%export,Arial,12,$calc(%w - 50),%x)
- drawtext -norf @GeoSketchDrawBuff 0 "Arial" 12 $calc((%w / 2) - ($width(%txt,Arial,12) / 2)) $calc(%h + $height(%txt,Arial,12) * (%x - 1)) %txt
- dec %x
- }
- ;drawtext -norf @GeoSketchDrawBuff 0 "Arial" 12 $calc((%w / 2) - ($width(%export,Arial,12) / 2)) %h %export
- hadd -m GeoSketch DrawBuff.x $calc(%w / 2)
- hadd -m GeoSketch DrawBuff.y $calc(%h / 2)
- hadd -m GeoSketch DrawBuff.w %w
- hadd -m GeoSketch DrawBuff.h %h
- hadd -m GeoSketch DrawBuff.lh $calc(%h2 - %h)
- }
- }
- alias GeoSketch.ApplyDraw {
- var %scale $hget(GeoSketch,Scale)
- var %base.x $calc($hget(GeoSketch,Buffer.X) + ($mouse.x * %scale) - $hget(GeoSketch,DrawBuff.X))
- var %base.Y $calc($hget(GeoSketch,Buffer.Y) + (($mouse.y - $hget(GeoSketch,Score.H) - $hget(GeoSketch,Scorepadding.H) * 2) * %scale) - $hget(GeoSketch,DrawBuff.Y))
- 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
- ;drawCopy -n @GeoSketchDrawBuff 0 0 $hget(GeoSketch,DrawBuff.W) $calc($hget(GeoSketch,DrawBuff.H) + ($hget(GeoSketch,DrawLabel) * 20)) @GeoSketchBuffer %base.x %base.y
- }
- alias GeoSketch.Zoom {
- var %zoomRatio 0.125
- if $1 {
- hinc -m GeoSketch Scale %zoomRatio
- var %newX $iif($calc($hget(GeoSketch,Buffer.X) - $window(@GeoSketch).w * (%zoomRatio / 2)) > 0,$v1,0)
- 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)
- if %newX > $calc($window(@GeoSketchBuffer).w - 2 - ($window(@GeoSketch).w * $hget(GeoSketch,Scale))) $&
- || %newY > $calc($window(@GeoSketchBuffer).h - 2 - (($window(@GeoSketch).h - $hget(GeoSketch,Score.h) - $hget(GeoSketch,Scorepadding.h) * 2) * $hget(GeoSketch,Scale))) {
- hdec -m GeoSketch Scale %zoomRatio
- }
- else {
- hadd -m GeoSketch Buffer.X %newX
- hadd -m GeoSketch Buffer.Y %newY
- }
- }
- else {
- if $hget(GeoSketch,Scale) > %zoomRatio {
- var %newX $iif($calc($hget(GeoSketch,Buffer.X) + $window(@GeoSketch).w * (%zoomRatio / 2)) > 0,$v1,0)
- 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)
- hdec -m GeoSketch Scale %zoomRatio
- hadd -m GeoSketch Buffer.X %newX
- hadd -m GeoSketch Buffer.Y %newY
- }
- }
- }
- ;;;;;;;;;;;;;;;;
- ; Random ;
- ;;;;;;;;;;;;;;;;
- alias GeoSketch.Rand2 {
- hdel -m GeoSketch Last.X
- hdel -m GeoSketch Last.Y
- hadd -m GeoSketch ArmCount $1
- hadd -m GeoSketch Color $r(0,16777215)
- hadd -m GeoSketch Color2 $r(0,16777215)
- var %x $1,%y,%z
- while %x {
- 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))
- hinc -m GeoSketch Arm $+ %x $+ Speed $iif($r(0,1),0.5,0)
- hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- }
- }
- alias GeoSketch.Rand3 {
- hdel -m GeoSketch Last.X
- hdel -m GeoSketch Last.Y
- var %x $1
- var %y,%z
- while %x {
- hadd -m GeoSketch Arm $+ %x $+ Speed $calc($r(0,1000) - 500)
- hadd -m GeoSketch Arm $+ %x $+ Length $r(50,125)
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- }
- hadd -m GeoSketch Color $r(0,16777215)
- hadd -m GeoSketch Color2 $r(0,16777215)
- hadd -m GeoSketch ArmCount $1
- }
- alias GeoSketch.Gen1 {
- if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
- hdel -m GeoSketch Last.X
- hdel -m GeoSketch Last.Y
- tokenize 32 $1-
- var %x $hget(GeoSketch,ArmCount),%y %x
- var %sideCount $iif($1,$1,$r(1500,6000))
- if $calc(%sideCount % 2) { dec %sideCount }
- var %flutterSides $iif(%sideCount > 1500,$iif(%sideCount > 3000,8,6),4)
- var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
- var %length $r(5,12)
- hadd GeoSketch Arm $+ %x $+ Speed $calc((%speed + 180) * $iif($r(0,1),1,-1))
- hadd GeoSketch Arm $+ %x $+ Length $r(22,28)
- hadd GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- hadd -m GeoSketch Arm $+ %x $+ Speed %speed
- hadd -m GeoSketch Arm $+ %x $+ Length %length
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- dec %y 2
- GeoSketch.GenDefault %sideCount %x $2-
- }
- alias GeoSketch.Gen5 {
- var %m $r(2,4)
- return $GeoSketch.Gen2($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
- }
- alias GeoSketch.Gen2 {
- tokenize 32 $1-
- var %y $hget(GeoSketch,ArmCount),%x 1,%z
- while %x <= %y {
- var %r $iif($ [ $+ [ $calc(%x + 1) ] ] != $null,$v1,$int($calc($r(4,104) / 4)))
- ;var %r $iif($ [ $+ [ $calc(%x + 1) ] ],$v1,$r(4,180))
- var %tn $v1
- var %r $iif($regex($prop,/(m)+(\d+)/),$calc(%r + (1 / $iif($regml(2),$v1,2))),%r)
- if !%tn {
- var %r $calc(%r * ($r(0,1) * 2 - 1))
- }
- var %z %z %r
- inc %x
- }
- GeoSketch.GenDefault $iif($1,$1,$calc($r(20,50) + (1 / $r(8,20)))) %y %z
- }
- alias GeoSketch.Gen6 {
- var %m $r(4,6)
- return $GeoSketch.Gen2($calc($r(1,80) + (1 / $r(10,15) / %m))).sm [ $+ [ %m ] ]
- }
- alias GeoSketch.Gen4 {
- return $geoSketch.Gen3($calc($r(36,130) + (1 / $r(6,12))))
- ;return $geoSketch.Gen3($r(36,130))
- }
- alias GeoSketch.Gen3 {
- if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
- hdel -m GeoSketch Last.X
- hdel -m GeoSketch Last.Y
- tokenize 32 $1-
- var %flutterSides 6
- var %x $hget(GeoSketch,ArmCount),%y %x
- var %sideCount $iif($1,$1,$r(36,2000))
- var %speed $calc(360 / (%sideCount / (360 / %flutterSides)))
- var %length $r(10,15)
- hadd -m GeoSketch Arm $+ %x $+ Speed %speed
- hadd -m GeoSketch Arm $+ %x $+ Length %length
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- dec %y
- if t isin $prop {
- hadd -m GeoSketch Arm $+ %x $+ Length $r(15,40)
- hadd -m GeoSketch Arm $+ %x $+ Speed $calc((360 / %sideCount ) / $r(11,22))
- dec %x
- dec %y
- }
- GeoSketch.GenDefault %sideCount %x $2-
- }
- alias GeoSketch.GenDefault {
- tokenize 32 $1-
- var %maxLength 400,%minLength 50
- var %sideCount $1,%x $2,%y %x
- tokenize 32 $3-
- while %x {
- var %rand $iif($ [ $+ [ %x ] ] != $null,$v1,$int($calc($r(11,121) / 11)))
- if $v1 == $null {
- var %rand $calc(%rand * ($r(0,1) * 2 - 1)))
- }
- var %k $calc(360 / (%sideCount / %rand)) %k
- hadd -m GeoSketch Arm $+ %x $+ Length $r($int($calc((%maxLength / %y) / 3)),$calc(%maxLength / %y))
- hadd -m GeoSketch Arm $+ %x $+ Speed $calc(360 / (%sideCount / %rand))
- hadd -m GeoSketch Arm $+ %x $+ Angle 90
- dec %x
- }
- var %y $hget(GeoSketch,ArmCount),%x %y,%z
- while %y {
- var %a $hget(GeoSketch,Arm $+ %y $+ Speed)
- var %z $round($calc(%sideCount / (360 / %a)),4) %z
- var %k %a %k
- dec %y
- }
- if $window(@Debug) {
- echo @Debug Sides: %sideCount - Ratios: %z - Speeds: %k - Tube: $iif(%tube,Yes,No)
- ; clipboard $RotatixEnc(%sideCount,%z)
- }
- }
- alias DegToSide {
- var %x $hget(GeoSketch,ArmCount),%z
- while %x {
- var %z $hget(GeoSketch,Arm $+ %x $+ Speed) %z
- dec %x
- }
- tokenize 32 %z
- var %sideCount $lcmzz($regsubex($1-,/(\d+\.*\d*)/g,$calc(360 / \1)))
- var %armRatio $regsubex($1-,/(\d+\.*\d*)/g,$calc(%sideCount / (360 / \1)))
- if !$dialog(GeoESides) { dialog -dm geoESides export }
- else { did -f geoESides 2 }
- did -a geoESides 2 Side Count: %sideCount - Ratios: %armRatio - Speeds: $1-
- }
- alias Lcmzz {
- var %maxIter 2000
- tokenize 32 $sorttok($1-,32,n)
- var %tolerance 0.5
- while $abs($calc($token($1,1,58) - $token($token($1-,-1,32),1,58))) > %tolerance && %maxIter > 0 {
- tokenize 32 $sorttok($+($abs($calc($replace($1,:,+))),:,$iif($token($1,2,58),$v1,$abs($1))) $2-,32,n)
- dec %maxIter
- }
- return $iif(%maxIter > 0,$token($1,1,58),360)
- }
- dialog bgcolor {
- title "Background Color"
- size -1 -1 119 26
- option dbu
- icon 1, 5 6 15 15
- edit "FFFFFF", 2, 25 12 50 10
- text "Background Color:", 3, 25 4 52 8
- button "Change Color", 4, 79 4 37 18
- }
- dialog armp {
- title "Arm Options"
- size -1 -1 236 252
- option dbu
- list 1, 1 17 59 209, size extsel vsbar
- check "Draw Selected Arms", 2, 68 25 62 10
- check "Show Selected Arms", 3, 68 13 60 10
- button "Set All To This Value", 4, 168 10 54 12
- button "Set All To This Value", 7, 168 24 54 12
- box "Display Options", 8, 64 2 170 38
- box "Arm Colors", 9, 64 42 171 65
- icon 10, 68 58 15 15
- edit "FFFFFF", 11, 86 62 50 11
- box "Arm Parameters", 12, 64 107 171 90
- icon 13, 68 83 15 15
- edit "FFFFFF", 14, 86 88 50 10
- text "Color I:", 15, 87 54 25 8
- text "Color II:", 16, 87 80 25 8
- text "Length:", 17, 68 122 19 8, right
- edit "", 18, 86 121 50 10
- text "Width:", 19, 70 136 17 8, right
- edit "", 20, 86 135 50 10
- text "Speed:", 21, 69 164 18 8, right
- text "Angle:", 22, 69 178 18 8, right
- button "Set All To This Value", 23, 168 60 54 12
- button "Set All To This Value", 24, 168 86 54 12
- button "Set All To This Value", 25, 168 120 54 12
- button "Set All To This Value", 26, 168 134 54 12
- text "Arms:", 27, 8 7 15 8
- button "+", 28, 44 7 7 7
- button "-", 29, 28 7 7 7
- button "Accept", 30, 2 230 58 19
- edit "", 31, 86 163 50 10
- edit "", 32, 86 177 50 10
- button "Set All To This Value", 33, 168 161 54 12
- button "Set All To This Value", 34, 168 175 54 12
- box "Random", 35, 64 197 171 54
- combo 36, 86 208 50 58, size vsbar drop
- text "Type:", 37, 69 210 17 8, right
- button "Generate", 38, 168 212 54 28
- edit "", 5, 86 222 50 10
- edit "", 6, 86 235 50 10
- text "Sides:", 39, 62 223 25 8, right
- text "Params:", 40, 62 236 25 8, right
- }
- dialog export {
- title "Export Drawing"
- size -1 -1 236 62
- option dbu
- text "Your Export Has been printed below:", 1, 67 4 97 8, center
- edit "", 2, 5 17 228 29, read multi vsbar
- button "Copy", 3, 100 48 37 12
- }
- dialog import {
- title "Import Drawing"
- size -1 -1 236 62
- option dbu
- text "Enter string to import:", 1, 67 4 97 8, center
- edit "", 2, 5 17 228 29, multi vsbar
- button "Import", 3, 100 48 37 12
- }
- on 1:dialog:geoBg:init:0: {
- GeoSketch.Dialog.BGEdit
- }
- on 1:dialog:geoBg:edit:2 {
- GeoSketch.Dialog.BGEdit
- }
- on 1:dialog:geoBg:sclick:4: {
- if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
- var %oldc $hget(GeoSketch,BGColor)
- hadd -m GeoSketch BGColor $base($regml(1),16,10)
- drawFill -nrs @GeoSketchBuffer $base($regml(1),16,10) %oldc 0 0
- }
- dialog -c $dname
- }
- alias GeoSketch.Dialog.BGEdit {
- var %id $iif($1,$1,$did)
- if $regex($did($dname,2),/([0-9A-Fa-f]{6})/) {
- window -hp @Armc -1 -1 200 200
- drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
- drawsave -b32 @Armc Armc.bmp
- window -c @Armc
- did -g $dname 1 Armc.bmp
- }
- }
- on 1:dialog:geoExport:init:0: { did -a $dname 2 $GeoSketch.export }
- on 1:dialog:geoE*:sclick:3: {
- var %x $did($dname,2).lines,%z
- while %x {
- var %z $did($dname,2,%x) $+ %z
- dec %x
- }
- clipboard %z
- dialog -c $dname
- }
- on 1:dialog:geoImport:sclick:3: {
- var %x $did($dname,2).lines,%z
- while %x {
- var %z $did($dname,2,%x) $+ %z
- dec %x
- }
- GeoSketch.Import %z
- dialog -c $dname
- GeoSketch.InitDrawing
- }
- ;;;;;;;;;;;;;;;;;;;;;
- ; Dialog Init ;
- ;;;;;;;;;;;;;;;;;;;;;
- on 1:dialog:arm*:init:0: {
- if $window(@Armc) { clear @Armc }
- else { window -hp @Armc -1 -1 200 200 }
- drawsave -b32 @Armc Armc.bmp
- window -c @Armc
- did -g $dname 10 Armc.bmp
- did -g $dname 13 Armc.bmp
- var %x $hget(GeoSketch,ArmCount),%y 1
- while %y <= %x {
- did -a $dname 1 %y
- inc %y
- }
- did -c $dname 1 1
- if %x > 0 {
- GeoSketch.Dialog.ArmSelect 1
- }
- var %x 1
- while $isalias(GeoSketch.Gen $+ %x) {
- did -a $dname 36 Gen $+ %x
- inc %x
- }
- did -c $dname 36 1
- did -o $dname 5 1 $hget(GeoSketch,RandSides)
- did -o $dname 6 1 $hget(GeoSketch,RandParams)
- hadd -m GeoSketch MouseLock 1
- hadd -m GeoSketch Mouse.X $calc($window(@GeoSketch).w / 2)
- hadd -m GeoSketch Mouse.Y $calc(($window(@GeoSketch).h - $hget(GeoSketch,ScorePadding) * 2 - $hget(GeoSketch,Score.h)) / 2)
- }
- on 1:dialog:arm*:close:0: { hadd -m GeoSketch MouseLock 0 | GeoSketch.InitDrawing }
- on 1:dialog:arm*:sclick:2-3: { GeoSketch.Dialog.ChangeDisplay | GeoSketch.InitDrawing }
- on 1:dialog:arm*:edit:11,14: { GeoSketch.Dialog.ColorEdit | GeoSketch.InitDrawing }
- on 1:dialog:arm*:sclick:1: { GeoSketch.Dialog.ArmSelect }
- on 1:dialog:arm*:edit:18,20,31,32: { GeoSketch.Dialog.ArmEdit | GeoSketch.InitDrawing }
- on 1:dialog:arm*:edit:5,6: { GeoSketch.Dialog.RandEdit }
- on 1:dialog:arm*:sclick:25,26,33,34,23,24,4,7: { GeoSketch.Dialog.SetAll | GeoSketch.InitDrawing }
- on 1:dialog:arm*:sclick:28-29: { GeoSketch.Dialog.ChangeArm | GeoSketch.InitDrawing }
- on 1:dialog:arm*:sclick:38: { GeoSketch.Dialog.GenRand | GeoSketch.InitDrawing }
- on 1:dialog:arm*:sclick:30: {
- dialog -c $dname
- hadd -m GeoSketch MouseLock 0
- GeoSketch.InitDrawing
- }
- alias GeoSketch.Dialog.RandEdit {
- hadd -m GeoSketch RandSides $did($dname,5)
- hadd -m GeoSketch RandParams $did($dname,6)
- }
- alias GeoSketch.Dialog.GenRand {
- GeoSketch. $+ $did($dname,36).seltext $did($dname,5) $did($dname,6)
- GeoSketch.Dialog.ArmSelect
- GeoSketch.InitDrawing
- }
- alias GeoSketch.Dialog.ChangeDisplay {
- var %state $did($dname,$did).state
- if $did == 3 {
- GeoSketch.Dialog.ModifyVar Show %state 1
- }
- else {
- GeoSketch.Dialog.ModifyVar Draw %state 1
- }
- }
- alias GeoSketch.Dialog.ChangeArm {
- var %id $iif($1,$1,$did)
- if %id == 28 {
- GeoSketch.InitArm
- did -a $dname 1 $hget(GeoSketch,ArmCount)
- did -c $dname 1 $hget(GeoSketch,ArmCount)
- GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
- }
- else if $hget(GeoSketch,ArmCount) > 1 {
- hdec -m GeoSketch ArmCount
- hadd -m GeoSketch Arm $+ $calc($v1 - 1) $+ Draw 1
- hdel -w GeoSketch Arm $+ $v1 $+ *
- did -d $dname 1 $v1
- did -c $dname 1 $hget(GeoSketch,ArmCount)
- GeoSketch.Dialog.ArmSelect $hget(GeoSketch,ArmCount)
- }
- }
- alias GeoSketch.Dialog.SetAll {
- var %id $iif($1,$1,$did)
- goto %id 0
- :4
- GeoSketch.Dialog.ModifyVar Show $did($dname,3).state
- return
- :7
- GeoSketch.Dialog.ModifyVar Draw $did($dname,2).state
- return
- :23
- GeoSketch.Dialog.ModifyVar Color $calc($base($did($dname,11),16,10))
- return
- :24
- GeoSketch.Dialog.ModifyVar Color2 $calc($base($did($dname,14),16,10))
- return
- :25
- GeoSketch.Dialog.ModifyVar Length $calc($did($dname,18))
- return
- :26
- GeoSketch.Dialog.ModifyVar Width $calc($did($dname,20))
- return
- :33
- GeoSketch.Dialog.ModifyVar Speed $calc($did($dname,31))
- return
- :34
- GeoSketch.Dialog.ModifyVar StartAngle $calc($did($dname,32))
- return
- :%id
- :0
- return
- }
- alias GeoSketch.Dialog.ArmEdit {
- var %id $iif($1,$1,$did),%val $calc($did($dname,%id))
- goto %id 0
- :18
- GeoSketch.Dialog.ModifyVar Length %val 1
- return
- :20
- GeoSketch.Dialog.ModifyVar Width %val 1
- return
- :31
- GeoSketch.Dialog.ModifyVar Speed %val 1
- return
- :32
- GeoSketch.Dialog.ModifyVar StartAngle %val 1
- return
- :%id
- :0
- return
- }
- alias GeoSketch.Dialog.ArmSelect {
- var %select $iif($1,$1,$did($dname,1,$did($dname,1,0).sel).sel)
- did -o $dname 11 1 $base($hget(GeoSketch,Arm $+ %select $+ Color),10,16,6)
- did -o $dname 14 1 $base($hget(GeoSketch,Arm $+ %select $+ Color2),10,16,6)
- did -o $dname 18 1 $hget(GeoSketch,Arm $+ %select $+ Length)
- did -o $dname 20 1 $hget(GeoSketch,Arm $+ %select $+ Width)
- did -o $dname 31 1 $hget(GeoSketch,Arm $+ %select $+ Speed)
- did -o $dname 32 1 $hget(GeoSketch,Arm $+ %select $+ StartAngle)
- did $iif($hget(GeoSketch,Arm $+ %select $+ Draw),-c,-u) $dname 2
- did $iif($hget(GeoSketch,Arm $+ %select $+ Show),-c,-u) $dname 3
- GeoSketch.Dialog.ColorEdit 11
- GeoSketch.Dialog.ColorEdit 14
- }
- alias GeoSketch.Dialog.ColorEdit {
- var %id $iif($1,$1,$did)
- if $regex($did(%id),/([0-9A-Fa-f]{6})/) {
- window -hp @Armc -1 -1 200 200
- drawrect -nrf @Armc $base($regml(1),16,10) 1 0 0 $window(@Armc).w $window(@Armc).h
- drawsave -b32 @Armc Armc.bmp
- window -c @Armc
- if %id == 11 {
- did -g $dname 10 Armc.bmp
- }
- else {
- did -g $dname 13 Armc.bmp
- }
- }
- if (!$1) {
- GeoSketch.Dialog.ModifyVar $iif(%id == 11,Color,Color2) $calc($base($regml(1),16,10)) 1
- }
- }
- alias GeoSketch.Dialog.ModifyVar {
- var %var $1,%val $2,%select $3
- var %x $iif(%select,$did($dname,1,0).sel,$hget(GeoSketch,ArmCount))
- while %x {
- hadd -m GeoSketch $+(Arm,$iif(%select,$did($dname,1,%x).sel,%x),%var) %val
- dec %x
- }
- }
- alias GeoSketch.Export {
- var %x $hget(GeoSketch,ArmCount)
- while %x {
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ StartAngle),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Speed),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Length),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Width),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Color2),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Show),$v1,0)
- var %y %y $iif($hget(GeoSketch,Arm $+ %x $+ Draw),$v1,0)
- var %z $+(%y,:,%z)
- var %y
- dec %x
- }
- bset -t &Data 1 $+(%z,;,$iif($hget(GeoSketch,Template),$v1,0),;,$iif($hget(GeoSketch,RandSides),$v1,0),;,$hget(GeoSketch,RandParams))
- var %x $compress(&Data,b)
- var %x $encode(&Data,bm)
- var %output $bvar(&Data,1-).text
- return %output
- }
- alias GeoSketch.Import {
- bset -t &Data 1 $1-
- var %x $decode(&Data,bm)
- var %x $decompress(&Data,bm)
- var %x $token($bvar(&Data,1-).text,1,59)
- var %template $token($bvar(&Data,1-).text,2,59)
- var %sides $token($bvar(&Data,1-).text,3,59)
- var %params $token($bvar(&Data,1-).text,4,59)
- var %y 1
- if ($dialog(ArmParameters)) dialog -c ArmParameters
- if $hget(GeoSketch,Drawing) { GeoSketch.HandleDraw }
- while $token(%x,%y,58) != $null {
- tokenize 32 $v1
- hadd -m GeoSketch Arm $+ %y $+ StartAngle $1
- hadd -m GeoSketch Arm $+ %y $+ Speed $2
- hadd -m GeoSketch Arm $+ %y $+ Length $3
- hadd -m GeoSketch Arm $+ %y $+ Width $4
- hadd -m GeoSketch Arm $+ %y $+ Color $5
- hadd -m GeoSketch Arm $+ %y $+ Color2 $6
- hadd -m GeoSketch Arm $+ %y $+ Show $7
- hadd -m GeoSketch Arm $+ %y $+ Draw $8
- hadd -m GeoSketch Arm $+ %y $+ Angle $1
- hdel -m GeoSketch Arm $+ %y $+ Last.X
- hdel -m GeoSketch Arm $+ %y $+ Last.Y
- inc %y
- }
- hadd -m GeoSketch RandSides $iif(%sides,$v1,0)
- hadd -m GeoSketch RandParams %params
- dec %y
- hadd -m GeoSketch ArmCount %y
- hadd -m GeoSketch Template %template
- GeoSketch.HandleDraw
- }
- alias GeoSketch.ExportRotatix {
- var %color $rgb(15,15,15)
- var %bgColor 0
- var %glowColor $rgb(255,255,255)
- var %glowStrength 2
- var %glowBlurX 6
- var %glowBlurY 6
- var %glowAlpha 40
- var %y $hget(GeoSketch,ArmCount),%x 1
- bset -t &Data 1 $+($chr(40),%bgColor)
- var %arm1Speed $hget(GeoSketch,Arm1Speed)
- while %x <= %y {
- var %template $iif($hget(GeoSketch,Template),360 / $v1,%arm1speed)
- var %armSpeed $calc(($hget(GeoSketch,Arm $+ %x $+ Speed) / %arm1Speed) * %template)
- 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
- inc %x
- }
- bset &Data $calc($bvar(&Data,0) + 1) 41 13 13
- var %x $compress(&Data,b)
- var %z $encode(&Data,mb)
- return &Data
- }
- alias GenRand {
- var %id $ticks
- var %x $1
- tokenize 32 $2-
- var %file Export $+ %id $+ .txt
- .fopen -no %id %file
- while %x {
- var %rand $ [ $+ [ $r(1,$0) ] ]
- var %armCount $r(18,27)
- hadd -m GeoSketch ArmCount %armcount
- echo -a Generating Image with $+(,%armCount,) arms using: %rand
- %rand
- GeoSketch.ExportRotatix
- .fwrite -bn %id &Data
- .fwrite -n %id $crlf
- ;echo -a Wrote $qt($bvar(&Data,0)) bytes
- bunset &Data
- dec %x
- }
- run %file
- .fclose %id
- }
- alias rotatixEnc {
- tokenize 32 $1-
- var %str 360 / (sideCount / (key - (((floor(x / (2^(b*(n-1)))) / (2^b)) - floor(floor(x / (2^(b*(n-1)))) / (2^b))) * (2^b))))
- var %bits 8
- var %key $calc(2^ (%bits - 1) - 1)
- var %sideCount $1
- tokenize 32 $2-
- var %x 1,%y
- while %x <= $0 {
- var %deg $ [ $+ [ %x ] ] % %key
- var %offset $calc((%key - %deg) * 2^(%bits * (%x - 1)))
- inc %y %offset
- inc %x
- }
- return $replace(%str,x,%y,key,%key,sideCount,%sideCount,b,%bits)
- }
- ;;;;;;;;
- ; Menu ;
- ;;;;;;;;
- menu * {
- -
- GeoSketch: /GeoSketch.InitGui
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement