Category Archives: Python

A raytracer in python – part 3: samplers

In the previous post, we explored a very basic way of plotting images: shooting a ray from the center of every pixel, and plot the color of the object we hit. The result is a rather flat, very jagged image Border jagging arises from the fact that we are sampling with a discrete grid (our [...]

A raytracer in python – part 2: rendering multiple objects

A quick addition needed to the raytracer is providing freedom to add more objects to the rendering scene. In Part 1, the design was such that only one object, a sphere, could be drawn. The new code allows much more flexibility. I added a Plane object, introduced assignment of colors to the objects, divided the [...]

A raytracer in python – part 1: basic functionality

Some time ago I visited Sydney, and I made a tragic mistake: I entered the University bookshop. Why a mistake, you say? I am book maniac. As soon as I enter a book shop (live or on web) I end up spending up to a thousands euro every time. This time, it was not the [...]

The Mandelbrot set, in python

Hello StumbleUpon users. I am writing two additional posts on the Mandelbrot set, and you may be interested in them. The first one is here. The second one is here. Thank you for your interest! This code is so fascinating from PIL import Image max_iteration = 1000 x_center = -1.0 y_center =  0.0 size = [...]

Using contexts in rdflib

I am playing with rdflib, a fantastic python library to handle RDF data. I had trouble understanding how to use contexts so to partition my ConjunctiveGraph into independent subgraphs. Here is the code import rdflib from rdflib.Graph import Graph conj=rdflib.ConjunctiveGraph() NS=rdflib.Namespace(“http://example.com/#”) NS_CTX=rdflib.Namespace(“http://example.com/context/#”) alice=NS.alice bob=NS.bob charlie=NS.charlie pizza=NS.pizza meat=NS.meat chocolate=NS.chocolate loves=NS.loves hates=NS.hates likes=NS.likes dislikes=NS.dislikes love_ctx=Graph(conj.store, NS_CTX.love) food_ctx=Graph(conj.store, [...]

Can’t grok grok. Back to Django.

I wanted to use Grok for my future development, so I just spent a week trying to do porting of a project from Django to Grok. I had to back off. Grok is very powerful without doubt. However, the learning curve is steep, and I am not talking about “mountain trekking” steep, I’m talking about [...]

Pythonic Evolution – Part 3

You are welcome to take a look at Part 1 and Part2 of this series. In this third part of the “silicon-based” bacterial evolution, we move to the real action. I developed a program (you can download it from here), which perform evolutive selection based on mathematical criteria.  The program has a set of rules [...]

Pythonic Evolution – Part 2

This is the second part of a post relative to evolution. You can find the first part of the post here. The last argument in the first post was relative to the requirements for evolution to happen. To recall, you need An imperfect replicator, an entity able to produce a copy of itself, for example [...]

Pythonic Evolution – Part 1

This post is in different parts. The fact is that it requires quite a lot of time investment, something I really don’t have in this period. A long time ago I wanted to play with the concept of genetic code, and how it represents nothing but a language to code for molecular machines. As the [...]

What’s the point of inheritance in python ?

Python is a fascinating language. It makes you think. Sometimes it can destroy your beliefs. My background is in statically typed languages. I came from C++, camped there for a while, then moved to python. I also explored Java recently. I would like to present my case by remembering the three pillars of object oriented [...]