Skip to content

Instantly share code, notes, and snippets.

@Drumsin
Last active June 11, 2022 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drumsin/c9f7f14c7fc1c72f8a9d36add7f3a733 to your computer and use it in GitHub Desktop.
Save Drumsin/c9f7f14c7fc1c72f8a9d36add7f3a733 to your computer and use it in GitHub Desktop.
AoE4 Generated Map Function: Circle Outline
--draws a circle outline
--copy and paste code to preview at https://aoe4.app/
--radius (float) the radius of the circle
--centerCoord (table) x y coordinates of the circle center
--pickedTerrain (str/var) the terrainType name to draw
--implodeWidth (float) experimental and can produce interesting results when increasing
--iterations (int) the number of circle iterations to draw, used in conjunction with strokeSpacing
--strokeWidth (int) the circles outline width
--strokeSpacing (float) the amount of spacing between circles if there are multiple iterations set
function circleOutline(radius, centerCoord, pickedTerrain, implodeWidth, iterations, strokeWidth, strokeSpacing)
--checks to see if coords exist in table
--used to prevent out of bounds areas from being set
local function isInTable(searchTable, row, col)
if (searchTable[row] ~= nil and searchTable[col] ~= nil) then
result = true
else
result = false
end
return result
end
print("--- BEGIN CIRCLE OUTLINE ---")
for i = 0, strokeWidth do
--increase the radius with each pass for a thicker stroke
radius = radius + i * 0.125
for r = 0, math.floor(radius * math.sqrt(0.5)) do
d = math.floor(math.sqrt(radius * radius - r * r) - implodeWidth)
if (isInTable(terrainLayoutResult, centerCoord.row - d, centerCoord.col + r)) then
terrainLayoutResult[centerCoord.row - d][centerCoord.col + r].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row + d, centerCoord.col + r)) then
terrainLayoutResult[centerCoord.row + d][centerCoord.col + r].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row - d, centerCoord.col - r)) then
terrainLayoutResult[centerCoord.row - d][centerCoord.col - r].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row + d, centerCoord.col - r)) then
terrainLayoutResult[centerCoord.row + d][centerCoord.col - r].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row + r, centerCoord.col - d)) then
terrainLayoutResult[centerCoord.row + r][centerCoord.col - d].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row + r, centerCoord.col + d)) then
terrainLayoutResult[centerCoord.row + r][centerCoord.col + d].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row - r, centerCoord.col - d)) then
terrainLayoutResult[centerCoord.row - r][centerCoord.col - d].terrainType = pickedTerrain
end
if (isInTable(terrainLayoutResult, centerCoord.row - r, centerCoord.col + d)) then
terrainLayoutResult[centerCoord.row - r][centerCoord.col + d].terrainType = pickedTerrain
end
end
end
--creates expanding rings based on number of iterations
--stroke spacing increases the distance between rings
if (iterations > 1) then
circleOutline(radius + (strokeSpacing + 1), centerCoord, pickedTerrain, implodeWidth, iterations - 1, strokeWidth, strokeSpacing)
end
end
centerCoord = {}
centerCoord.row = mapHalfSize
centerCoord.col = mapHalfSize
--circle outline params
--adding 0.25 increments to radius and strokeSpacing can produce better looking results
circleRadius = 5.25
implodeWidth = 0
iterations = 2
strokeWidth = 2
strokeSpacing = 2
--the circle outline!
circleOutline(circleRadius, centerCoord, tt_swamp, implodeWidth, iterations, strokeWidth, strokeSpacing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment