Skip to content

Instantly share code, notes, and snippets.

  • Save alloy-d/871932 to your computer and use it in GitHub Desktop.
Save alloy-d/871932 to your computer and use it in GitHub Desktop.
Being a horrid troll; move along...
var useSeveralSmallAndSinglePurposeHelperFunctionsToManipulateASetOfClearlyNamedVariablesWithTheUltimatePurposeOfCreatingSomethingThatLooksLikeASpiralGalaxy = function () {
var imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy = 0;
var imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy = 0;
var imCallingThisVariableTemporaryCounterVariableToMakeBrianHappy = 0;
var imCallingThisTheArrayOfStarsThatHasOneSubarrayForEachArmInTheSpiralGalaxyToMakeBrianHappy = [];
var getARandomColorThatIsEitherBluishOrReddish = function () {
// returns a random color that is either bluish or reddish.
// used in addStar().
}
var addStar = function (arm, x, y) {
// creates a star and adds it to the array of stars that has
// one subarray for each arm in the spiral galaxy.
}
var drawStar = function (star) {
// draws a star on the canvas using its x and y position,
// randomly generated color, and a completely arbitrary
// measure of size to which we should avoid using any
// convenient name to refer in the interest of not going afoul
// of physics or code clarity.
}
for (imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy = 0; imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy < 7; imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy += 1) {
imCallingThisTheArrayOfStarsThatHasOneSubarrayForEachArmInTheSpiralGalaxyToMakeBrianHappy[imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy] = []
for (imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy = 1; imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy < 1000; imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy += 1) {
for (imCallingThisVariableTemporaryCounterVariableToMakeBrianHappy = 0; imCallingThisVariableTemporaryCounterVariableToMakeBrianHappy < 5000; imCallingThisVariableTemporaryCounterVariableToMakeBrianHappy += 10 * imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy) {
addStar(imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy, imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy + rn(70), 100 * Math.log(imCallingThisVariableDistanceInArbitraryUnitsAlongTheCurveToMakeBrianHappy - 2) + rn(60))
}
}
}
return {
draw: function () {
var imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy = 0
context.save()
context.translate(cw(700), ch(300))
context.rotate(Math.PI / 7)
for (imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy = 0; imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy < 7; imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy += 1) {
Array.each(imCallingThisTheArrayOfStarsThatHasOneSubarrayForEachArmInTheSpiralGalaxyToMakeBrianHappy[imCallingThisVariableIndexOfArmInTheSpiralGalaxyToMakeBrianHappy], drawStar)
context.rotate(2 / 7 * Math.PI)
}
context.restore()
},
stars: imCallingThisTheArrayOfStarsThatHasOneSubarrayForEachArmInTheSpiralGalaxyToMakeBrianHappy,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment