Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 607 608 [609] 610 611 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 908661 times)

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9120 on: February 24, 2016, 07:38:58 pm »

I am facepalming so hard right now. I'm a 2nd year Math major but when it comes time to use math in a practical application, nothing I've learned helps. The education system is so stupid...Anyways, I'm new to C++ and I have a question.



Given the starting point 0 and ending point n, how do I smoothly scale up to n? Either of these methods is fine, but I'd prefer the one on the right. I'd also prefer not including any libraries but I will if there's no alternative.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9121 on: February 24, 2016, 07:52:01 pm »

these seem fine

the log one isn't as easily adjustable, but you can adjust n for the sin one willy nilly to get somewhat similar results you want for any n

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9122 on: February 24, 2016, 07:53:36 pm »

Given the starting point 0 and ending point n, how do I smoothly scale up to n? Either of these methods is fine, but I'd prefer the one on the right. I'd also prefer not including any libraries but I will if there's no alternative.
I need more words. What is it exactly you want to construct, and what are you given? Is there any context or constraints?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9123 on: February 24, 2016, 07:55:27 pm »

Well you can note for a start that the left hand graph looks a lot like the upper right quadrant of the right hand graph. That saves you from having to use two formulas - you can use one formula but tweak the parameters and range as needed and get either behavior.

The standard equation to get the right hand side behavior is called the logistic function aka the sigmoid function:





x0 is the x-center of the curve. That would be zero for the LHS graph and n/2 for the right hand side graph.

L scales up the y-values. It should be set to N for the right hand side behaviour, and n*2 for the left hand side behavior (but you have to subtract N from the final result to get it to pass through the origin then).

k controls how steep the curve is. Higher K makes it plateau faster.
« Last Edit: February 24, 2016, 07:58:13 pm by Reelya »
Logged

DragonDePlatino

  • Bay Watcher
  • [HABIT:COLLECT_WEALTH]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9124 on: February 24, 2016, 08:23:50 pm »

Ohh. Shiny web app. Me likey. O_O

For context, I'm programming a graphical roguelike and I want my characters to smoothly move between tiles regardless of the game speed (ranging from 12 frames per move to 60 frames per move).

Anyways, thanks for the help guys! Putnam's equation involving sin seems to be what I'm looking for. I can't customize how quickly it plateaus, but I always get f(n) = n for every value I put in. The logistic function has a smoother curve, but the fact that it doesn't quite hit 0 or n is problematic.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9125 on: February 24, 2016, 08:48:38 pm »

Ohh. Shiny web app. Me likey. O_O

For context, I'm programming a graphical roguelike and I want my characters to smoothly move between tiles regardless of the game speed (ranging from 12 frames per move to 60 frames per move).

Anyways, thanks for the help guys! Putnam's equation involving sin seems to be what I'm looking for. I can't customize how quickly it plateaus, but I always get f(n) = n for every value I put in. The logistic function has a smoother curve, but the fact that it doesn't quite hit 0 or n is problematic.

EDIT: Oh, I see what you mean.

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9126 on: February 25, 2016, 02:41:56 pm »

Really Skype? Why do you have to use the same port as SQL's server.
Logged

Mini

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9127 on: February 25, 2016, 04:09:15 pm »

In options->advanced->connection there's a checkbox to (not) use ports 80 and 443. No idea how it effects Skype's function.
Logged

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9128 on: February 25, 2016, 10:34:54 pm »

In options->advanced->connection there's a checkbox to (not) use ports 80 and 443. No idea how it effects Skype's function.
I know. It didn't take long to fix, but I still wanted to express my annoyance.
Logged

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9129 on: February 26, 2016, 02:50:44 pm »

I'm looking for a bit of help with HTML.

Say I have a couple radio buttons, like:
Red Circle: <input type="radio" name="shape">
Blue Square: <input type="radio" name="shape">

...and I want them to each set two parameters, shape and colour, if selected. Is there any simple way to do that or do I need to set it like value="Red,Circle" and then have the server parse that?
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9130 on: February 26, 2016, 03:19:56 pm »

I do almost all of my logic like that with javascript.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9131 on: February 26, 2016, 04:12:51 pm »

We need more information to really know what you're trying to do.  Parameters for what?  If you want it to just be client side then you could encode the parameters as attributes on the inputs, like this:

Code: [Select]
<input type="radio" name="shape" shape="circle" color="red" />
<input type="radio" name="shape" shape="square" color="blue" />

To get those values you could use anything client side that works with DOM elements.  Pardon me for using jQuery here instead of raw DOM manipulation, but it's the best I can do from  memory.  Something like this would work:

Code: [Select]
$('input [type=radio]').click(function() {
    // $(this) refers to a single element matching that CSS selector, and in this case would be the radio button that was clicked
    var color = $(this).attr('color');
    var shape = $(this).attr('shape');

    // Do whatever else needs to happen when you change selections
});

You could just as easily encode those as the value and parse it on the server if you needed to.  Something like this:

Code: [Select]
<form action="some_script.php">
    <input type="radio" name="shape" value="circle,red" />
    <input type="radio" name="shape" value="square,blue" />
    <input type="submit value="Select Shape" />
</form>

Then you would just parse the value of the posted form's shape value on the server however you needed to.  In PHP, for example that might look something like this:

Code: [Select]
<?php
$pieces 
explode(","$_POST["shape"]);
$shape $pieces[0];
$color $pieces[1];

// Do whatever needed to happen when the form was submitted
?>


If you give us more details we can help with whatever it is you're trying to do exactly.
Logged
Through pain, I find wisdom.

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9132 on: February 26, 2016, 05:45:21 pm »

This was for a plain HTML form without client-side scripting. The example I just made up off the top of my head.

I was just curious if there was a way to define multiple parameters for a single input using only HTML. But, since it looks like there isn't, your last solution works for me. Thanks.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9133 on: February 26, 2016, 07:38:56 pm »

The last one is PHP, which means it has to have a page refresh for you to see the change. But you'd also need a way to make the change persistent (if the page was refreshed again, the information from the page would be reset).

The client-side Javascript solution allows the change to happen in real-time when the element is selected, and requires no page refresh. This is probably better.

In either case if you want the change to be persistent if they reload the page fully, then you need to store some information (the simplest way is in a cookie) for that purpose.
« Last Edit: February 26, 2016, 07:42:10 pm by Reelya »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9134 on: February 27, 2016, 01:04:14 am »

Hey guys i'm trying to create a really basic pop up messege where I use JOptonPane in java instead of the console.

Problem: I got my program to work so far that i can ask the program to create a regular account but it dosen't give me an ID and password for the account that is made. I've been trying to output this information into the GUI but I can't get the program to look through my arraylist properly.
Spoiler (click to show/hide)
Logged
Pages: 1 ... 607 608 [609] 610 611 ... 796