Wednesday 24 May 2017

You Won't BELIEVE what I found in the new Spiderman : Homecoming trailer!

Note that I like to pander about, talking about whatever comes to mind, if you want to get straight to the analysis scroll down till you see the code.

I found decorative computer code. There, now send me an angry comment for the clickbait and be on your way, Internet stranger.
(But pls remember to tweet how angry you are and don't forget to link this and Google Plus this (I don't judge you for using that) and Facebook and send this to all your friends! Email if you have too! Or -gasp- talk to your friends about this!)
....
plz
....
 i hvae no raeders
....
I am broken inside
...
 :'(
....

Anyway here's Spidey's suit given to him by Tony

(Image courtesy of Sony, screencapped from the Youtube trailer, (98027 views as of writing) all of these are from there, don't sue me please :(  
 I'm also pretty sure it's legal for me to use this under fair use as long as I don't use it in it's entirety for educational purposes or something like that, so there's that. Sorry for rambling, readers. Wait I thought I have no readers?)

Looks pretty cool, apparently the red and blue isn't painted on but is emitted through the suit. Handy
for changing colour schemes and logos in the future without having to come up with the old "Upgraded suit" cliche.

Looks like the entire suit is a circuit. And guess what, it's programmable too!



Anyways here is the code, presumably in-universe written by Tony Stark. I believe this is the first time we see his actual code on-screen in the MCU.



So, either Tony left some code for Spidey to play with (but he blocked out most of it with "The Training Wheel Protocol", wow Tony. Just. Wow.).

I heavily suspect there is more code at the top and bottom, but the screen is scrolled somewhere in the middle of the code. That also explains the "boxAnchor + offset" meaningless code at the bottom, it's not fully displayed and maybe it's a typo or something.

If someone could identify the language used (assuming it's a real language), I would appreciate it. Right now my theory is....Javascript? I honestly have no clue.

So let's take a look at the code. I've written down for you, the non-existent reader's, convenience

MODEM BACKUP
boxTopLeft = box.toComp([0,0]);
boxBottomRight = box.toComp([box.width,box.height]);
boxAnchor = box.toComp(box.anchorPoint); xRatio = deltaX/distanceEdge;

deltaVec = sub(targetPos,boxAnchor);
deltaX = deltaVec[0];
deltaY = deltaVex[1];
xRatio = 1;
yRatio = 1;

if (deltaX>0)
{
    //target is right of anchorPoint
    xDistanceToEdge = boxTopLeft[0] - boxAnchor[0];
    xRatio = deltaX / xDistanceToEdge;
}

else if (deltaX<0)
{
    xDistanceToEdge = boxTopLeft[0] - boxAnchor[0];
    xRatio = deltaX / xDistanceToEdge;
}

if (deltaY>0)
{
    //target is below anchorPoint
    yDistanceToEdge = boxBottomRight[1] - boxAnchor[1];
    yRatio = deltaY / yDistanceToEdge;
}

else if (deltaY<0)
{
    yDistanceToEdge = boxTopLeft[1] - boxAnchor[1];
    yRatio = deltaY / yDistanceToEdge;
}

ratio = (xRatio>yRatio) ? xRatio:yRatio;
offset = div(deltaVec,ratio);
boxAnchor + offset

.;
MYCONFIGPROGRAM,SH
CREATE_SAMPLE_FILES,SH            BLURRY
./BACKUP:
DAVINCIPROGRAM.SH POWER.NEURAL.;     BLURRY
# FIND -INAME "POWER.NEURAL.1"

So yeah. Sorry I can't read the super blurred out section on the left.
Tony Stark has some really buggy code.By the way if you want, look at the picture you can see his style of writing code, the positioning of brackets and the like. Just an interesting observation, a man's style of writing is as expressive as his walking gait and personality in my opinion.

So at first glance, I think it's definitely something to do with geometry as evidenced by all the coordinates of Xs and Ys and Vectors.

Now I was too lazy to actually read the code, so I made up 2 hypotheses as to what it could be
  1. Detection for where to shoot web (it was mentioned there was 576 possible web shooter combinations in the trailer)
  2. Spidey's Heads Up Display GUI
Yes. Spiderman does have a HUD like Iron Man.



Honestly I like him better independent. Ah well it's a kick-ass cool suit.

I ruled out the first theory because  it seemed to simple for pattern recognition and the like.For some daft reason, I also ruled it out because of the lack of a 'z' coordinate in the real world. Only a little later did I realise that cameras on the suit (if there are any) would capture in 2d hence the lack of a z coordinate.

So it's likely to be used somewhere in Spiderman's HUD.

But what is it actually?

it seems to have an input a deltaVec 2d coordinate, a bounding box which I assume contains the deltaVec (it makes sense), and the target 2d coordinate I assume is away from the box.


(Yeah, sorry I didn't have my tablet at the time and now I'm too lazy)

First off it calculates the ratio between a) distance between the delta and the side of the box (in the direction of the target) b) distance between the input and the target.
Rinse and repeat for all possible cases for both x and y (4 cases, calculate X for left and right, calculate Y for up and down).

Note within a note : It may seem there are cleaner ways to do this with less code (i.e: taking the absolute value only so that eliminates
the need for if statements), but after some thinking, the code provided is actually the most readable way of doing this.

It seems to target the higher ratio first, that is, the one with a further distance to target and smaller distance to side of box,
then divide the delta vector by that "bigger" ratio.
What I don't get is why it chooses the "bigger" ratio for dividing *both* x and y coordinates in the vector. it would make more sense
for

offset = div(deltaVec[0],xRatio);
offset = div(deltaVec[1],yRatio);

where deltaVec[0] and deltaVec[1] are the x and y coordinate respectively.
THIS would have created a still weird but totally slightly more logical normalization.
No idea why it does what it does. Hit me up with a comment if you have a theory and definitely contact me if you managed crack the whole thing wide open and figured out what it does.

For the curious wondering what a normalization is, Wolfram Alpha defines it as so:
The normalized vector of x is a vector in the same direction but with norm (length) 1.
 This is used in conjunction with targetCoordinates-playerCoordinates to get the direction vector to move and multiply that with a speed float instead to control the speed. So a player from (0,0) to enemy (3,3) would give (3-0,3-0) and thus (3,3) as the direction (northeast). So That's is essentially moving (1,1) at a speed of 3 units per second. What normalising does is take the (3,3) and makes it into a (1,1) but the ratios must still be the same (3:3 is equal to 1:1)

Yes I understand the so-called "normalization"  does not have a unit length of 1. I'm still fairly sure the ratios are still the same though. I have no idea why or how they Tony did it like this. Genius level code obfuscation?

Hit me up with a comment if I got normalization completely wrong.
Be as harsh as you want, I have no emotions.

Hit me up with a comment if I got spelling errors.
Be as harsh as you want, I have no emotions.

Hit me up with a comment if you want to talk.
Be as harsh as you want, I have no emotions.

Side-thoughts:
The script "DAVINCIPROGRAM.SH POWER.NEURAL.;" seems to indicate a shell script named after Leonardo Da Vinci. The word Neural, which I first read as Neutral (assuming like as in Live, Neutral, Earth/Ground) but upon reinspection it is most definitely Neural. This word, along with the word Da Vinci, leads me to believe that this is a shell script for activating a Artificial Neural Network (Artificial Intelligence) for pattern finding in the real world through cameras to estimate where best to shoot those webs. Keep in mind this is a long shot and just a not-very-useful movie-wise theory which will likely never get verified (or debuked).

What the heck is "xRatio = deltaX/distanceEdge;" for?
xRatio gets reassigned a few lines later without ever being used.
Perhaps out of the reach of the screen we could not see it was being used for something though.
Why that weird ugly style of coding for someone of the likes of Tony Stark? I do not know.

All in all I was impressed with how they handled the code in the trailer. It might not be the perfect code, but honestly it's good enough for just a quick glance even by a coder.It visually feels interesting while not falling into the trope of having animated ASCII art and colourful GUIS all over the place with an deliberately attention-seeking "Look at me I'm a computer genius look at these random 0s and 1s and scrolling of texts in a green font" type of code. It even seems to be doing something, something related to the suit without ever mentioning "Spider" or something in the code, though I still for the life of me do not know what that something is.

But then again, fools know nothing.
(that was supposed to be a profound endin-

No comments:

Post a Comment