Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Mata
Dec 23, 2003
Now that I think about it, doing it with fractals seems obvious! That page will help me a lot!

Adbot
ADBOT LOVES YOU

Cirofren
Jun 13, 2005


Pillbug
Is there a good book for intermediate/hobby developers on Windows Mobile 6 programming? I won't have an opportunity to check out the SDK until tomorrow so there's a chance that the code samples there will have what I need. But if anyone knows of a good/worthwhile book then that'd be great!

Scaevolus
Apr 16, 2007

Mata posted:

Alright, bear with me on this one.. I'm trying to generate an infinitely large height-map. I want it to resemble a landscape/map of some sort, so I don't want there to be any obviously recognizable patterns, but it can't be "too" random: Hills and mountains have slopes, not random jagged spikes, same with continents and oceans... So I figured, overlapping sine functions with random periods might look good: A huge sine curve would form continents, smaller ones would be mountain ranges, smaller still might make hills, etc: Plus, it "loops" so it doesn't matter wether you're looking at a region at (100000,70000) or at (0,0).

Perlin noise sounds perfect for what you want to do. It's basically your like your idea of layering multiple sine functions. Here's a good tutorial on it. It's quite efficient as well.

You can tweak the parameters to get various effects: (from here)


e: simplex noise (also invented by Perlin) might be better

quote:

The advantages of simplex noise over Perlin noise:
* Simplex noise has a lower computational complexity and requires fewer multiplications.
* Simplex noise scales to higher dimensions (4D, 5D and up) with much less computational cost, the complexity is O(n>n) for n dimensions instead of the O(2n) of classic Noise[2].
* Simplex noise has no noticeable directional artifacts (is isotropic).
* Simplex noise has a well-defined and continuous gradient everywhere that can be computed quite cheaply.
* Simplex noise is easy to implement in hardware.

Perlin/simplex noise is much easier to generate in realtime than fractal noise.

Scaevolus fucked around with this message at 07:51 on Jan 7, 2009

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
edited out

Hammerite fucked around with this message at 20:22 on Jan 7, 2009

csammis
Aug 26, 2003

Mental Institution
Just FYI, I know you already moved it once, but the list of links in the OP of this thread includes the Web Development Megathread.

zootm
Aug 8, 2006

We used to be better friends.

Fly posted:

There have got to be older editions for sale at a quarter of that price.
Well there's what appears to the same edition of the same book on a linked page anyway.

hey mom its 420
May 12, 2007

I need to see how long a piece of C code needs to run. What's the most reliable way to time it? I found this method:
code:
clock_t t1, t2;
float ratio;
ratio = 1./CLOCKS_PER_SEC;
// Record the start time:
t1 = clock();
/*************************
Run a segment of Code
*************************/
// Record the end time:
t2 = clock();
// Print out the difference, converting it to seconds:
printf("Time = %f", ratio*(long)t1 + ratio*(long)t2 );
and it seems to work, only I don't get why. There's a + there at the end. Shouldn't it be a -, because a time delta is t2 - t1?

EDIT: I can't use the unix time program because I have to time my program at 4 different sections (three of which take a really short time and one takes quite a long time) and I also have to disregard the time it takes to do some preliminary I/O (loading up a file into memory)

hey mom its 420 fucked around with this message at 23:26 on Jan 7, 2009

WildGunman
Feb 11, 2005
Fathering the Anti-Christ since 1927
Quick question regarding web crawling. Is perl still the best language out there for scripting web crawling stuff? I know the choice of language is a religious debate, but I was wondering if there was any consensus in this small sphere. I'm going to end up doing a lot of scripting trying to pull and parse information from the web and I'd rather not go down roads I don't need to.

tef
May 30, 2004

-> some l-system crap ->
It is less about the language and more about the libraries - it depends what level you will have to be parsing the html (text only/html only/ with javascript?).

Most dynamic languages make excellent choices - Perl has LWP::Simple and a few html parsing modules.

