Pages

Friday, May 17, 2013

My first Python game HOORAY!!


PONG


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:

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

p = position
v = vector
t = time

Python:
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:

Python:
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

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


Anyways was awesome fun :D/


Sunday, May 12, 2013

Collatz Conjecture In Python and ICE...




Statement:
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...

Tuesday, April 9, 2013

Sector/Segment Area





 There are two main "slices" of a circle:
     The "pizza" slice is called a Sector*white selection below*


Sector
*Click to make bigger*
              

                   And the slice made by a chord is called a Segment. *white selection below*


Segment
*Click to make bigger*
             


Lets take a look at this in Softimage....

 
* Watch in highest quility possible*


To work out the area of the segment and sector you will use the formulas:

Area of Sector = ½ × (θ × π/180) × r2   (when θ is in degrees)

Area of Segment = ½ × ( (θ × π/180) - sin θ) × r2   (when θ is in degrees)

*So basically what we need is the angle of the "center" corner, and the radius of the circle the sector belongs too*

Area of a Sector in Softimage
*Click to make bigger*

What these formulas will look like in ICE - once you have the angle and raduis - :

Segment area:

*Click to make bigger*

Sector area:

*Click to make bigger*


So you will need to work out the lengths of the three sides of the triangle that fits inside the sector "pizza slice".
I did this by simple creating cluster centers on the last point of the three curves then getting the length between them....


*Click to make bigger*

Here are the tree's for that...

*Click to make bigger*
 they are all basically the same...

*Click to make bigger*


*Click to make bigger*


....then you can work out the angle of the center corner in the circle your sector is part of.
I used the standard law of cosines node for this one but here is the math formula:
cos A = (b2 + c2 - a2)/2bc


I used this law because I already had all three side lengths worked out, but never fear here is a link to other ways of working out you triangles if you have say one angle and two sides... 

*Click to make bigger*


law of cosines in Softimage
*Click to make bigger*


You can also work out the "arc length" - the blue line in the image below - of your sector, by using the formula:

L = (θ × π/180) × r  


*Click to make bigger*

Here's that ICE tree...

arc Length formula
*Click to make bigger*

And there you have it. If you ever need to work out how big a pizza slice is ..... now you can do it :)

End 

Monday, April 8, 2013

Lindy Hop



The animation project I'm buzy with at the moment involves some really cool dancing reference.



So started animating out this awesome dance routine for a learning challenge.
*the characters are made by AnimSchool - you can download them here: http://www.animschool.com/DownloadOffer.aspx *




This is the Blocking for the first 210 frames ...... he he loving it so far.

For now the only issue has been gimble lock.... but with them turning around so much and stuff, its to be expected. 

Tuesday, March 26, 2013

Even more fractal fun....



"THEY NEVER END!" *runs around in a circle like her hairs on fire*



Line replacement Fractals


Def : Draw a fractal based on iterated line replacement



Koch curve and snowflake








Levy Tapestry




Cross-stitch Curve



Cresaro Fractal



Minkowski Sausage
*Doesn't look anything like a sausage*



Space-filling Curves




some variations on the Peano curve I made before.....





3D Fractals


Just some random 3D fractals I've been playing with.





End

Tuesday, March 12, 2013

some more Fractals.....



Just some more fractal fun I've been having...


Mcworters Pentadentrite



Heighway Dragon Curve



Sierpinski's n-gon



Durers Pantagon




Peano Curve

This is my first space filling curve fractal... made pretty much in the same way as the Sierpinski ones.



Peano Curve Fractal





Will be adding more post on fractals soon ;)

Friday, March 1, 2013

Sierpinski and self-similar sets...




Walclaw Sierpinski



Wacław Franciszek Sierpiński was a polish Math-magician - aka Grand Master of set theory, Senior Warlock of number theory, dude who liked fractals - and school teacher.

He is best know for "Sierpinski's triangle" (in 3D its called Sierpiński tetrahedron)

Sierpinski's triangle

 his carpet - also related to Sierpiński Sponge or Menger's Sponge when in 3D.

Sierpinski's carpet

his arrowhead curve

Sierpinski arrowhead curve

 
and his pentagon O_O

Sierpinski's pentagon

*He also got to be on a coin, which is pretty cool.*


These beauties are known as iterated function systems or IFS, and we will be looking at how we can build some self-similar fractals using Softimage ICE in this post.
**All these IFS have fixed Attractors.**

Some fractal Terminology...

Iterated Function System:

A finite set of contraction maps w_i for i=1, 2, ..., N, each with a contractivity factor s<1, which map a compact metric space onto itself. It is the basis for fractal image compression techniques. 

Self-similarity:

An object is said to be self-similar if it looks "roughly" the same on any scale.

Attractor:

Each consists of affine transformations involving rotations, translation and scaling by a constant ratio, where applicable. It can also be divined as the smallest unit which itself cannot be decomposed into two or more attractors.

 L-Systems:

A Lindenmayer system, also known as an L-system, is a string writing system that can be used to generate fractals with dimensions between 1 and 2.




Sierpinski's triangle


To create this fractal you need the following things:
1. repeat on counter node
2. clone point node
3. basic kind of loop
*Just a note, this is a really render and ram intensive way of doing any fractal, but it is cool if you just want to get your head around the math of L-Systems*


In Image A you will see that I have two parts to my setup.  Part one is adding a single point to a pointcloud, and part two which I call the I.F.S is where that point gets cloned and repeated for the fractal.  This is the basic setup for all four of Sierpinski's fractals shown above.


Image A
Sierpinski's Triangle in Softimage/ICE
*click on image to make bigger*


To start add a single point to an empty pointcloud at the origin. As shown in Image B.  Make that point into a cone or create your own triangle and use that as an instance shape.  The scale of the triangle/cone 10, 10, 10. *Its easier to see the small iterations when the first triangle is nice and big*
Image B - Attractor NODE
Attractor Node in softimage
*click on image to make bigger*



After that you will need to setup the tree shown in Image C.  Here is where it gets interesting, to build the ICE tree shown in Image C you will have to build all the trees in images C1, D and E.
 In the cast of Sierpinski's triangle, the first Iteration on the Repeat with counter node will produce 3 clones of the original triangle - you want to turn on the delete source if cloned option - and then 9 triangles by the second iteration and so on.
Image C - IFS_Triangle NODE
IFS Node Softimage/ICE
*click on image to make bigger*

What the Log node - Image D - does is translate the new triangles so that they fit inside the original triangle.  We do this with the help of the point ID's and a select case node, run by a loop.


Image D - log 3 NODE
LOG node Softimage/ICE
*click on image to make bigger*
The translate local point - Image C1 -  node makes sure that the previous point position gets calculated as well as the new point position.
*I got this useful little node from doing Chris Marshall's tutorial on a tree.*



Image C1 - Translate local points NODE
Translate local point Softimage/ICE
*click on image to make bigger*



In Image E we subtract the Point ID by one so that it starts with zero as a value just like the select case node.  Then we feed it through the modulo node to be modulated by the number 3 - number of clones in IFS.
Math behind the log node 



Image E - Loop Value Fractals NODE
loop Softimage ICE
*click on image to make bigger*

In Image F you can see the ram usage and render time if your on an Iteration step of 12 with 531 441 triangles in your scene.  I'm totally looking into ways of speeding this up.  My poor laptop can't really handle this much ram going to a render.




Image F
sierpinski's triangle ram
*click on image to make bigger*


Sierpinski's Triangle


Sierpinski's Tetrahedron


Sierpinski's Carpet
  


Once you've mastered the Triangle feel free to try and make his carpet as well.  Image AA and AB shows the log and scale for that. Start with a Box with a scale of 10 and then fit 8 new boxes to the side facing the X translation.

 Image AA
Log sierpinski's carpet softimage ICE
*click on image to make bigger*


Note the difference in the scale being 0.667 instead of 0.5 like with the triangle
 Image AB
IFS Sierpinski's Carpet Softimage ICE
*click on image to make bigger*


This one is even worse on the ram side but really nice looking.


Image AC
Sierpinski's Carpet RAM in Softimage
*click on image to make bigger*




Sierpinski's Carpet




Sierpinski's Sponge

















Sierpinski's Arrowhead


The arrowhead is really interesting because you don't just work with the center point position like you did with the triangle and the carpet, you now work with the starting point 0, 0 - the root of the cylinder - and the end position 0, 1 - the tip of the cylinder, like with the triangle you will have a Log of 3 here, but now you also have to deal with the orientation of the cylinders.

Start with a single cylinder that is rotated to lay horizontally with a scale of  5, 10, 1.  Now just build Image BA and BB into the IFS node.


Image BA
Log Sierpinski's arrowhead Softimage ICE
*click on image to make bigger*

The scale for this one is also 0.5 just like the triangle.



Image BB
Sierpinski's arrowhead Scale in Softimage ICE
*click on image to make bigger*


This one becomes really heavy after 12 iterations couldn't even render it...


Image BC
Sierpinski's arrowhead RAM in ICE Softimage
*click on image to make bigger*


Sierpinski's Arrowhead





Sierpinski's Pentagon


To make the beautiful pentagon you will need to make a pentagon and the use the instance shape node to add it to your point in your pointcloud.  This one is a weird one... It has a log with 5 clones and a scale of 0.618 but it also has an offset of sorts.

Image CA
IFS Sierpinski's Pentagon Softimage ICE
*click on image to make bigger*

The offset comes in with the 5 sides of the pentagon being in strange places : / See Image CB for the strangeness.

Image CB
Log Sierpinski's Pentagon Softimage ICE
*click on image to make bigger*

All of them seem to come in at around 2 to 4 min a frame with anything from 600mb to 1700mb of ram usage.

Image CC
Sierpinski's Pentagon RAM in softimage ICE
*click on image to make bigger*


Sierpinski's Pentagon




End :D