Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 18 19 [20] 21 22 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95878 times)

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #285 on: July 22, 2010, 07:20:34 am »

The "recently filled pixels" is usually denoted by a pixel of the same color as you're trying to fill. Most simple flood-fill algorithms do that since it's probably the easiest way to do it.

EDIT:

@ILikePie:
I don't see where you're getting that sentiment from. If we thought you were a moron, would we be helping you?
« Last Edit: July 22, 2010, 03:32:44 pm by Normandy »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #286 on: July 22, 2010, 07:47:48 am »

Spoiler (click to show/hide)

The problem with just using the color as "recently filled" is that you can have a barrier of the fill color. If you have white-red-white, and I fill the left white red, the other white should not fill. Or I don't understand what you just said :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #287 on: July 22, 2010, 09:02:33 am »

How about this? It would compile if it had a main()...
I didn't go so far as to test it in OpenGL, but it probably works.

Spoiler: long (click to show/hide)
Logged
Eh?
Eh!

DrPizza

  • Bay Watcher
    • View Profile
    • Ars Technica
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #288 on: July 22, 2010, 09:08:34 am »

Quote
What? There is precisely nothing that can be done recursively that cannot be done in an iterative manner.
That's not a useful statement.

Every iterative function can be trivially transformed to a recursive one.

The reverse is not true, however. Converting a recursive function to an iterative one requires explicit maintenance of a stack. This is fiddly at best for simple recursive functions, and a complete pain in the ass for mutually recursive functions.

Now, every tail recursive function can be trivially transformed to an iterative one, but not all functions are tail recursive. You can sorta-kinda make them all tail recursive with CPS, but that has all sorts of complexities of its own.

Iteration may be faster in many circumstances, but oftentimes the recursive solution is simpler and easier to read, and this consideration is almost always the more important one.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #289 on: July 22, 2010, 09:16:59 am »

@querty Nice, except... :) (there I go)

You add every pixel 4 times, and all into the same queue. Which makes a 10 by 10 px fill a queue of 400*sizeof(RGB), and a 256 by 256 fill a size of 262144 RGB's. Whereas my solution continuously discards already written pixels. Which could be a performance hit in itself, but uses less memory at the same time.
FAKEEDIT: ok, my fault, you do an in-queue check so you don't get the 4-times multiplier, but you do iterate over the entire queue for every add, which is even worse, as you now iterate 262144+262143+262142+262141+ ... 3+2+1 times 2 over the queue to check if it's not already in...
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #290 on: July 22, 2010, 09:29:58 am »

Except that they are removed once read, so it must only go over <perimeter> entries. For a 256x256 square, that will remain fairly low, under 2000, and for oddly shaped other things, it will depend on the shape, but still shouldn't be that bad.
The biggest issue I see is that often it will reallocate when a simple move would be adaquate.

Agh, and I forgot the most important one of all, the check to see that target colour != fill colour.
Logged
Eh?
Eh!

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #291 on: July 22, 2010, 09:40:54 am »

Except that they are removed once read, so it must only go over <perimeter> entries. For a 256x256 square, that will remain fairly low, under 2000, and for oddly shaped other things, it will depend on the shape, but still shouldn't be that bad.
The biggest issue I see is that often it will reallocate when a simple move would be adaquate.

Agh, and I forgot the most important one of all, the check to see that target colour != fill colour.
Yep, you're right, didn't see that in queue_next, sorry et mea maxima culpa.

Good challenge by the way, ilikepie, I liked it :)
Targetcolor == fillcolor should return as soon as it's called, for every fillfunction.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #292 on: July 22, 2010, 03:53:19 pm »

The last time I wrote a fill function was about a year and a half ago, and the article I read said to immediately return the floodFill() function if the chosen pixel's color is not equal to the previous color, or more importantly, equal to the fill color. There will be only three cases when the pixel's color will equal the flood fill color:

1) The pixel is already that color, and hence the flood fill doesn't need to act
2) The pixel was originally that color, and hence not part of the original flood fill region
3) The pixel was set that color by the flood-fill function, and thus has already been visited

Hence, the only checking you need to do is whether or not the pixel is equal to the original color or not equal to the flood filled color. I'm not sure this applies to hardware accelerated stuff because accessing RGB values directly requires a software buffer - but that's not of concern, and I'm way out of my league when talking about that.

As well, you may want to replace std::list by std::stack or std::queue, because the latter two are more idiomatic to what is actually happening. In the recursive floodFill() function, it's functionally the same as doing the iterative function using a stack instead of a queue (hence, the "stack"). When you do the queue version, you get a modified behavior.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #293 on: July 22, 2010, 05:06:50 pm »

Good challenge by the way, ilikepie, I liked it
Wait, wait, wait, wait... I think I missed something.
« Last Edit: July 22, 2010, 05:13:25 pm by ILikePie »
Logged

Toady One

  • The Great
    • View Profile
    • http://www.bay12games.com
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #294 on: July 22, 2010, 05:51:22 pm »

Please try to keep it polite in here.  Siquo and Supermikhail have been warned for their insults.
Logged
The Toad, a Natural Resource:  Preserve yours today!

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #295 on: July 23, 2010, 02:41:22 am »

Duly noted, my apologies.

@iLikePie: well, thinking about the floodfill was fun to do :)

@normandy, Yeah, you're right. The fill only needs one colorcheck, and I didn't really look at what container was necessary. A stack would've been just as good. So far I just used map, list and vector, as they are the only three with really different access. Stack, queue, deque, etc. I've never really had a use for.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #296 on: July 30, 2010, 03:20:21 pm »

Argh. Facepalm. Okay, I want to translate an image, right? Sounds simple: I have a large image, and want to move the borders of the image by a certain amount, sort of like panning a viewport. In fact, it's exactly like panning a viewport over a map. The problem: when I try something simple like this (this is in Java, but the concepts are more or less universal):

Code: [Select]
Graphics2D g2d = imgbuf.createGraphics();
AffineTransform atr = new AffineTransform();
atr.translate(-dx, -dy);
g2d.drawImage(imgbuf, atr, null);

It works, but only when translating down and/or right of the screen. Going up and/or left, because it overwrites the image data as it draws on the image, unexpected behavior happens. It completely aggravates me that it works in this one direction, but not the other.

Anyone have a solution to this quandary? Surely there is some hardware accelerated way for safely translating and blitting an image onto itself that doesn't involve copying the entire image buffer?
« Last Edit: July 30, 2010, 04:35:03 pm by Normandy »
Logged

Dakorma

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #297 on: July 30, 2010, 05:13:56 pm »

I had a small/vague question. How long does it take to learn how to make things like Minecraft?
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #298 on: July 30, 2010, 05:47:39 pm »

I've been programming as a hobby for four years now, and I'm just beginning to be able to pull off even vaguely complex programs now, if that's any indication of anything. Though to be fair, I am still in school (not in computer science) and my learning time is limited.
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #299 on: July 31, 2010, 07:39:29 am »

I had a small/vague question. How long does it take to learn how to make things like Minecraft?
???
with experiance in what? nothing??
Logged
Pages: 1 ... 18 19 [20] 21 22 ... 78