How do I populate a 1D array with Gradient?

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm struggling to figure out how to populate an array of 24 X fields (each representing 1 hour of the day) with temperatures. So to define the daily temperature let's say (-4) and get a gradient of hourly temperatures in the array. But, the temperature should be lower in the morning and evening and be highest around 3 pm. Whatever I try I get data to the e-10 and fail to understand how it works since all examples are for 2D, even formulas I found.

    I'm working with events, not scripting.

    In a nutshell:

    daily_average_temperature = -4
    
    arr_hourly_temperatures(24) = []
    
    morning is 03:00h -> 11:00h
    day is 11:00h -> 18:00h
    evening is 18:00h -> 03:00h
    • morning gets warmer from 03:00h
    • day gets warmer until 15:00 (highest point) and starts dropping off until 18:00h
    • evening gets colder and colder until 03:00h

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You're lacking a range/scale value. Even if you have an average of -4, your range through the day could be -3 to -5 or 96 to -104 and both be valid.

    Assuming you want an symmetrical, eased, curve like set of values across 24 hours, you won't need to define different behaviours for different sets of time at all. You can use lerp for this, perhaps combined with either the easy-ease formula or a simple sine formula to make it smooth.

    Also, is your data going to be continuous for the next day? If you're just going by a daily average and don't take into account what temperature the previous day ended at, there could be a jump. Basically you'll also want to define a starting point.

  • I basically built a while ago a pretty bloat system that does it by seasons etc. each day has lowest and highest point, but it's not perfect, the temperature can sometimes jump at the high from -8 to 0, which is pretty bad. This system isn't built via Advanced Random. I didn't implement the entire year so that days blend into each other but yes, now that is more relevant so I really need it, they should also blend at midnight (i think midnight is the most appropriate?).

    The system is under event sheet time_temp_seasons, but it doesn't do much for the new one I wanna build.

    https://file.io/76YOTwf5WFcJ

    In the new one it should first calculate it for the entire year:

    And then each day at midnight it should calculate it for the day:

    Did try using lerp but it's too perfect and not like the curves in the pictures above. I probably over-complicated it

  • Looks like you can use a regular curve and apply some 1d perlin noise to it.

    Again you'll need to define either a min/max range or a maximum rate of change.

    Since you're using a formula/procedurally generating the temperatures anyway, might as well do it for the whole year in one go. The coolest temperatures in winter and the warmest in summer. It would just be another similar looking curve as the daily temperatures but on a different timescale. That's actually how perlin noise works in general.

    If you don't mind waiting a bit I can experiment later on putting this together, probably with a variables for yearly, monthly, and daily variation. A tropical location would have less variation across seasons than others. Maybe also need a start/target temperature variable, which would basically be your average.

  • Sounds interesting enough, would never think perlin noise is good for that :D Yes, I can wait of course and thank you for replying again!

  • Sorry got busy over the weekend.

    dropbox.com/s/pkg9p0abzts1tks/temperaturesimulation.c3p

    See if this looks good to you, and let me know if you have any questions.

    Also the values I used in the example are in F because I am a filthy American, in case you were wondering why the numbers are so high lol ;p

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)