OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I format ImageMagick argument for Powershell script (array of points for drawing intersecting lines connecting hexagonal vertices)?

  • Thread starter Thread starter bladeo
  • Start date Start date
B

bladeo

Guest
I'm trying to set up a project to interest nephew in design/coding (while learning myself). This snippet appears to work, but it's suboptimal and I can't figure out how to set $draw as array and call thrice like -draw $draw that works (or otherwise approach). I've tried iterations of single- and/or double-quotes. (Idk how to initialize $hex properly either.)

Code:
# Hexagon
$size = '482'
$half = $size/2
$hex = @(0,1,2,3,4,5)
for ($i = 0; $i -lt 6; $i++)
{
    $x = $half * [math]::cos(2 * [math]::pi * $i/6+[math]::pi) + $half
    $y = $half * [math]::sin(2 * [math]::pi * $i/6+[math]::pi) + $half
    $hex[$i] = "$x,$y"
}
$draw1 = 'line ' + $hex[0] + ' ' + $hex[3]
$draw2 = 'line ' + $hex[1] + ' ' + $hex[4]
$draw3 = 'line ' + $hex[2] + ' ' + $hex[5]
Write-Output $draw1
magick -size '482x482' xc:none -stroke 'black' -fill 'white' -draw "polygon $hex" `
-stroke 'black' -fill 'none' `
-draw $draw1 -draw $draw2 -draw $draw3 test_hex.png

Hexagon
<p>I'm trying to set up a project to interest nephew in design/coding (while learning myself). This snippet appears to work, but it's suboptimal and I can't figure out how to set $draw as array and call thrice like <strong>-draw $draw</strong> that works (or otherwise approach). I've tried iterations of single- and/or double-quotes. (Idk how to initialize $hex properly either.)</p>
<pre><code># Hexagon
$size = '482'
$half = $size/2
$hex = @(0,1,2,3,4,5)
for ($i = 0; $i -lt 6; $i++)
{
$x = $half * [math]::cos(2 * [math]::pi * $i/6+[math]::pi) + $half
$y = $half * [math]::sin(2 * [math]::pi * $i/6+[math]::pi) + $half
$hex[$i] = "$x,$y"
}
$draw1 = 'line ' + $hex[0] + ' ' + $hex[3]
$draw2 = 'line ' + $hex[1] + ' ' + $hex[4]
$draw3 = 'line ' + $hex[2] + ' ' + $hex[5]
Write-Output $draw1
magick -size '482x482' xc:none -stroke 'black' -fill 'white' -draw "polygon $hex" `
-stroke 'black' -fill 'none' `
-draw $draw1 -draw $draw2 -draw $draw3 test_hex.png
</code></pre>
<p><a href="https://i.sstatic.net/AJUovko8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AJUovko8.png" alt="Hexagon" /></a></p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top