Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active January 31, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajweeks/2f3bfc4736baf538db99 to your computer and use it in GitHub Desktop.
Save ajweeks/2f3bfc4736baf538db99 to your computer and use it in GitHub Desktop.
Devember Day Four

Devember Day 04

Happy Friday! I got a solid 2.5 hours of coding done today, just more work on my school assignment, which is finally finished. We had to make a dice rolling simulator and display the results, as well as a Koch snowflake renderer. I've made Koch snowflakes before, but this time I tried using a different method. You can see the main recursive method here:

void VectorAdd3::AddKochPoints(DOUBLE2 startPoint, DOUBLE2 endPoint, std::vector<DOUBLE2> &kochArrRef)
{
	DOUBLE2 diff = endPoint - startPoint;
	if (diff.Length() < 12)
	{
		kochArrRef.push_back(endPoint);
		return;
	}


	DOUBLE2 p1 = startPoint;
	DOUBLE2 p2 = startPoint + (diff / 3.0);
	DOUBLE2 p4 = startPoint + (2.0 * diff / 3.0);
	DOUBLE2 p5 = endPoint;

	DOUBLE2 d = p4 - p2;
	DOUBLE2 p3 = p2 + DOUBLE2(
		d.x * cos(-M_PI / 3.0) - d.y * sin(-M_PI / 3.0),
		d.x * sin(-M_PI / 3.0) + d.y * cos(-M_PI / 3.0));

	AddKochPoints(p1, p2, kochArrRef);
	AddKochPoints(p2, p3, kochArrRef);
	AddKochPoints(p3, p4, kochArrRef);
	AddKochPoints(p4, p5, kochArrRef);
}

I added a few different snowflakes of different size and colour and set them to rotate around.

Unfortunately you can't seem to preview gifs (or gifv's) on here, but you can see a gif of it spinning here

I also spent a while playing around with a simple particle effect shown briefly in yesterday's post. That's it for now! Tomorrow I will get some more work done on TM495.

Previous Entry | All Entries | Next Entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment