Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
72
Task/Pentagram/Nim/pentagram.nim
Normal file
72
Task/Pentagram/Nim/pentagram.nim
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import libgd
|
||||
from math import sin, cos, degToRad
|
||||
|
||||
const
|
||||
width = 500
|
||||
height = width
|
||||
outerRadius = 200
|
||||
|
||||
proc main() =
|
||||
|
||||
proc calcPosition(x: int, y: int, radius: int, posAngle: float): (cint, cint) =
|
||||
var width = int(radius.float * sin(degToRad(posAngle)))
|
||||
var height = int(radius.float * cos(degToRad(posAngle)))
|
||||
return (cast[cint](x + width), cast[cint](y - height))
|
||||
|
||||
proc getPentagonPoints(startAngle = 0, radius: int): array[5, array[2, int]] =
|
||||
let spacingAngle = 360 / 5
|
||||
|
||||
var posAngle = (90 - startAngle).float
|
||||
|
||||
var n = 0
|
||||
var points: array[5, array[2, int]]
|
||||
while n < 5:
|
||||
(points[n][0], points[n][1]) = calcPosition(250, 250, radius, posAngle)
|
||||
n += 1
|
||||
posAngle -= spacingAngle
|
||||
|
||||
return points
|
||||
|
||||
let outerPentagon = getPentagonPoints(18, outerRadius) # rotate 18 degrees
|
||||
let innerPentagon = getPentagonPoints(54, int((cos(degToRad(72.0))/cos(degToRad(36.0))) * outerRadius)) # rotate 54 degrees
|
||||
|
||||
var pentagram: array[10, array[2, int]]
|
||||
var n = 0
|
||||
for i in countup(0, 4):
|
||||
pentagram[n] = outerPentagon[i]
|
||||
inc(n)
|
||||
pentagram[n] = innerPentagon[i]
|
||||
inc(n)
|
||||
|
||||
withGd imageCreate(width, height) as img:
|
||||
discard img.setColor(255, 255, 255)
|
||||
|
||||
let black = img.setColor(0x404040)
|
||||
let blue = img.setColor(0x6495ed)
|
||||
|
||||
img.drawPolygon(
|
||||
points=pentagram,
|
||||
color=blue,
|
||||
fill=true,
|
||||
open=false)
|
||||
|
||||
img.setThickness(4)
|
||||
|
||||
img.drawPolygon(
|
||||
points=pentagram,
|
||||
color=black,
|
||||
fill=false,
|
||||
open=false)
|
||||
|
||||
img.drawPolygon(
|
||||
points=innerPentagon,
|
||||
color=black,
|
||||
fill=false,
|
||||
open=false)
|
||||
|
||||
let png_out = open("pentagram.png", fmWrite)
|
||||
img.writePng(png_out)
|
||||
|
||||
png_out.close()
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue