1

I'm not very skilled when it comes to PHP but I've created this and it's probably not the best way to put it together but the only one that came to my mind right now.

enter image description here

What are we looking at?

It's the Apple Watch 'standing up in each hour' activity ring. This ring holds 12 image slices so called 'steps' because you have to stand up at least 12 times a day till you reach your goal (100% full circle) this means when you stand for 14 or 16 times a day the ring will loop further around 100% but the only difference between slide 2 and 14 is the background behind the circle will already be filled. Because I don't like to create 24 slices but only 12, I will rotate slide number 12 (full circle) X degree when the value gets over 12+ this will keep the amount of used images on the page low because we keep using slide number 12 most of the time only rotate it around for step 12 till 24.

Example: the blue middle ring

enter image description here

PHP wise everything is working so far but you can imagine how tall those if else list will become when I start the red 'move' or calories burned circle. This circle has 100 slices or better called steps. The green circle has 30 slices. That's why I was wondering if there is maybe a more lean way to make those if else steps. Maybe performance wise this can be done a lot better.

Thanks already..

3
  • have you used switch case statements ? if not have a look switch Commented Aug 16, 2015 at 11:04
  • 1
    If you don't mind, please copy/paste your code into the question rather than posting a screen capture of it. If you highlight the code block and click the {} editor toolbar button or ctl-k it will be indented 4 spaces with a preceding blank as a code block, which gets it syntax highlighting based on the php tag. It makes it much easier for answerers to assemble new code based on existing. Commented Aug 16, 2015 at 11:07
  • I did try to add the code but for some reason it all minified my if else and variables. into a single line. Commented Aug 16, 2015 at 14:05

2 Answers 2

5

This looks like a simple math problem. Without looking at all the details and making it even shorter (there is probably no need for an if statement at all...), you can already see that:

if ($stand > 12) {
    $stanr = ($stand % 12) * 30;
    $stand = 12;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, something like this was I looking for.. Easy and simple!
0

Erm...

$stanr = 0;
if ($stand <= 12) {
} elseif (($stand > 12) and ($stand < 24) {
    $stanr = ($stand - 12) * 30;
    $stand = 12;
else {
    $stand = 0;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.