mircscripting.info Forum Index mircscripting.info
#mIRCscripting Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Poly2Wave

 
Post new topic   Reply to topic    mircscripting.info Forum Index -> Snippets
View previous topic :: View next topic  
Author Message
Ook
Major


Joined: 01 May 2004
Posts: 82

PostPosted: Sun Feb 24, 2019 3:49 pm    Post subject: Poly2Wave Reply with quote

A small example just for fun.
This turns any shape into a wave form, once loaded run it using the Poly2Wave menu items.
Only tested on mIRC v7.55

Code:

;
; Shape to wave v1.0 by Ook
; Turns any polygon shape into a wave form.
;
; Known issues:
;  Center point is not correcly calculated for polygons

; show circle2wave in action
alias demo_circle2wave circle2wave 100

; show poly2wave in action
alias demo_poly2wave poly2wave 10,10 10,260 260,50 260,30 265,15

; quick access menu
menu menubar,status {
  Poly2Wave
  .Circle: circle2wave 100
  .Square: poly2wave 10,10 10,260 260,260 260,10
  .Poly: poly2wave 10,10 10,260 260,50 260,30 265,15
}

; $1 = val1, $2 = val2
alias -l max !return $iif(($1 > $2),$1,$2)
alias -l min !return $iif(($1 < $2),$1,$2)

; draw a poly shape
; $1- = set of poly coordinates 0<=x<=260 0<=y<=260
; 10,10 10,100 100,100 100,10 = a square
; 10,10 10,100 100,100 110,110 100,10
alias poly2wave {
  var %w = @poly2wave
  if ($window(%w)) window -c %w
  if ($window(@polybuf)) window -c @polybuf
  ; 3 points min, last point is same as the first.
  if ($0 < 3) return

  set %pw_type poly
  set %pw_shape $1- $1
  set %pw_pointcnt $calc($0 +1)
  set %pw_centerx 0
  set %pw_centery 0
  set %pw_clockpos 0
  set %pw_lastdot
  set %pw_thisdot

  ; window consists of 2 basic areas
  ; area 1 = area where shape is drawn
  ;  This area shows the shape with a center point drawn & a radius line that moves in a clockwise fashion.
  ;  At the point where this radius line meets the shape edge a horizontal line goes to the right untill the start of area 2
  ; area 2 = area where wave form is drawn
  ;  This area shows a scrolling wave form formed by the radius extention from area 1

  var %w = @poly2wave
  window -pdCfizk0 %w -1 -1 800 280
  titlebar %w Shape to Wave

  ; find min & max x,y
  var %minx = 300, %miny = 300, %maxx = 0, %maxy = 0, %c = 1
  while ($gettok($1-,%c,32) != $null) {
    var %x = $gettok($v1,1,44), %y = $gettok($v1,2,44)
    var %minx = $min(%x,%minx)
    var %miny = $min(%y,%miny)
    var %maxx = $max(%x,%maxx)
    var %maxy = $max(%y,%maxy)
    inc %c
  }
  ; find center point of shape
  set %pw_centerx $calc(((%maxx - %minx) / 2) + %minx)
  set %pw_centery $calc(((%maxy - %miny) / 2) + %miny)

  ; draw shape
  drawshape %w
  ; fill bkg
  drawbkg %w

  drawdot %w
  .timerpoly -m 0 50 polytimed
}

; draw a circle
; $1 = Radius
alias circle2wave {
  var %w = @poly2wave
  if ($window(%w)) window -c %w
  if ($window(@polybuf)) window -c @polybuf
  ; 3 points min, last point is same as the first.
  if ($0 < 1) return

  set %pw_type circle
  set %pw_shape $1
  set %pw_centerx 130
  set %pw_centery 130
  set %pw_clockpos 0
  set %pw_lastdot
  set %pw_thisdot

  ; window consists of 2 basic areas
  ; area 1 = area where shape is drawn
  ;  This area shows the shape with a center point drawn & a radius line that moves in a clockwise fashion.
  ;  At the point where this radius line meets the shape edge a horizontal line goes to the right untill the start of area 2
  ; area 2 = area where wave form is drawn
  ;  This area shows a scrolling wave form formed by the radius extention from area 1

  window -pdCfizk0 %w -1 -1 800 280
  titlebar %w Shape to Wave

  ; draw shape
  drawshape %w
  ; fill bkg
  drawbkg %w

  ; show drawing
  drawdot %w
  .timerpoly -m 0 50 polytimed
}

;drawpoly -ihnr @ <color> <size> <x y> <x y> [<x y>...]
alias -l drawpoly {
  ;if (- isin $1) var %p = $5 $6
  ;else var %p = $4 $5
  ;drawline $1- %p
  drawline $1-
}

; $1 = window, $2 = xCenter, $3 = yCenter, $4 = radius
alias -l drawcircle drawrect -nre $1 0 1 $calc($2 - $4) $calc($3 - $4) $calc(2* $4) $calc(2* $4)

; $1 = window
alias -l drawbkg {
  if (!$window($1)) return

  var %bkgclr = $rgb(146,146,146)

  drawrect -nr $1 %bkgclr 1 5 5 265 265 275 5 500 265
}
; $1 = window
alias -l drawcenter drawdot -nr $1 $rgb(255,0,0) 2 %pw_centerx %pw_centery

; Find point that line intersects circle
; $1 = xCenter, $2 = yCenter, $3 = radius, $4 = angle of line
; returns x y
alias -l PtIntersectCircle return $int($calc($1 + ($3 * $cos($4).deg))) $int($calc($2 + ($3 * $sin($4).deg)))

; Find point that line intersects poly
; returns x y
alias PtIntersectPoly {
  var %cnt = 2, %xInter = $round($calc(%pw_centerx + ($cos(%pw_clockpos).deg * 300)),0), %yInter = $round($calc(%pw_centery + ($sin(%pw_clockpos).deg * 300)),0), %ptStart = $gettok(%pw_shape,1,32)
  while (%cnt <= %pw_pointcnt) {
    var %ptEnd = $gettok(%pw_shape,%cnt,32)
    var %xStart = $gettok(%ptStart,1,44), %yStart = $gettok(%ptStart,2,44), %xEnd = $gettok(%ptEnd,1,44), %yEnd = $gettok(%ptEnd,2,44)
    if ($intersect(%xStart,%yStart,%xEnd,%yEnd,%pw_centerx,%pw_centery,%xInter,%yInter) != $null) return $v1
    var %ptStart = %ptEnd
    inc %cnt
  }
  return %pw_centerx %pw_centery
}

; $1 = window
; returns x y
alias -l getintersect {
  if (%pw_type == circle) return $PtIntersectCircle(%pw_centerx, %pw_centery, %pw_shape, %pw_clockpos)
  return $PtIntersectPoly
}

; $1 = window, $2 = xIntersect, $3 = yIntersect
alias -l drawintersect drawline -nr $1 255 1 %pw_centerx %pw_centery $2-

; $1 = window, $2 = xIntersect, $3 = yIntersect
alias -l drawcrossline {
  drawline -nr $1 $rgb(0,255,255) 1 $2- 299 $3
  set %pw_lastdot %pw_thisdot
  set %pw_thisdot 300 $3
  if ((%pw_lastdot != $null) && (%pw_thisdot != $null)) drawline -nr $1 255 1 %pw_lastdot %pw_thisdot
  drawdot -nr $1 255 1 %pw_thisdot
}
; $1 = window
alias -l drawwave {
  drawscroll -n $1 1 0 299 6 470 260
  ;if ((%pw_lastdot) && (%pw_thisdot)) drawline -nr $1 255 1 %pw_lastdot %pw_thisdot
}
; $1 = window
alias -l drawshape {
  drawrect -nrf $1 $getdot(@poly2wave,1,1) 1 5 5 295 265
  ; draw shape
  if (%pw_type == circle) drawcircle $1 %pw_centerx %pw_centery %pw_shape
  else drawpoly -nr $1 0 1 $replace(%pw_shape,$chr(44),$chr(32))
  ; draw center point
  drawcenter $1
  ; draw clock line
  var %int = $getintersect($1)
  drawintersect $1 %int
  ; draw linking line across to scroll area
  drawcrossline $1 %int
}
alias -l polytimed {
  var %w = @poly2wave
  if (!$window(%w)) { .timerpoly off | return }
  inc %pw_clockpos
  if (%pw_clockpos >= 360) set %pw_clockpos 0
  drawshape %w
  drawbkg %w
  ;
  drawwave %w

  drawdot %w
}
on *:unload: unset %pw_*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    mircscripting.info Forum Index -> Snippets All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group