My Xfire profile

Posts Tagged ‘programming’

Computational Art Assignment

Wednesday, June 11th, 2008

Random SpiralsI had an assignment due on Monday for KKB210: Computational Arts 1, where I had to create 3 computational art works. This has kept me pretty busy over the past week or so, especially since I had another assignment due on Tuesday, just a 1500-1800 word essay fortunately, so it didn’t take up too much time.

For full details on everything I’ve done for this assignment, have a look at my computational arts blog. I’ve learned a lot about various programming environments and languages in relation to computational arts and live-coding. In particular, I’ve found the Processing Development Environment and Quartz Composer quite interesting and fun to work with. Of course, Quartz Composer isn’t a programming environment, but a patching tool.

I have always been particularly interested in fractals and other forms of digital art, so the computational arts subjects at uni were particularly appealing to me, and thus far have been exactly what I was looking for.

I have made a few fractal animations previously, including one for my NSW Higher School Certificate that I synced up with music. On my second fractal animation, I created the music for it myself instead of using an existing piece. Using Quartz Composer and Processing, I am able to make very similar effects, though not fractals, and have them render and animate in real-time. Two of my artworks for KKB210 are actually live rendered animations based on audio input. You can have a look at them here and here. They are both available under feel free to edit them, redistribute them etc, just take note that it is an attribution, non-commercial, share-a-like license (full details are available on http://matthewbrown.net.au), so you do have say where you got it from if you are re-distributing it.

Now, while I am a novice at the whole live-rendered animations to music and the like, I am happy to do some for events where it is appropriate. Let me know at matt at stillaslife dot com.

Popularity: 48% [?]

Happenings

Friday, May 23rd, 2008

It’s been a while since I’ve written anything for this blog, the past couple of weeks have been absolutely hectic.

So what have I been up to?

  • Fixed a problematic client website that had a lot more problems than expected.
  • 20 hours worth of maintenance on another client website.
  • Created the art for my business cards and setup the files for printing.
  • Got the business cards printed (they are pretty hot, even if I do say so myself).
  • Designed a series of website prototypes for a prospective client.
  • Organised a client meeting in Lismore.
  • Wrote a draft essay for KKB101: Creative Industries - People and Practices.
  • Did my major Python assignment for ITB001: Problem Solving and Programming.
  • Learned, the basics of UML, class diagrams, interaction diagrams and class descriptions.
  • Worked on my ITB008: Modelling Analysis and Design team assignment.
  • Seen post 3am more times in a week than I have all semester.
  • Found a Pizza Hut Restaurant (ie non-take-away) near my place.

What do I have to do over the next few days?

  • Finish my part of the ITB008 team assignment by Sunday night.
  • Organise the deferral of my ITB001 exam.
  • Update the TerraMedia Web Design General Terms and Conditions by Monday.
  • Organise the appropriate documentation and presentation material for the client meeting on Tuesday.
  • Hopefully get a new client.
  • Do 10 hours worth of maintenance on a client website.
  • Get my hair cut.

What do I have to do over the next week or two?

  • Finish the final version of my KKB101 essay.
  • Design three different computational artworks for KKB210: Computational Arts 1 using anyof the design tools outlined on my other blog.
  • Display the three artworks on my computational arts blog.
  • Study for ITB001 and ITB008 exams.
  • Sort out a new computer back up system.
  • Do some more client website maintenance.
  • Finish the new TerraMedia website.
  • Other work?
  • Get the car fixed.
  • Finish the fractal gallery section of Still As Life.
  • Blog some more.
  • Anything else that comes up.

If you follow me on Twitter, you would probably be aware of many of these things, but hey.

So that’s what I’ve been up to. I have 500 or so unread items in Google Reader, so hopefully I’ll catch up on everything by the end of next week, and hopefully you’ll be hearing more from me soon.

Popularity: 38% [?]

Python Tutorial 3 - Integers and Floats

Monday, March 24th, 2008

As you saw in the final section of the previous tutorial on numeric expressions in Python, Fractions, the following two expressions give different answers:


18.0 / 7.0
# This returns 2.571485714285716

18 / 7
# This returns 2

So what’s going on here? Well, this is an example of the two main number systems in Python, integers and floats.

A float can be distinguished from an integer because it has a fractional part, even if it is just .0, such as the .0 at the end of the 18 and 7 in the above example.

If you choose to leave out the fractional portion of a set of numbers, Python will always return it as an integer, unless you force it to return it as a float which I will explain in a moment.

If you put in the fractional part, even if it is just a 0, Python will always return it as a float, unless you force it to do otherwise.

Now what happens if you use both a float and an int? Such as 18 / 7.0?

Let’s try it and find out.


18 / 7.0
# I get the same as 18.0 / 7.0
# 2.571485714285716

Why does it do this?

By using a float with an integer, Python defaults to a float for the result.

Forcing a Number Type in Python

Forcing a number to be either an integer or a float is a pretty simple task. All you have to do is add the following to your expressions:


int (18.0 / 7.0)
# This will force Python to return an integer value
# instead of the default float.

float (18 / 7)
# This will force Python to return a float value
# instead of the default integer.

If you need to determine what number type something is, this can be determined very easily with the following function:


type (18)
# This will return <type 'int'>
# In other words, 18 is an integer.

type (18.0)
# This will return <type 'float'>
# So, 18.0 is a float.

If you convert a floating point number to an integer, the fraction is lost, so if you need to use it, it is a good idea to keep your numbers in the floating point format.

Does 1 = 1.0?

You would expect 1 and 1.0 to be the same, and logically, they are, right?

While the integer 1 is numerically the same as 1.0, their value is not equal. You can test this in Python by doing the following:


1 == 1.0
# This asks Python if 1 is exactly equal to 1.0
# It returns True.

1 is 1.0
# This asks Python if 1 and 1.0 hold the same value.
# It returns False.

Floating point numbers are encoded as finite approximations in binary. This can cause some slight rounding inaccuracies to occur that are machine based.

Have a look below at some examples:


1.0 / 3.0
# Python cannot encode the infinite fraction, try it and see.

(0.1 * 3.0) / 0.1
# This should return 3.0, I do not get exactly that though.
# Try it and see what you get. It will be 3.something.

If you have any comments thus far, please let me know, the same goes if you have any corrections or input for the tutorials.

Next up I will be looking at strings in Python, so stay tuned.

Popularity: 59% [?]

Python Tutorial 2 - Numeric Expressions

Tuesday, March 18th, 2008

Python programming language logoPython’s interpreter can be used as a calculator quite easily. Of course, this is somewhat pointless since there are calculators built into most operating systems anyway. However, the numeric expressions that are built into Python become quite useful in general applications and are important to know.

Before you can start learning Python, you will need to install it.

The install is pretty straight forward, once you’ve got that done, you are ready to go.

Numeric Operators in Python

Python uses all of the normally expected operators, much the same as most other languages:

+ addition
- subtraction
* multiplication
/ division

Now, using these operators, we can type directly into the Python interpreter, IDLE, and it will return the result:


# Addition:
2 + 2
# Will return 4.

# Subtraction:
4 - 2
# Will return 2.

# Multiplication:
2 * 2
# Will return 4.

# Division:
4 / 2
# Will return 2.

Note that a # indicates a comment in Python.

If you need to take things a bit further, there are more operators commonly used in Python.

** is used to indicate to the power of, such as 8 to the power of 4, or 4 squared and so on.

Additionally, you can use brackets to override the default order that the expression will be interpreted in, the same was you would on a calculator.


# To the power of:
8 ** 4
# Will return 4096.

4 ** 2
# Will return 16.

# Using brackets to change the order:
4 * 2 + 5
# Will return 13, whereas.
4 * ( 2 + 5 )
# Will return 28.

Functions that you may find on a scientific calculator are available as either predefined functions, or need to be imported from a library.


5 + abs(-5)
# The "abs" function will return the absolute value,
# so this returns 10 rather than 0

abs(5 * -5)
# Returns 25 rather than -25.

Importing Additional Functions

Other less common operators are not loaded into Python by default, and so they have to be imported from a library of functions. This can become time consuming when you are writing directly into IDLE. If you open up a blank Python window (File > New Window), you will be able to type as many lines of code as necessary before sending it to IDLE. If you are writing expressions such as the ones above into a separate window, you will need to add a print command before hand, otherwise Python will just evaluate them and not display them, for example:


print 4 - 2
# Should be used so that IDLE will print the result,
# otherwise it will just interpret it without printing it.

To load less common operators, such as the square root operator, you have to load Pythons math library. If you just a single function, such as square root, this can be done as follows:


from math import sqrt

# The square root can then be found with this command:
sqrt(25)
# This will return 5.0.

If you need to use multiple, less common functions it may be easier to load the entire mathematics library.


import math
# This tells IDLE to load the mathematics library.

Once the library has been loaded there are quite a few more functions available, similar to those used in C.


math.ceil(2.2)
# The ceiling function will round the decimal up.

math.floor(2.2)
# The floor funtion will round the decimal down.

math.pi
# The constant, pi (3.1415926535897931).

math.pi*2
# Multiplies pi by 2.

pow(4, 2)
# The power function works similarly to the ** function.

# pow(4, 2) returns the same answer as 4 ** 2.

There are many more available including angular, hyperbolic, trigonometric, powers and other mathematic functions. A full list is available in the Python documentation.

Fractions

So far, we have mostly seen whole numbers as a result to our answers, why do you think this is? What happens if you tell IDLE to interpret the following expressions?


2.3 + 5.9
18.0 / 7.0
18 / 7

The answers and explanations in the next Python tutorial, Integers and Floats.

Thanks for reading, if you have any questions or comments, feel free to let me know below.

Popularity: 69% [?]

Python Tutorial 1 - Getting Python

Friday, March 14th, 2008

Python programming language logoPython object-oriented programming language at uni in ITB001: Problem Solving and Programming, I figure what better way to solidify what I am learning than to write about it. Someone might find it useful as well.

So if you see anything that is wrong, or anything like that, feel free to point it out, I won’t bite.

First up, you have to get Python, this is pretty straightforward, but I may as well make it the first of my tutorials since it is necessary.

If you use OS X, it comes with it, as do some Linux distributions, though it may be outdated. Grab the latest version for OS X, or Unix based operating systems, or Python for Windows from the Python website.

The install is pretty straight forward and should have you up and running in no time, just follow the instructions, all of the defaults should be fine.

After it is installed, when you run the Python Shell (IDLE), it should bring up a window called IDLE. This is Python’s interpreter window, so anything you run will be evaluated here. You can type directly into IDLE, however it is limited to writing a line at a time which is slow and painful and cannot be saved. It is really only effective for checking a line of code here and there.

If you go to File > New Window, it will open up a blank window. These windows can be saved as .py files and are where you will write the majority of code. You can write as many lines as you want in these and then have Python evaluate them whenever you are ready.

If you want to get straight into Python, the best documentation I have seen personally, and also as recommended by my lecturer, is the documentation material available on the Python website.

I will be going through Python in the same sequence as I have been going through it at uni. So stay tuned and the next tutorial will be up soon.

If you want to leave any thoughts or input, it would be greatly appreciated.

Go on to the next tutorial, Numeric Expressions In Python.

Popularity: 26% [?]

Still As Life is proudly powered by WordPress
Entries (RSS) and Comments (RSS).