python - Array of coordinates to SVG Polygon shape -
I am making a random map generator in Python I am creating random political states. I have an algorithm that creates a list of X, coordinates for the list of areas Y. These areas need not be narrowed, so the list of digits can produce many polygon shapes.
Currently, I am converting the list of points into path strings, essentially a very long line that wraps around to create a shape, not exactly what the path was intended for. It is very disabled; If you have a particularly long time zone then it can be several thousand characters long. Also, using this method, the stroke property essentially functions as an asset filled, which means that I can not drag the boundary line between the fields.
:
& lt; Svg xmlns = "http://www.w3.org/2000/svg" version = "1.1" width = "512" height = "512" & gt; & Lt; Path D = "M 332 263 H 346 M 331 264 H 347 M 330 265 H 348 M 329 266 H 349 M 328 267 H 350 M 327 268 H 351 M 326 269 H 352 M 325 270 H 364 M 324 271 H 365" M 323 272 H 366 M 322 273 H 367 M 321 274 H 368 M 320 275 H 36 9 M 319 276 H 370 M 318 277 H 371 M 317 278 H 372 M 317 279 L 317 279 M 319 279 M 322 279 H 373 M 318 280 L 318 280 M 323 280 H 374 M 317 281 L 317 281 M 324 281 H 375 M 322 282 L 322 282 M 324 282 H 376 M 320 283 H 376 M 321 284 H 376 M 321 285 H 323 M 325 285 H 330 m 333 285 m340 285 h 375 m 323 286 h 324 m 326 286 h 328 m 342 286 h 371 m 373 286 h 374 m 325 287 l 325 287 m 327 287 m 345 287 h 373 m 346 288 H 372 M 345 289H 372 M 346 290 H 36 9 M 372 290 M 375 290 M 345 291 H 368 M 371 291 M 374 291 H 377 M 345 292 H 368 M 374 292 H 375 M 344 293 H 367 M 344 294 h 363 m 365 294 m 343 295 h 362 m 344 296 h 363 m 345 297 h 363 m 345 298 h 363 m 345 29 9 h 363 m 345 300 h 363 m 345 301 h 361 m 344 302 h 361 m 345 303 h 361 m 346 304 h 357 m 347 305 h 356 m 350 306 h 351 m 354 306 m 356 306 "stroke =" rgb (252, 81, 193) "& gt; & Lt; / Path & gt; & Lt; / Svg & gt;
The real question:
How can I change the list of digits to one or more polygons? More specifically, I need a polygon "line" string.
Obviously creating a algorithm in your area is a bitmap. You need to find out the size of the frame instead of making the shape outline "run-length encoding" instead of finding the outline of the shape.
Describing how to do this is a little beyond SO. answer. In general, this is called "bitmap tracing". This is a popular library for utensils
. I think there are dragon binding for it.
Otherwise, you might work better by taking advantage of the internal data structures (compared to the utensils) which makes your area algorithm.
Comments
Post a Comment