00:00
00:00
Newgrounds Background Image Theme

Hyper-Neko-Gold just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Programming Regs Lounge

714,983 Views | 15,737 Replies
New Topic Respond to this Topic

Response to Programming Regs Lounge 2013-07-31 09:49:01


At 7/31/13 06:45 AM, Dean wrote:
At 7/31/13 06:08 AM, deckheadtottie wrote: Don't suppose anyone knows the formula for calculating a percentage?

(amount / total) * 100 = %

For instance:
total_users = 500;
left_handed_users = 70;
(70.0 / 500.0) * 100 = 14;
14% of total_users are left_handed_users


"If loving Python is crazy then I don't want to be sane." -Diki

Response to Programming Regs Lounge 2013-07-31 16:32:03


So I've been playing around today with procedural generation, I'm pretty sure this algorithm is called the Drunkard Walk Algorithm (if it can be even called an algorithm), pretty basic.

Code:

class Generate
    {
        Random random = new Random();
        public Tile[,] generate(Texture2D tile)
        {
            int height = 50;
            int width = 50;
            Tile[,] level = new Tile[width, height];
            List<Vector2> miners = new List<Vector2>();
            miners.Add(new Vector2(1, 1));
            miners.Add(new Vector2(0, 1));
            miners.Add(new Vector2(1, 0));

            List<Vector2> directions = new List<Vector2>();
            directions.Add(new Vector2(1, 0));
            directions.Add(new Vector2(-1, 0));
            directions.Add(new Vector2(0, 1));
            directions.Add(new Vector2(0, -1));

            foreach (Vector2 miner in miners)
            {
                Vector2 p = miner;
                for(int i = 0; i < 1000; i++)
                {
                    Vector2 newP = p + directions[random.Next(4)];
                    if (newP.X < miner.X)
                        newP.X = miner.X;
                    if (newP.Y < miner.Y)
                        newP.Y = miner.Y;
                    level[(int)p.X, (int)p.Y] = new Tile(tile, p);
                    p = newP;
                }
            }
            return level;
        }
    }

    public class Tile
    {
        public Texture2D texture;
        public Vector2 position;
        public Tile(Texture2D Texture, Vector2 Position)
        {
            texture = Texture;
            position = Position;
            position.X *= texture.Width;
            position.Y *= texture.Height;
        }
    }

Any tips or comments from the masters?

Also, I would to get more square rooms, not just a mess of tiles. Any suggestion on the 1000s of algorithms out there for generation? (Preferably with a diagram)

Programming Regs Lounge


To protect the world from devastation.

kidd25 is the best Newgrounder ever.

BBS Signature

Response to Programming Regs Lounge 2013-08-02 15:34:33


At 7/31/13 04:32 PM, Thegluestickman wrote: Any tips or comments from the masters?

Also, I would to get more square rooms, not just a mess of tiles. Any suggestion on the 1000s of algorithms out there for generation? (Preferably with a diagram)

Here's the code for a BSP based dungeon generator I've made a while ago, it's written in C++, but the code itself should be pretty readable I guess

#define MIN_ROOM_AREA 25
#define MAX_ROOM_AREA 90

inline float MaxVal(float a, float b, float c, float d)
{
	float m1 = a > b ? a : b;
	float m2 = c > d ? c : d;
	return m1 > m2 ? m1 : m2;
}

inline float MinVal(float a, float b, float c, float d)
{
	float m1 = a < b ? a : b;
	float m2 = c < d ? c : d;
	return m1 < m2 ? m1 : m2;
}

struct BTreeNode
{
	bool isLeaf;

	BTreeNode* left;
	BTreeNode* right;

	Vector2 m_boxMin;
	Vector2 m_boxMax;
	BTreeNode(){left = NULL; right = NULL;}
	~BTreeNode(){delete left; delete right;}
};

void BuildLeafList(BTreeNode* root, std::vector<BTreeNode*>& outLeafList)
{
	if(root == NULL)
		return;

	if(root->isLeaf)
		outLeafList.push_back(root);
	BuildLeafList(root->left, outLeafList);
	BuildLeafList(root->right, outLeafList);
}

void FillMatrixArea(int startX, int startY, int endX, int endY, int width, MazeStorageType* maze)
{
	startX += 1;
	startY += 1;
	endX -= 1;
	endY -= 1;

	for (int i = startY; i < endY; ++i)
	{
		for(int j = startX; j < endX; ++j)
		{
			maze[j + i * width] = 0;
		}
	}
}

void GenerateMazeMatrix(int startX, int startY, int endX, int endY, int width, BTreeNode& crNode, MazeStorageType* maze)
{
	crNode.m_boxMin.X = startX;
	crNode.m_boxMin.Y = startY;
	crNode.m_boxMax.X = endX;
	crNode.m_boxMax.Y = endY;

	int xInterval = endX - startX;
	int yInterval = endY - startY;
	int area = xInterval * yInterval;

	crNode.isLeaf = false;

	if(xInterval < 4 || yInterval < 4)
		return;

	if(area < MIN_ROOM_AREA)
		return;

	if(area < MAX_ROOM_AREA)
	{
		crNode.m_boxMax.X -= 1;
		crNode.m_boxMax.Y -= 1;
		crNode.m_boxMin.X += 1;
		crNode.m_boxMin.Y += 1;
		FillMatrixArea(startX, startY, endX, endY, width, maze);
		crNode.isLeaf = true;
		return;
	}

	crNode.left = new BTreeNode();
	crNode.right = new BTreeNode();

	float aspect = (float)xInterval / yInterval;

	if(aspect > 1)
	{
		int splitPoint = (qrand() % (int)(xInterval * 0.9f)) + startX;
		GenerateMazeMatrix(startX, startY, splitPoint, endY, width, *crNode.left, maze);
		GenerateMazeMatrix(splitPoint, startY, endX, endY, width, *crNode.right, maze);
	}
	else
	{
		int splitPoint = (qrand() % (int)(yInterval * 0.9f)) + startY;
		GenerateMazeMatrix(startX, startY, endX, splitPoint, width, *crNode.left, maze);
		GenerateMazeMatrix(startX, splitPoint, endX, endY, width, *crNode.right, maze);
	}
}

void CreateTunnel(BTreeNode* room1, BTreeNode* room2, MazeStorageType* maze, unsigned int mazeWidth)
{
	bool overlapX = room1->m_boxMax.X >= room2->m_boxMin.X && room1->m_boxMin.X <= room2->m_boxMax.X;
	bool overlapY = room1->m_boxMax.Y >= room2->m_boxMin.Y && room1->m_boxMin.Y <= room2->m_boxMax.Y;

	if(overlapX)
	{
		unsigned int overlapEnd = room2->m_boxMax.X > room1->m_boxMax.X ? room1->m_boxMax.X : room2->m_boxMax.X;
		unsigned int overlapStart = room2->m_boxMin.X > room1->m_boxMin.X ? room2->m_boxMin.X : room1->m_boxMin.X;

		for(unsigned int i = room1->m_boxMax.Y; i < room2->m_boxMin.Y; ++i)
		{
			for(unsigned int j = overlapStart; j < overlapEnd; ++j)
			{
				maze[i * mazeWidth + j] = 0;
			}
		}
	}
	else if(overlapY)
	{
		unsigned int overlapEnd = room2->m_boxMax.Y > room1->m_boxMax.Y ? room1->m_boxMax.Y : room2->m_boxMax.Y;
		unsigned int overlapStart = room2->m_boxMin.Y > room1->m_boxMin.Y ? room2->m_boxMin.Y : room1->m_boxMin.Y;

		for(unsigned int i = overlapStart; i < overlapEnd; ++i)
		{
			for(unsigned int j = room1->m_boxMax.X; j < room2->m_boxMin.X; ++j)
			{
				maze[i * mazeWidth + j] = 0;
			}
		}
	}
	else
	{
		int lineStartY = room2->m_boxMax.Y > room1->m_boxMax.Y ? room1->m_boxMax.Y : room2->m_boxMax.Y;
		int lineEndY = room2->m_boxMin.Y > room1->m_boxMin.Y ? room2->m_boxMin.Y : room1->m_boxMin.Y;
		int lineStartX = room2->m_boxMax.X > room1->m_boxMax.X ? room1->m_boxMax.X : room2->m_boxMax.X;
		int lineEndX = room2->m_boxMin.X > room1->m_boxMin.X ? room2->m_boxMin.X : room1->m_boxMin.X;
		for(unsigned int i = lineStartX; i <= lineEndX; ++i)
		{
			unsigned int mazePosition = (unsigned int )(lineEndY * mazeWidth + i);
			maze[mazePosition] = 0;
		}

		for(unsigned int i = lineStartY; i <= lineEndY; ++i)
		{
			unsigned int mazePosition = (unsigned int)(i * mazeWidth + lineEndX);
			maze[mazePosition] = 0;
		}
	}
}

