Friday, May 17, 2013

My first Python game HOORAY!!


Below is a video of me playing against myself -lol- I suck at playing pong....

Loved making my first little game in python, though. 
Most fun part was creating the simple reflection and collision we needed for the ball. I use some vector math and an if statement. There was also the fact that the paddles cant go off screen, and they needed to only move when you hit the correct keys on the keyboard.

The math looked something like this.....

For movement:

p(t+1) = p(t) +(1)(v(t))

p = position
v = vector
t = time

New pos      Init pos
p[0] =     p[0] + v[0] 
p[1] =     p[1] + v[1]

 ball_pos[0] += vel[0]
 ball_pos[1] += vel[1]

*add a negative value on the horizontal vector to make the reflection off of paddle.*

ball_pos[0] += vel[0]
 ball_pos[1] -= vel[1]

and then to get distance between two points:

dist(p, q)                            
return math.sqrt((p[0]-q[0])**2+(p[1]-q[1])**2)

then you pretty much just say if point 0 is in the same range as point 1, point 0 either reflect off of the pad or hits the wall.

With the paddles:

To move paddles:

 I used a local acceleration variable when the player hits a key(up or down)

To keep paddle on screen:

I made an if statement that stopped the paddle from going beyond its own height off screen

if paddle1_pos[0] + paddle1_vel[0] <= PAD_HEIGHT

Anyways was awesome fun :D/

Sunday, May 12, 2013

Collatz Conjecture In Python and ICE...

Consider the following operation on an arbitrary positive integer:
If the number is even, divide it by two.
If the number is odd, triple it and add one.
In modular arithmetic notation, define the function f as follows:

if statement for colletz conjection

Collatz in Python:

To make this collatz conjecture I used a simple if statement, see code below... 

Python Collatz conjecture program
*click to make bigger*

Here is a video of how that all works with a gui:

Collatz in ICE:

In ICE I used the same idea as I used in python. Then just added a repeat node to get an updated n number.

Collatz Conjecture in Softimage/ICE
*click to make bigger*

What that looks like:

End :D

P.S :

Monday, May 6, 2013

Convert miles to feet....

To convert miles to feet you need to know how many feet there is in a mile. Google says....

*I'll take their word for that*

In python to convert would look something like this:

Convert miles to feet in python
*click to make better*

So how could we do this in Softimage and ICE?

String in Softimage
*click to make bigger*

My first attempt gets the right answer for the conversion,  but I would like it to say "...miles equals how ever much feet" like in the example in python so not very happy yet. 
It seems that the string nodes wont be of much help either, as they don't convert floats to string like in python.

Will have to look at a different way around this problem. :/

too be continued...