dimitris kalamaras

math, social network analysis, web dev, free software…

Tag: C++

Create complex visual elements with Processing language

I was having a kind of …insomnia attack last Friday night, so I decided to search the openSUSE repositories for interesting applications. I was using openSUSE (11.1) at the moment, with lots of additional repos [1] from the excellent Build Service, so there were a lot of things there to explore. One thing led to another, and soon I ended up downloading Processing. What is this? The package description looked interesting:

Processing is an open source programming language and
environment for people who want to program images, animation,
and interactions. It is used by students, artists, designers,
researchers, and hobbyists for learning, prototyping, and production.
It is created to teach fundamentals of computer programming
within a visual context and to serve as a software sketchbook
and professional production tool. Processing is an alternative
to proprietary software tools in the same domain

I thought “ok, this is promising, let’s have a closer look at it”, and waited a couple minutes for all 85MB of packages to be downloaded and installed from the Education repository (no Ubuntu packages yet, but you can just download a tarball with linux binaries). Then I started the application with the command:

Read More

Qt (Μέρος IIΙ): Αρχειοθέτης άρθρων

Στο προηγούμενο tutorial φτιάξαμε μια γραφική εφαρμογή, το BookAdmin, για να διαχειρίζεστε τη συλλογή των βιβλίων σας χρησιμοποιώντας μια βάση δεδομένων MySQL. Δεν ήταν κάτι ιδιαίτερο, βέβαια, και η αλήθεια είναι ότι θα έπρεπε ίσως να συνεχίζαμε την ανάπτυξή της (βάζοντας π.χ. φίλτρα για τις εγγραφές). Ωστόσο, πολλοί αναγνώστες του “LF” μας ζήτησαν με ευγενικό τρόπο (μας δωροδόκησαν καλά!) να τους δώσουμε έναν τρόπο αρχειοθέτησης των άρθρων του περιοδικού για όλα τα μέχρι σήμερα τεύχη. Οπότε σκεφτήκαμε: “τι καλύτερο από το να γράψουμε ένα μικρό tutorial γι’ αυτό βασιζόμενοι σε ότι κάναμε στο BookAdmin;” Έτσι, αυτή τη φορά, θα φτιάξουμε μια τέτοια εφαρμογούλα για να τηρείτε το “αρχείο” σας, αλλά και για να δείτε πως φτιάχνεται κάτι τέτοιο στην πράξη. Τέτοιο …making of ούτε στο Holywood δεν θα βρείτε! 😛 Σημείωση: μπορείτε να κατεβάσετε όλον τον κώδικα του άρθρου από εδώ.

Το σχέδιο έχει ως εξής. Η εφαρμογή, ας την βαφτίσουμε ArtAdmin, θα πρέπει να έχει ένα γραφικό περιβάλλον αντίστοιχο του BookAdmin, δηλαδή με πεδία για προβολή και αναζήτηση κάποιων εγγραφών (δηλαδή άρθρων) και ένα TableView σε ξεχωριστή καρτέλα για να βλέπετε όλα τα άρθρα μαζί. Συνεχίζοντας με αυταπάρνηση την παράδοση που θέλει κάθε προγραμματιστή …τεμπέλη, θα βασιστούμε στη φόρμα του BookAdmin αλλάζοντας ελαφρώς την πρώτη καρτέλα της για να φτιάξουμε το ολοκαίνουριο ArticlesAdmin – φασόν δηλαδή 🙂 Αυτή τη φορά, όμως θα προσθέσουμε και μερικά νέα κόλπα…

Read More

Qt (Μέρος IΙ): Βάσεις δεδομένων

Σε αυτό το tutorial, στόχος μας είναι να φτιάξουμε μια εφαρμογή που να αλληλεπιδρά με τη MySQL. Η Qt υποστηρίζει αρκετές βάσεις δεδομένων (MySQL, PostgreSQL, SQLite), αλλά εδώ θα περιοριστούμε στην MySQL.

Στο παράδειγμα που θα δούμε παρακάτω, θα φτιάξουμε2008/08/02/qt-μέρος-ι-convertor/#content μια εφαρμογή διαχείρισης βιβλίων, το bookAdmin. Η υλοποίηση του όμως θα είναι αρκετά γενική ώστε να μπορείτε να το προσαρμόσετε εύκολα στις δικές σας ανάγκες. Με μερικές αλλαγές στο περιβάλλον της εφαρμογής θα μπορείτε, αντί για βιβλία, να διαχειρίζεστε CDs, ταινίες, γραμματόσημα, οτιδήποτε. Θυμίζω ότι βασιζόμαστε στην Qt 4.2+ οπότε, ανάλογα με τη διανομή σας, θα πρέπει να έχετε ήδη εγκαταστήσει τα πακέτα ανάπτυξης της Qt4 (δείτε το πρώτο tutorial). Επιπλέον, επειδή θα δουλέψουμε με βάσεις δεδομένων, θα πρέπει να εγκαταστήσετε και το πακέτο libqt4-sql στο Debian/Ubuntu (ή το qt4-database-plugin-mysql-lib στο PCLinuxOS). Κατά τ’ άλλα, θα αρκεστούμε και πάλι στo Qt Designer και σε ένα κειμενογράφο.

Δημιουργία GUI

Αρχικά θα φτιάξουμε το GUI του bookAdmin. Τρέξτε λοιπόν το QtDesigner. Στην ερώτηση για το είδος της φόρμας, επιλέξτε “Main Window” μια και αυτή τη φορά θέλουμε να φτιάξουμε μια κανονική εφαρμογή. Στο προηγούμενο τεύχος είχαμε προτιμήσει το Widget, μια και τότε θέλαμε μόνο ένα λιτό διάλογο με μερικά μόνο πεδία για την εισαγωγή και προβολή των μονάδων. Το bookAdmin όμως θα είναι πολύ πιο περίπλοκη εφαρμογή, γι’ αυτό προτιμάμε το MainWindow.

Read More

LIFO (2001)

The goal of this project was to create a class (named lifo) of Last-In-First-Out Lists (Stacks) of integers with variable length. The class actually defines a new Data Type, named lifo. Each variable of this type will be a LIFO List. Of course, the class must have defined some operations (member-functions) for handling the lists, ie PUSH an integer to a stack, POP an integer from the stack, PRINT a list, COPY one list to another, COMPARE two lists, CONCATENATE two lists, SEARCH a list for an element etc.
The program is quite simple. It creates an “array” a of 100 elements of type lifo. Thus, it creates 100 LIFO lists and displayes a simple menu as user interface with the above actions.

It was written in Borland C++ v.5 but I think you can compile and run it in any compiler due of its simplicity. It only requires the iostream.h for cout and cin.

Read More

Integral in C (1997)

This program uses the basis of the Archimedes (287-212 BC) method, known as exhaustion, to approximate the integral of a given real function in a given space [a,b]. First it segments the given space into N subspaces. It calculates: a) the sum of the areas of orthogonal parallelograms of height equal to the minimum of the function in each segment and b) the sum of the areas of orthog. parallelograms of height equal to the max value of f(x) in each segment. Theoretically, when N right infty, the progressions are both converging to the same limit which is the integral of the function.

The program is simple. It requires the segmentation number N and the integration limits a,b. You can easily change the function to your desired one in the function at the end of the code. As you may see, after the calculations, it tries to graph the function. Well don’t expect much, although it has very good output in some functions like the f(x)=xsinx.

The program was written in Borland C++ 5.0. You will need the compiler bcc in order to compile and run it, but it’s very easy to make some alterations for other compilers or other OS’s.

Read More

Powered by WordPress & Theme by Anders Norén