void CreateMazeMatrix(int sizeX, int sizeY)
{
	BTreeNode root;
	int area = sizeX * sizeY;
	std::vector<BTreeNode*> leafList;

	std::vector<MazeStorageType> mazeStorage;
	mazeStorage.resize(area, 1);

	GenerateMazeMatrix(0, 0, sizeX-1, sizeY-1, sizeX, root, &mazeStorage[0]);
	BuildLeafList(&root, leafList);

	size_t nrLeafIterations = leafList.size() - 1;
	for(size_t leafIt = 0; leafIt < nrLeafIterations; ++leafIt)
	{
		CreateTunnel(leafList[leafIt], leafList[leafIt + 1], mazeStorage, sizeX);
	}
}

It basically subdivides a linear matrix into rooms building a BSP tree along the way if you need it. I've biased the algorithm to try and equalize the aspect ratio of the rooms as much as possible, so it's still random, but at least it gives some not so boring square rooms. I've also used a minimum and maximum area for the rooms, but you can remove them if you want to and set it to generate a leaf when it reaches a certain or random level if you want to.

Pic of the generated dungeon attached

Programming Regs Lounge

Response to Programming Regs Lounge 2013-08-04 05:29:18


hey


BBS Signature

Response to Programming Regs Lounge 2013-08-06 14:21:29


At 8/2/13 08:05 AM, deckheadtottie wrote: A friend and I have been working on a simple Android app for the past couple of months.

That's actually quite impressive. I sort of went in expecting it to feel a bit cheap and nasty after your description but it's the opposite. It actually feels pretty professional and well done. Nice work.

Although my final year project was Android based I never really looked into all the fancy things you could do with the UI and as a result my software looked really basic. Is it pretty straight forward to get things looking all nice and pretty like that? I just resorted to using the default buttons and whatnot because I never had the time to muck about with that stuff, but I planned on looking into it.

Android development got a little dull for me once I had to return the Nexus 7 I was using. Now I'm back to using my little Wild Fire S and I feel limited having such a small screen to work with.


BBS Moderator - Feel free to send me a PM if you have a problem!

BBS Signature

Response to Programming Regs Lounge 2013-08-08 16:00:36


At 8/6/13 02:56 PM, deckheadtottie wrote: We really tried to keep the use of .png files down

Why? PNGs are great if you have an image with thousands of colours and alpha-transparencies that you don't want to be degraded in quality (since PNG is lossless). Of course if you don't have images that meet those requirements then you wouldn't need PNG, but I don't see why you'd actively avoid using it.

At 8/6/13 02:56 PM, deckheadtottie wrote: All the stylings are done in XML
At 8/6/13 02:56 PM, deckheadtottie wrote: Things like the animation are all done in XML

Wouldn't it be simpler to use a more succinct data structure like JSON?

Response to Programming Regs Lounge 2013-08-09 11:06:05


Free Schnail Mail For Life is quite possibly the coolest introduction for an open-source project I've ever seen.

I'm not entirely sure what the product is... It kind of seems like some form of VC firm.


"If loving Python is crazy then I don't want to be sane." -Diki

Response to Programming Regs Lounge 2013-08-09 11:17:32


At 8/8/13 04:45 PM, deckheadtottie wrote: I completely agree, but as I said, me and my programming buddy aren't artists and had to use free images we found on the internet.

That makes sense. A lot of people on the Internet have absolutely no clue what they're doing and use JPEG and GIF compression for images that should be done in PNG, but once they fuck it up with the wrong compression algorithm it's too late. :)

At 8/8/13 04:45 PM, deckheadtottie wrote: If you can, download it and you'll see pngs are used in sensible places.

I've been meaning to, and I'll get around to it eventually.

At 8/8/13 04:45 PM, deckheadtottie wrote: All the books and resources I read used XML for drawables/animations etc. XML is the native solution for this on the Android platform

Ah, I didn't know that it was how Android was designed (I've never done any development for it). I thought you were building your own thing and just happened to be using XML.

Response to Programming Regs Lounge 2013-08-09 11:23:22


At 8/9/13 11:06 AM, pirateplatypus wrote: Free Schnail Mail For Life is quite possibly the coolest introduction for an open-source project I've ever seen.

I'm not entirely sure what the product is... It kind of seems like some form of VC firm.

It's not an introduction to a project, it's a satirical explanation of Google's practices regarding GMail. They used all that "snail mail" talk as an analogy for how Google runs GMail, trying to make the point that what Google does is a violation of privacy.

Response to Programming Regs Lounge 2013-08-11 15:12:23


So, anyone want to explain why the hell this is valid JavaScript?

http://pastebin.com/zcqT7qKu
http://jsfiddle.net/p6AXL/


To protect the world from devastation.

kidd25 is the best Newgrounder ever.

BBS Signature

Response to Programming Regs Lounge 2013-08-12 00:38:05


Am I crazy, or didn't there used to be a sticky in this forum at one point?

Response to Programming Regs Lounge 2013-08-12 00:53:17


The only stickied threads that I can recall are news posts by the staff.

Response to Programming Regs Lounge 2013-08-13 17:17:04


Response to Programming Regs Lounge 2013-08-15 15:59:16


I try to keep a list of epically stupid and useless error messages and I hit one today that actually managed to skyrocket straight to the top.
Try to compile the following and see the result:

#include <vector>
#include <algorithm>

struct MyClass
{
	int a;
	int b;
	bool operator < (const MyClass& other){return other.a < a;} 
};

typedef std::vector<MyClass> MyVector;

int main()
{
	MyVector test;
	const MyVector& stupidError = test;
	std::sort(stupidError.begin(), stupidError.end());
	return 0;
}

Three pages of text and nothing remotely useful anywhere.

Response to Programming Regs Lounge 2013-08-15 17:51:05


At 8/15/13 03:59 PM, kiwi-kiwi wrote: Three pages of text and nothing remotely useful anywhere.

I uh, what?

Programming Regs Lounge


To protect the world from devastation.

kidd25 is the best Newgrounder ever.

BBS Signature

Response to Programming Regs Lounge 2013-08-15 22:02:32


At 8/15/13 03:59 PM, kiwi-kiwi wrote: I try to keep a list of epically stupid and useless error messages and I hit one today that actually managed to skyrocket straight to the top.
Try to compile the following and see the result:
Three pages of text and nothing remotely useful anywhere.

I think I should try this, too.

Response to Programming Regs Lounge 2013-09-02 13:33:31


In hopes of reviving this thread, what's everyone currently working on? Myself, I'm just working on a simulation of how ants find food using pheromones. For those who don't know, each ant follows simple rules and as they all interact together, complex behavior emerges such as finding the shortest path to food.

Programming Regs Lounge

Response to Programming Regs Lounge 2013-09-11 21:59:52


Is it just me, or is the top selling themes on themeforest.net have the exact same layout? Header bar with navigation and logo, maybe contact info. Huge picture slideshow. Columns with some sort of hoopla (blog posts, "why we're the best," etc.). Maybe another huge picture. More columns with even more detailed text. Then a huge footer with tons of links to blog posts, social media sites, search boxes, about the company/site, and more contact info.

Am I going crazy?


BBS Signature

Response to Programming Regs Lounge 2013-09-12 00:17:52


At 9/2/13 01:33 PM, Daedalu5 wrote: In hopes of reviving this thread, what's everyone currently working on?

Nothing as fancy as an ant simulator, but I'm improving my Python networking library. I've been too lazy to push my changes to the repo so what you see there doesn't accurately represent what the library is actually like now.

I'm also porting it to C++ to be used as the backend for an online web-based hacking game (comparable to Uplink and Slave Hack) that I am prototyping. If the prototype ends up being decent I'll go through with the idea and actually make the game.

At 9/11/13 09:59 PM, coln wrote: Is it just me, or is the top selling themes on themeforest.net have the exact same layout?

From what I can tell you're referring to the layouts that look like this, this, and this. They are very similar because that is a cliche layout; it's used all over the place. It's not that the people who designed those are stealing from one-another, it's just that they weren't, in those instances, original.

Response to Programming Regs Lounge 2013-09-12 00:35:44


At 9/12/13 12:17 AM, Diki wrote: From what I can tell you're referring to the layouts that look like this, this, and this. They are very similar because that is a cliche layout; it's used all over the place. It's not that the people who designed those are stealing from one-another, it's just that they weren't, in those instances, original.

Ah, well I did not mean to imply that I thought they were stealing from each other. I just thought it kind of funny that the "top selling of all time" designs were all related to that similar design.


BBS Signature

Response to Programming Regs Lounge 2013-09-13 09:07:55


I was doing embedded programming and now im homeless so i can't really program right now. But i am going to call my folks and ask them to get me a laptop with netbeans so i can do some basic programming (sorry i don't program with notpad yet lol).

Response to Programming Regs Lounge 2013-09-13 15:01:39


At 9/13/13 09:07 AM, PMMurphy wrote: I was doing embedded programming and now im homeless so i can't really program right now.

SHouldn't programming be the least of your worries?


To protect the world from devastation.

kidd25 is the best Newgrounder ever.

BBS Signature

Response to Programming Regs Lounge 2013-09-13 20:49:00


At 9/2/13 01:33 PM, Daedalu5 wrote: In hopes of reviving this thread, what's everyone currently working on?

IRC bot in python.
Will be done in a few days


BBS Signature

Response to Programming Regs Lounge 2013-09-13 20:52:37


At 9/13/13 08:49 PM, DaysOfThePheonix wrote: in python.

I like it already.

Response to Programming Regs Lounge 2013-09-13 21:14:01


Happy Programmers' Day everyone!

Response to Programming Regs Lounge 2013-09-13 22:43:29


I'm having fun here in Colorado being wiped off the face of the earth by floods. How's everyone else?

Response to Programming Regs Lounge 2013-09-13 23:03:01


At 9/13/13 08:52 PM, Diki wrote:
At 9/13/13 08:49 PM, DaysOfThePheonix wrote: in python.
I like it already.

I recently started learning python and I wanted to put it to use.
Although Im still a beginner, I think Im doing well.

You program in python?

Oh yeah, do you know of a good site/books I could for reference?


BBS Signature

Response to Programming Regs Lounge 2013-09-13 23:39:34


At 9/13/13 11:03 PM, DaysOfThePheonix wrote: I recently started learning python and I wanted to put it to use.
Although Im still a beginner, I think Im doing well.

Keep it up. Python is a fantastic language.

At 9/13/13 11:03 PM, DaysOfThePheonix wrote: You program in python?

Yep. Python is my favourite programming language. I've written a lot of things in Python, but currently the only that I've made publicly available is my networking library. I've also made other things like websites, and chat applications, but they weren't very well-made which is why I didn't make them public.

At 9/13/13 11:03 PM, DaysOfThePheonix wrote: Oh yeah, do you know of a good site/books I could for reference?

The book that I learnt Python from, and the book that I recommend more than any other, is Learn Python the Hard Way (it's free). It is a very well written book by a very knowledgeable author. I cannot recommend it enough.

Response to Programming Regs Lounge 2013-09-14 00:13:14


At 9/13/13 11:39 PM, Diki wrote: Keep it up. Python is a fantastic language.

I plan to!

Yep. Python is my favourite programming language. I've written a lot of things in Python, but currently the only that I've made publicly available is my networking library. I've also made other things like websites, and chat applications, but they weren't very well-made which is why I didn't make them public.

I know JS more than anything and have really only made small time stuff too, nothing big enough to publish or share but I learn more everyday!

The book that I learnt Python from, and the book that I recommend more than any other, is Learn Python the Hard Way (it's free). It is a very well written book by a very knowledgeable author. I cannot recommend it enough.

Alright thanks!
What are you thoughts on codeacademy? I used to learn stuff there but I dont go there much anymore.


BBS Signature

Response to Programming Regs Lounge 2013-09-14 00:48:54


At 9/14/13 12:13 AM, DaysOfThePheonix wrote: What are you thoughts on codeacademy? I used to learn stuff there but I dont go there much anymore.

It's a site that apparently works for some people, but not one I have ever used or would ever recommend. There's too much focus on flashy gimmicks opposed to focusing solely on what Zed A. Shaw did in his book: teaching. As well I can't find anything on CodeAcademy that shows practical applications of what is being taught; it basically just teaches syntax and then says "have a nice day". You're certainly not going to find something like this on there. CodeAcademy also does not teach concepts such as debugging, despite that being one of the most important aspects of programming.

All in all my opinion of CodeAcademy is that it was made by knowledge programmers whom don't know how to teach properly, and put little to no thought into the structure and contents of the curriculum.

I'm probably the only person on NG that will have anything bad to say about CodeAcademy, so of course take what I'm saying with a grain of salt.