...And Mexico will Pay for It!

26

3

Donald Trump is very impressed with the work of the people on this site. He saw how amazing of a job you did helping Ben Carson, so he even hired you to build his wall. He thinks you're terrific. Now he needs your help again. While he has successfully built his wall, now he needs the Mexican government to pay for it. He wants to charge $1 million a mile, and he has told them that the U.S.-Mexico border is 1,989 miles long. However they are not quite sure this number is accurate, so they would like a to-scale visual representation as well. That's where you come in. You are to take this map: enter image description here

and for every n (50 <= n <= 500) miles on the border draw a 25 pixel-length line, perpendicular to the slope of the border at that point. Using the scale on the right-hand side of the map, I've determined that 100 miles ~ 50 pixels. I've drawn a sample of the first 3 lines for n=60, but these are only approximate:

enter image description here

Notes:

  • The only input is n. Output should be the map image, with the lines added, drawn to the screen or saved in a raster image file (you can overwrite the original map file).
  • You can save the blank map file with whatever file name you want. It is a JPEG, but you can convert it to another common raster format if you prefer. Also, you can reduce the size of the image by up to 50%, as long as you keep the dimensions proportional, and your lines are still to scale.
  • Each line should be perpendicular to the slope of the border at that point. The slope should be calculated starting 50 miles before the point and ending 50 miles after the point.

Accuracy:

  • The slope of each line can have a margin of error of ±5°
  • The spacing between each line can have a margin of error of ±20 miles (10 pixels on the regular map).

geokavel

Posted 2015-12-25T03:27:35.143

Reputation: 6 352

3The price $10000/mile is probably off by a factor of 100, unless by "wall" you mean 3 strands of barbed wire installed by laborers making $2.50/hour. – Glenn Randers-Pehrson – 2015-12-25T13:44:11.757

1Also, Mma states that the U.S.-Mexico border is about 1952 miles long. – LegionMammal978 – 2015-12-25T13:59:00.720

18Good to know, but the important thing is neither of those numbers mean anything for this challenge. – geokavel – 2015-12-25T15:17:09.950

@geokavel Go ahead and answer it. – programmer5000 – 2017-07-29T13:34:37.243

@programmer5000 Is it at possible (I'm honestly not sure how bounties exactly work) to extend the deadline of the bounty? I have a Python answer in the works, but I'm busy at the moment and I'm not sure I can complete it by the end of the time period. – notjagan – 2017-07-31T00:05:28.823

1Additionally, is the intention of this challenge to be able to process the image and identify the border before drawing the lines, or is it acceptable to just be able to draw the lines without actually processing the image (essentially assuming what the image will be like)? – notjagan – 2017-07-31T00:27:36.017

Answers

7

Python 2 + numpy + OpenCV, 576 bytes

Demo GIF

from cv2 import*
from numpy import*
n=input()/4
f="m.png"
i=imread(f)
b=array([0]*3)
y=array([165,195,225])
j=inRange(i,b,b+120)
k=inRange(i,y,y+25)
for x,y in zip(*where(j)):j[x,y]=k[x+3,y]-j[x+1,y]>1
j=j[506:732,152:557]
p=[array([11,9])]
for c in sorted(zip(*where(j)),key=lambda c:c[1]):r=range(p[-1][1]+1,c[1]+1);p+=map(array,zip(map(int,interp(r,*zip(p[-1],c)[::-1])),r))
for x,c in enumerate(p[25:-25:n]):s=-1/true_divide(*p[x*n+50]-p[x*n+25]);k=6/(1+s**2)**.5;line(i,*map(tuple,[(c+[int(k*s)+506,int(k)+152])[::-1],(c-[int(k*s)-506,int(k)-152])[::-1],b]))
imwrite(f,i)

This program is almost entirely ungolfed, and there are aspects of it that are somewhat inaccurate at the moment, but at least it works for the most part. Additionally, there is a little bit of hardcoding, but it's only for an approximate window enclosing the border and the coordinate of the first pixel on the border (the latter of which I will actually most likely remove later).

The image used by the program is halved in area (i.e. 1120 x 865), and so the length of lines drawn and the distance between lines is smaller.

notjagan

Posted 2015-12-25T03:27:35.143

Reputation: 4 011

2cool!! great to see an answer! – geokavel – 2017-07-31T05:12:26.917

suggest to delete unworking tio link – Евгений Новиков – 2017-07-31T09:11:22.147

1

gif demo https://i.stack.imgur.com/RWQu4.gif . Apply my edit

– Евгений Новиков – 2017-07-31T10:44:01.083

@ЕвгенийНовиков Thanks for the gif! It's much more illustrative (and succint) than the pictures I had before. – notjagan – 2017-08-01T01:43:09.910