Python has beautifulsoup (slow) or lxml to parse html, and urllib2 or pycurl to grab pages.

I'm not sure about ruby, but I'm pretty sure it has similar libraries.

Really, Perl, Ruby or Python are perfectly capable of web crawling.

hexadecimal
Nov 23, 2008

by Fragmaster

WildGunman posted:

Quick question regarding web crawling. Is perl still the best language out there for scripting web crawling stuff? I know the choice of language is a religious debate, but I was wondering if there was any consensus in this small sphere. I'm going to end up doing a lot of scripting trying to pull and parse information from the web and I'd rather not go down roads I don't need to.

Lex/Yacc + Libcurl (C/C++) is what I would use. Depending on how complex your parsing needs to be for the webpage, you may or may not need Yacc, but lexer is a pretty nice tool. Also fast as gently caress.

hexadecimal fucked around with this message at 02:16 on Jan 8, 2009

floWenoL
Oct 23, 2002

hexadecimal posted:

Lex/Yacc + Libcurl (C/C++) is what I would use. Depending on how complex your parsing needs to be for the webpage, you may or may not need Yacc, but lexer is a pretty nice tool. Also fast as gently caress.

You seriously give the worst programming advice.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
What. Why would you write a parser for HTML when you could just, you know, use any implementation of DOM you want?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Man, you shoulda told him to implement his own HTTP library. Fast as gently caress

hexadecimal
Nov 23, 2008

by Fragmaster
But on a serious note, using lexer itself is not that complicated and is enough to pull out links and other tags from a given webpage or something. Also he asked for what is the fastest, and I don't think you can beat lexer / DFAs.

hexadecimal fucked around with this message at 03:12 on Jan 8, 2009

DLCinferno
Feb 22, 2003

Happy
Heh, and last time someone asked how to read XML he told them to use lex/yacc...

http://forums.somethingawful.com/showthread.php?threadid=2779598&userid=143791#post353463540

I think someone needs a new custom title.

Only registered members can see post attachments!

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

You know what else is equivilent to a DFA? A regular expression.

hexadecimal posted:

Also he asked for what is the fastest
Where?

hexadecimal
Nov 23, 2008

by Fragmaster

Dijkstracula posted:

You know what else is equivilent to a DFA? A regular expression.

In theory yes, but who knows how some random library implements it. With lexer you know!

quote:

where?
Oh whoops, I guess I misread :( Still Lex/Yacc rule. You're all just mad you cant manually resolve ambiguous BNF grammar!

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

hexadecimal posted:

You're all just mad you cant manually resolve ambiguous BNF grammar!
We're mad because it's not at all the right choice for what he's trying to do. Also, yacc will not resolve an ambiguous grammar (unlike us, who can resolve ambiguous grammars of natural languages, unlike LALR parsers), either: it'll bitch about shift/reduce and/or reduce/reduce errors and make a set choice.

edit: also, I'm preeeetty sure a ton of work has gone into optimizing the poo poo out of perl/python/$LANGUAGE_OF_THE_WEEK's regex library anyway.

hexadecimal
Nov 23, 2008

by Fragmaster

Dijkstracula posted:

We're mad because it's not at all the right choice for what he's trying to do. Also, yacc will not resolve an ambiguous grammar (unlike us, who can resolve ambiguous grammars of natural languages, unlike LALR parsers), either: it'll bitch about shift/reduce and/or reduce/reduce errors and make a set choice.

edit: also, I'm preeeetty sure a ton of work has gone into optimizing the poo poo out of perl/python/$LANGUAGE_OF_THE_WEEK's regex library anyway.

That's why I said "manually" :smug:

floWenoL
Oct 23, 2002

DLCinferno posted:

I think someone needs a new custom title.

[big-red-text]
IGNORE ANYTHING I HAVE TO SAY REGARDING PROGRAMMING
[/big-red-text]

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
You know, hex, when normal people are criticized for their bad advice, they stop to think about why they are being criticized and sometimes even work to improve themselves so they can give good advice, rather than just vomiting up a bunch of dumb words to justify the bad advice they initially supplied.

hexadecimal
Nov 23, 2008

by Fragmaster

Avenging Dentist posted:

You know, hex, when normal people are criticized for their bad advice, they stop to think about why they are being criticized and sometimes even work to improve themselves so they can give good advice, rather than just vomiting up a bunch of dumb words to justify the bad advice they initially supplied.

Ok I agree. Sorry I sort of trolled in this thread. I will not do it again.

vapid cutlery
Apr 17, 2007

php:
<?
"it's george costanza" ?>
Whoops, I left my posting knob on teh "troll" setting :smug:

That Turkey Story
Mar 30, 2003

ahhh spiders posted:

Whoops, I left my posting knob on teh "troll" setting :smug:

Looks more like the GBS setting to me.

Mata
Dec 23, 2003
Thanks everyone, I went with the Perlin method for my heightmaps! Looking much better now:

tef
May 30, 2004

-> some l-system crap ->

hexadecimal posted:

Depending on how complex your parsing needs to be for the webpage, you may or may not need Yacc, but lexer is a pretty nice tool. Also fast as gently caress.

Althugh everyone else has already called you out for this, the reason why I recommended things like beautifulsoup or lxml is that although parsing well formed htm lis easy, html is never well formed.

An HTML parser that supports xpath is a fantastic invention, I think some even support css selectors too.

TSDK
Nov 24, 2003

I got a wooden uploading this one

Bonus posted:

I need to see how long a piece of C code needs to run. What's the most reliable way to time it? I found this method:

and it seems to work, only I don't get why. There's a + there at the end. Shouldn't it be a -, because a time delta is t2 - t1?

EDIT: I can't use the unix time program because I have to time my program at 4 different sections (three of which take a really short time and one takes quite a long time) and I also have to disregard the time it takes to do some preliminary I/O (loading up a file into memory)
The only reason I can think for it apprearing to work, is that you're timing from very near the start of the program, when t1 is near to zero.

But yeah you're right, the time delta should be t2-t1.

Also the casting and pseudo-optimisation of turning one divide into two multiplies is a bit dumb. For quick and dirty, I generally use something like:
code:
clock_t start = clock();
// STUFF
clock_t stop = clock();
printf( "Time = %f ms\n", (float)( stop - start ) / ( CLOCKS_PER_SEC / 1000 ) );

chocojosh
Jun 9, 2007

D00D.
Ok not programming specific but CoC specific and I figure it will get read here.

I'm seeing a few threads specifically for job offers (there's a sudden increase in demand after the holidays?). There's also been a few posters mentioning they're looking for jobs, and I'm pretty sure that there are a fair amount of students on this forum like myself that will be looking for a summer internship.

Any thoughts on there being a single thread specifically for job seekers/job offers?

csammis
Aug 26, 2003

Mental Institution

chocojosh posted:

Any thoughts on there being a single thread specifically for job seekers/job offers?

Cidrick or one of the other mods should weigh in on this. I'm not sure how well it'd work. With the single thread per job offer model, jobs that aren't open anymore or aren't interesting will just go away eventually, or could be closed. If they were all in a single thread, offers that aren't good anymore will either have to be edited out or we'll get a lot of "I saw this back on page 2 and I know it's page 48 and three years later, but..."

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

tef posted:

I'm not sure about ruby, but I'm pretty sure it has similar libraries.

There's a ruby port of Beautiful Soup called rubyful soup but I've never used it. I have used Hpricot and liked it.

Presto
Nov 22, 2002

Keep calm and Harry on.
So, how 'bout that IPv6, eh?

I'm trying to update some code at work so that when someone someday decides that we need to make the switch to IPv6 I can slack off.

I have code similar to this:
code:
struct sockaddr_storage some_box;
socklen_t some_size;

...

some_size = sizeof(some_box);
cfd = accept(sfd, (struct sockaddr *)&some_box, &some_size);
When I connect a socket from the same machine using the IPv4 address, and I pull the address info of some_box (with inet_ntop), I get the actual IP address of the machine. If I connect using the IPv6 address, I get the loopback address instead. I've looked at the actual bytes in the some_box struct, and the accept() really is putting the loopback in there, so it's not inet_ntop's fault.

The server- and client-side sockets are set up in exactly the same way for both, except the address family for one is AF_INET and the other is AF_INET6. This is on Linux if it makes a difference.

I can work around this, but it's kind of a wart. Is this the intended behavior? Is it because my IPv6 address really a fake being tunneled back to the IPv4 address? Or what?

hey mom its 420
May 12, 2007

TSDK posted:

The only reason I can think for it apprearing to work, is that you're timing from very near the start of the program, when t1 is near to zero.

But yeah you're right, the time delta should be t2-t1.

Also the casting and pseudo-optimisation of turning one divide into two multiplies is a bit dumb. For quick and dirty, I generally use something like:
code:
clock_t start = clock();
// STUFF
clock_t stop = clock();
printf( "Time = %f ms\n", (float)( stop - start ) / ( CLOCKS_PER_SEC / 1000 ) );

Thanks, that works great! I don't even care for the exact timing, I'm just trying to see if the running time increases according to the algorithm time complexity.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

TSDK posted:

Also the casting and pseudo-optimisation of turning one divide into two multiplies is a bit dumb. For quick and dirty, I generally use something like:
code:
clock_t start = clock();
// STUFF
clock_t stop = clock();
printf( "Time = %f ms\n", (float)( stop - start ) / ( CLOCKS_PER_SEC / 1000 ) );

The division-to-multiplication optimization is not a bad one, although it would obviously be better to turn one division into one multiplication instead of two. If CLOCKS_PER_SEC is a compile-time constant (likely), your compiler should turn this into the optimal thing, but it probably wouldn't if it isn't.

hexadecimal
Nov 23, 2008

by Fragmaster
Can someone talk about free pool data structure? I saw some Microsoft research guy talk about it today on research channel, and it seemed interesting, but I didn't understand much from his short explanation.

Randomosity
Sep 21, 2003
My stalker WAS watching me...
This is kind of dumb, but anyone know about writing to the command line without spitting out a new line? I need to do a progress counter and don't want just spit out new lines.

This is in Groovy (which uses Java's output mechanisms).

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Randomosity posted:

This is kind of dumb, but anyone know about writing to the command line without spitting out a new line? I need to do a progress counter and don't want just spit out new lines.

This is in Groovy (which uses Java's output mechanisms).

I don't know anything about Groovy, but I know that Java has two separate printing functions: System.out.println (which prints a newline at the end) and System.out.print (which doesn't).

Randomosity
Sep 21, 2003
My stalker WAS watching me...
Well, I understand that stuff perfectly fine. I want to change to print new information without writing new lines to the buffer.

For example,
code:
1% done.
2% done.
3% done.
becomes
code:
1% done.
and then changes to
code:
2% done.
and then
code:
3% done.
etc.

It's just a stupid stylistic thing, but I'm curious how it's done.

zootm
Aug 8, 2006

We used to be better friends.

Randomosity posted:

It's just a stupid stylistic thing, but I'm curious how it's done.
In C, at least, if you print out "\r" it'll move you back to the beginning of the current line and let you type over it again. I think.

Edit: One-liner to show it in Ruby:
code:
(1..100).each { |i| print( "\r#{i}% done." ); sleep( 0.1 ) }

zootm fucked around with this message at 18:25 on Jan 9, 2009

yippee cahier
Mar 28, 2005

Randomosity posted:


I do this in python by accessing the stdout stream directly and sending it '\b' characters.

Adbot
ADBOT LOVES YOU

zootm
Aug 8, 2006

We used to be better friends.

sund posted:

I do this in python by accessing the stdout stream directly and sending it '\b' characters.
Yeah, \b moves back one character whereas \r moves to the beginning of the current line.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply