Saturday, July 19, 2014

Matt's Gaming Corner #1: Left 4 Dead 2

Like our fan-base, we are gamers. And, like all gamers, we like to discuss games. I will be, as you may have guessed, writing articles on gaming here. Feel free to comment on them, and have a good time.

So, For a small introductory article, today I was able to test AMD's answer to NVIDIA Shadowplay: AMD Game DVR. The results were fantastic. I was able to record Left 4 Dead 2 without the stuttering or outright freezing that were staples of my previous high quality recordings using Open Broadcast System. I played the entirety of the level Dead Center: Hotel.


I continued on my adventure on the next level: The Streets. Here, I encountered one hiccup. When the first horde spawned, the game began to stutter. Afterwards, as well as during further hordes, the game ran perfectly. This leads me to think that either the hard drive was overworked (I record the video to the D:\ drive, as well as play my games on it) or  my RAM was maxed out. I believe it had something to do with the hard drive, as I have 4GB. However, I do not think this will be a problem as long as Game DVR continues to work as well as it has.

If you would like to view higher quality, uncompressed versions, please go here
Monday, July 14, 2014

Python Lesson 1: Downloading Python and Hello World

Hello guys, and welcome to my python lesson series! In lesson 1, we will learn a little about the language, find and download a release and do a python "Hello World" example as our first program!

What is Python?

Python is a high level programming language, like Java, or C. Python allows you to easily reuse code you have written. For example, suppose you wrote a 10000 line program for a project. Then 6 months later, you need to use the code in a different project. Thanks to python's high level capabilities, adding all this code to your new project is as simple as 1 line of code in the new project. Python is the 4th most popular programming language, behind Java, C, and C++. You can use python for pretty much anything, from 2D and 3D games, to scientific studies, to number crunching (with numpy) and pretty much anything else you can think of. Python is also open source. This means that anyone can see it's source code. Java, on the other hand, is closed source, which means that you cannot see its source code.

Downloading Python

There are 2 versions of python that are commonly used today. At the time of this writing, the newest releases are 3.4.1 and 2.7.8 . You may be thinking: "Hey why do people use python 2 and not just use python 3?" This is because when python 3 was released, it did not offer backwards compatibility to python 2. Python 3 would not run python 2 code, causing a big issue. All previous work had to be ported to python 3. Although an automated python 2 to 3 converter was released, the tool is not perfect and usually a lot of code would have to be manually changed.

So which version should I download?

Although python 2 is still used widely today, in the future it will be replaced with python 3. Many new parts of the programming language are also not included in python 2. In these tutorials, we will be learning python 3, but if there is a difference in code between the 2, I will try to include it. We will be doing our python hello world example in python 3, along with all of our other future examples in this tutorial.

Enough talk! lets download it already!

download python
Go to https://www.python.org/downloads/, and choose the newest python 3 release for your operating system. At the time of writing, it is 3.4.1, but you should download the newest release.

Time for Your First Program: Python Hello World

It is a tradition that when you first learn a programming language for your first program to be a "Hello World" program. We will do this in this python lesson as well. Find a program called "IDLE" and open it. This stands for Integrated Development Environment.

python Hello World 1
IDLE in windows 8

IDLE, also known as python shell, should display a >>>. This is where we will do our python hello world example. Type in 

print('my python hello world!')

Make sure to type it in exactly, and do not use any uppercase letters. If you typed this in correctly, python should respond back by saying:

>>>print('my python hello world!')
my python hello world!

Congratulations! You just wrote your program.


So what happened in the python hello world example?

Lets dissect this simple line of code:

print('my python hello world!')

the print part is called a function. A function in programming can be thought of like a math function: you give it data, and it outputs data. In the case of print, you gave it 'my python hello world' as data, and it printed 'my python hello world' to the screen. Notice how this line of words is in quotes and shows up in green on python shell. This is called a string. You can think of strings in python as a line of text. Strings can use double or single quotes, but I prefer the single quotes because you do not have to hit shift on your keyboard to get them. More on strings in the future. So the print function will take a string, and print it to the screen, simple enough.

Expect the python lesson 2 in the next few days. In the meantime, do not forget to share, and follow me on google plus or on twitter for updates and new blog posts. Thanks!

Saturday, July 12, 2014

5 Helpful Python Tricks

python tricks
Have you ever wondered about the various python tricks and tips out there? Python has many nifty tricks and quarks. In this article I will go over a few of them I regularly use.

1.  Testing Multiple Boolean Statements with Python's in Statement

If you have many different statements to test for, it can be easier to test them out using a list using this simple python trick. This can be done using the  in statement and putting all test subjects in a list. For example, instead of:

    if name== 'ear' or name== 'nose' or name== 'eye'

you can simplify this down by using the in statement:

   if name in ['ear', 'nose', 'eye']:

I regularly find myself using this handy python tip.

2. The For, Else Statements

Many of us know how to use the for statement, but you can also use the lesser known else clause after a for statement. The else clause will execute after the for loop is done executing, but will not execute if a break statement was issued. It will eighter execute once (if the for loop did not end with a break) or it will never execute (if the loop had a break). The else statement does not execute after every loop, it executes once the looping is complete. This is often used in "find and exit" situations. For example, instead of writing:

isFound= False
for item in iterable:
    if do_something(item):
        isFound= True
        break
if isFound:
    do_something_else()

you would simply write:

for item in iterable:
    if do_something(item):
        break
else:
    do_something_else()

if do_something() returns True, it will cause the loop to break, thus preventing do_something_else() from being executed. If it returned False throughout the whole loop, the break statement would have never been called, causing do_something_else() to run.

3.  Quick Variable Assignments

There are a wide range of ways to assign values to variables. Although this is a simple python trick, it can come in handy and is good to know. Many different ways assign values to variables include:

>>> d= 1
>>> d= s= 1
>>> d
1
>>> s
1
>>> d= 2; s= 5
>>> d, s= s, d
>>> s
2
>>> d
5
>>> f= (5, 11)
>>> s, d= f
>>> s
5
>>> d
11

Remember to have care when using the d= s= 1 assignment, as it will hold reference to the same data which will cause trouble if you hold objects, lists and other things in them. 


4. Variable Parameters to a function

Believe it or not, functions can have variable parameters. This helpful python tip means that the parameter does not have to be predefined in order for the function to work correctly. They work by storing all the parameters in a tuple which can be used to look at them in the code. Performing variable functions is very simple but handy python trick:

def foo(*args):
    for arg in args:
        print(arg)

>>>foo(5, [5, 'string'], None)
5
[5, 'string']
None

Similarly, In order to give names to the parameters, you can use a dict like so:

def foo(**kwargs):
    for key, value in kwargs.items():

        print(str(key)+ ': '+ str(value))

You will probably see *args and **kwargs used a lot in other code. Like other parameters, you can call them whatever you want; it is a convention to call them that in python. Of course, you can make a mix and match between the tuple args, the dict, and a default on in a function:

def foo(cow, skunk= 2, **kwargs):
    print('**kwargs recieved:')
    for key, value in kwargs.items():

        print(str(key)+ ': '+ str(value))
    print()
    print('cow is', cow)
    print('skunk is', skunk)

>>>foo(5, skunk= 3)
**kwargs recieved:

cow is 5
skunk is 2
>>>foo(spam= 13, foogle= 42, pig= 17)
**kwargs recieved:
foogle: 42
pig: 17

spam is 13

wombat is 2

5. Perhaps The best Python Tricks: Easter Eggs


Although not quite a python tip or trick, the easter eggs are still worth mentioning. A good amount of them exist in python. I will not show what each easter egg does; it will ruin the surprise. I . So go grab IDLE and type these in:

>>>#Are braces to be expected in the future?
>>>from __future__ import braces
(...)
>>>#Worth the read, if you know what I mean
>>>import this
(...)
>>>#python is doing a little bragging about its high level capabilities here
>>>import antigravity
(...)

And there you have it. I know I missed alot of python tricks so please do share your own python tricks and tips!
Friday, July 11, 2014

Welcome to the blog!

I am proud to announce the new blog! It will feature information about python and pygame tutorials, and struggles I had to overcome with the various games I make. Stay tuned during the next few days as I plan to start a few tutorial blog posts about python and pygame. I may change the style of the blog around during the next few days until I find a style I like. More content coming later, stay tuned!