Problem description:
I'm trying to update the hand so that the rotation and spread of them is even and looks similar to the picture I'm going to link below this text, the code below is how I'm currently doing what's shown and I've tried out a bajillion different ways to try and get this to work but, my brain is currently lacking in this field of programming and math and would great appreciate any kind of help in solving the issue at hand :D
Code:
mob/player/proc/UpdateHand()
var start = 0 - (1*hand.len) - 22.5,p
for(var/obj/card/c in hand)
c.transform = turn(matrix(),start).Translate(-32,-48)
start += (p * 32) + (hand.len/2) + 16
screen.vis_contents |= c
c.pixel_x = (32 * 10 / 2 - 32) + sin(start) * 64
c.pixel_y = (8) + cos(start) * 32
1. Say the the first card has the minimum angle (e.g. -10 degrees), the last card has the maximum angle (e.g. 10 degrees), and any card in between should have an angle proportionally in between the minimum and maximum angle. There are many functions to achieve this, but a simple straightforward one would be what's commonly known as "map" or "re-map", where you take a value from one range of values and move it to another range at the same proportion. It takes advantage of a couple other commonly used functions, interpolate (AKA lerp, linear interpolation) and its inverse.
So the angle, from minimum_angle to maximum_angle, of the nth card, where the cards are numbered from 1 to hand.len, would be remap(n, 1, hand.len, minimum_angle, maximum_angle).
Warning: when using remap() where a1 = b1, or inverse_interpolate() where a = b, you'll get a division by zero. It's up to you what should happen in this case: when you have only one card in your hand, where should it go?
2. The position of a card appears to resemble the result of rotating by its angle about a common pivot point that is far enough below them. To pivot an object around a point, you can do that with matrix operations in this order: (this also applies the card's rotation)
There's definitely more tweaking to do, but this might be a start.