Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:44+00:00 2026-05-23T10:25:44+00:00

I am a bit stuck with this. I want to determine two opacity int

  • 0

I am a bit stuck with this. I want to determine two opacity int values. One should increase and the other should decrease by hour.

Imagine a day consists of 4 parts. Night, sunrise, day and sunset. Each of the parts is pictured by
two images that are overlayed. Night has a night image and a sunrise image. At midnight night image has an opacity of lets say 255 while sunrise is actually invisible.

While the time elapses to e.g. 4 o’clock the night image’s opacity gets lower while the sunrise’s opacity increases. At 5 o’clock night is over with an image opacity of 0 while sunrise image has an opacity of 255.

So in each of the 4 parts I want to calculate two opacity values, one increasing the other decreasing. In each part the opacity goes from 255 to 0 and on the other side from 0 to 255.

This is how I seperate the parts in hours

switch (hour) {
        //night to sunrise
        case 23: case 0: case 1: case 2: case 3: case 4:
            [self setSetting:1 andOpacity:opacIn andOpacity:opacOut];
            break;
        //sunrise to day
        case 5: case 6: case 7: case 8: case 9: case 10:
            [self setSetting:1 andOpacity:opacIn andOpacity:opacOut];
            break;
        //day to sunset
        case 11: case 12: case 13: case 14: case 15: case 16:
            [self setSetting:4 andOpacity:opacIn andOpacity:opacOut];
            break;
        //sunset to night
        case 17: case 18: case 19: case 20: case 21: case 22:
            [self setSetting:2 andOpacity:opacIn andOpacity:opacOut];
            break;
    }

I tried it with this solution

int opacIn = hour * 10;

if (opacIn >= 230) {
    opacIn += 25;
}

int opacOut = 255 - opacIn;

The problem with this is that this determines the opacity in reference to the whole day. So it goes from 255 to 0 only once. But I want it to be this way for each part of the day.

Any ideas on this? How could I determine the opacity for each part?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:25:45+00:00Added an answer on May 23, 2026 at 10:25 am

    It looks like you need a dash of the old modular arithmetic. Your day is broken up into four segments of six hours each; each hour you want to change some value, and the corresponding hours in every segment have the same value.

    So first, divide your target value by the number of steps:

    // Avoid magic numbers
    #define MAX_OPACITY 255
    #define HOURS_PER_SEGMENT 6
    #define OPACITY_STEP (MAX_OPACITY / HOURS_PER_SEGMENT)
    

    Notice that, if you read the cases of your switch statement as columns, every value in a column has the same result modulo 6. This is the key; each time you check the time, find out what your position is in the current segment:

    // For purposes of opacity, it's as if 11PM is the first hour of the day
    int shifted_hour = hour + 1;
    if( 24 == shifted_hour) shifted_hour = 0;
    int segment_pos = shifted_hour % HOURS_PER_SEGMENT;
    

    Now you get your opacity value quite simply:

    int opacIn = segment_pos * OPACITY_STEP;
    int opacOut = MAX_OPACITY - opacIn;
    

    You could also do away with the switch:

    int segment_index = shifted_hour / 6;
    
    [self setSegment:segment_index withOpacityIn:opacIn withOpacityOut:opacOut];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am bit stuck with this one.. what i want is update app_name (first
I'm a bit stuck on this. Basically I want to do something like the
I'm a bit stuck on this one. In my PHP code, I query for
Getting a bit stuck on this. Basically I have a method that I want
I've come a bit stuck this afternoon with a bug in my web application
I'm a bit stuck on this - I am using a Wordpress shortcode with
hi i am a bit stuck with this. what i am going to work
Okay i'm a little bit stuck on how to solve this problem. When a
I'm experimenting a bit with textual comparison/basic plagiarism detection, and want to try this
I am a bit stuck implementing a rather simple layout requirement. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.