2

enter image description here I'm making a cards game in python language.

I need a formula to zooming the cards in screen.

I put the following formula by now:

zoom=(NumberOfCards*0.042857)

This formula get a zoom factor of 0.3 for Number=7. This is the standard for the first hand. Now the number of cards can increase of decrease and the hand should fit into screen accordingly.

Now I want to improve the formula to:

  • If Number<7 -> Keep the zoom the same (because cards can fit in screen)
  • If Number from 7 to 54 decrease the zoom slightly (or even keep to 0.3 til a higher number because could fit in screen).

The screen is 1280x720. The 54 cards are saved 600x868 in png format (zoomed to 0.3 factor: 180x260.4 overlapped as you can see in the capture)

How should be the formula? I'm weak at maths, hahaha.

Thanks in advance. :-)

runs
  • 95
  • 2
  • 7

1 Answers1

2

You can use the formula

zoom = 0.3 * (7/NumberOfCards)

to get to get the values of zoom between 0.038 (54 cards) to 2.1 (1 card).

After that, you can multiply the zoom by a factor, so as to normalize it, and make it fall in your specific range.

For normalization, for example, to make all the values lie between 0 to 1, you can use feature scaling

X` = (X - Xmin) / (Xmax - Xmin)

In your case,

zoom` = (zoom - 0.038) / (2.1 - 0.038)

At last, add a scaling to the zoom' value, so that zoom is not below a certain value.

zoom` = zoom` + scaling_factor
  • Thanks to you I've implemented a cool zoom: `if MyHandLen<=7: _zoom= 0.3 else: zoom= 0.3 * (7.0/MyHandLen) _zoom= (zoom - 0.044) / (2.1 - 0.044) _zoom= _zoom+0.195` But I want to center the hand with a xpos formula, being xpos the x position for each card. Any suggestion from your part? – runs Mar 10 '18 at 15:22