What's the Best Way to Bounce A Variable Between 0 and 255

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 3436 Views - Last Post: 10 November 2016 - 09:37 AM

#16 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5894
  • View blog
  • Posts: 20,114
  • Joined: 05-May 12

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 01 November 2016 - 11:28 AM

There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 1
  • +
  • -

#17 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 02 November 2016 - 11:04 AM

Alrighty, still getting used to the culture.
Was This Post Helpful? 0
  • +
  • -

#18 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 03 November 2016 - 01:10 PM

@Baavgai, so I tried testing that code out in a console app and I got this message from the debugger, what should I do?
Thanks again for the help :)

Attached Image
Was This Post Helpful? 0
  • +
  • -

#19 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon


Reputation: 6979
  • View blog
  • Posts: 14,601
  • Joined: 16-October 07

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 03 November 2016 - 01:15 PM

Show your code. How did you implement the class Val?

Note, I only gave the header, the body is an exercise for you.
Was This Post Helpful? 0
  • +
  • -

#20 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 07:36 AM

Well I haven't really implemented it per se, basically just copied your code to see if I could get it working in a Win32 console program as I usually test concepts in command line instead of windows forms. I think I need to do some tutorials today on implementing classes. I will be back after I get a little more familiar with classes. I added your code to a .cpp item not a header though. I'm not using a header because for this test because I usually just compile a lone .cpp file when I'm doing command line apps. Let me do some research on classes and report back. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#21 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 07:40 AM

Curious - how do you read that error? White on turquoise is not really conducive to reading.. like white on yellow.
Was This Post Helpful? 0
  • +
  • -

#22 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 08:22 AM

View Postmodi123_1, on 04 November 2016 - 07:40 AM, said:

Curious - how do you read that error? White on turquoise is not really conducive to reading.. like white on yellow.


I have the hue adjusted on my video adapter. There are two screens and I offset the hue on one so that on my programming screen light blue is light purple and the brightness is turned down so it's easier to read than it appears there.
Was This Post Helpful? 0
  • +
  • -

#23 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 08:25 AM

That seems.. odd. Why would you want to misrepresent colors? Why not just use a different default highlight color?
Was This Post Helpful? 1
  • +
  • -

#24 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5894
  • View blog
  • Posts: 20,114
  • Joined: 05-May 12

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 08:31 AM

He's likely running f.lux. I've started using it to keep from waking my kids up while I use the dual monitor.
Was This Post Helpful? 0
  • +
  • -

#25 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 09:00 AM

View Postbaavgai, on 03 November 2016 - 01:15 PM, said:

Show your code. How did you implement the class Val?

Note, I only gave the header, the body is an exercise for you.


OK so I'm learning about classes, I see where you're going with this. So basically you've created a class that will keep the values for the integers within the specified boundaries? I'm still going to have to figure out why it's giving that message but at least I now understand what this class thing is doing.

Please forgive me, I've only been programming in C++ in my free time (which isn't much) and the only other programming language that I know is TI Basic (which is far simpler for trigonometric functions and input/output) so I'm still getting used to the complexities and intricacies of C++.
Was This Post Helpful? 0
  • +
  • -

#26 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 09:39 AM

View Postmodi123_1, on 04 November 2016 - 08:25 AM, said:

That seems.. odd. Why would you want to misrepresent colors? Why not just use a different default highlight color?



I'm at work, we have windows 10 here, windows 10 is extremely boring looking. I use the hue to spice up the interface a bit because when I was kid we used to have gradient title bars in windows 98 and it made the OS less BORING.
Was This Post Helpful? 0
  • +
  • -

#27 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5894
  • View blog
  • Posts: 20,114
  • Joined: 05-May 12

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 09:58 AM

Did you try playing with these settings?
Attached Image

Anyway other than the new flat "Metro" UI making a statement about departure from older versions of Windows, it actually also has the side effect of being much more energy efficient because a lot less CPU/GPU power is needed to render screen. This was a big boost in helping the battery life for Windows laptops and tablets. Of course, if you have a $1500 gaming video card on your desktop, it pretty much underutilized even if most of Windows 10 uses DirectDraw.
Was This Post Helpful? 0
  • +
  • -

#28 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 456
  • View blog
  • Posts: 1,179
  • Joined: 31-May 11

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 10:28 AM

Huh, well, I use f.lux as well, but it's more because even with dark themes f.lux still helps with eye-strain in night hours, and so it happens I'm at my most productive time when everybody else around is asleep. ; )
Enough offtopic from me, though.

OP: baavgai's class is such that when you instantiate an object of it, you give it a starting value, and min and max values. The object stores those values for later use. You probably should make sure that the value is in the min...max range, BUT, depending on what you want - you may even let the starting value be lesser than min, or larger than max - you'd just have to take care off appropriately setting the starting "direction" of the step.
As in, you could have:
auto b = /* give me a bouncer that starts with value 1, min is 10, max is 15 */;
for ( ; ; ) {
  cout << b;
  b += 1;
}
// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 11, ...

The most crucial part is of course the operator+= here - it does all the actual work of checking if your value is about to go out of range and appropriately handles the situation. Even there - there are subtle things that you may want to think about. Say, with a step value of 3 you can have these following two behaviors, any of which may be useful or not for your case:
auto b = /* give me a bouncer that starts with value 1, min is 0, max is 11 */;
for ( ; ; )  {
  cout << b;
  b += 3;
}
// 1, 4, 7, 10, ...? 
// now - the two behaviors are:
// (1, 4, 7, 10, 9, 6, 3, 0, 3, 6, 9, 10, 7, 4, 1, 2, 5, 8, 11, 8, 5, 2), 1...
// or...
// (1, 4, 7, 10, 7, 4), 1, 4, 7...


This is all with the saw-tooth version of course. Sinusoidal curve is a slightly another matter. : ) (Thus in my generic implementation the "stepping" part is abstracted away and can be supplied by the user)

This post has been edited by Xupicor: 04 November 2016 - 10:31 AM

Was This Post Helpful? 0
  • +
  • -

#29 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 11:35 AM

Xupicor, NICE!!!!! TY! I'm going to give this a shot. Be back in a second. Appreciate the help.

Skydiver, yes I changed that but the personalization options that have been in windows since 98 are all gone as of Win10. I understand what you're saying about the resource usage but that's not a good reason to remove features IMO. They should still be present, they're in Win7 you just have to switch to the classic theme but you can't do that in the latest release.
Was This Post Helpful? 0
  • +
  • -

#30 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5894
  • View blog
  • Posts: 20,114
  • Joined: 05-May 12

Re: What's the Best Way to Bounce A Variable Between 0 and 255

Posted 04 November 2016 - 05:18 PM

I remember being on the Win8 team when the perf team revealed the results of their testing for Aero UI vs. Metro UI. The difference was more than double in terms of watts used on Intel processors. It was even more dramatic for Atom processors. Since at the time, there was a company wide drive to be more power usage aware, the die was cast.
Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3