4,305 Posted Topics
Years ago I wrote a little screen-saver in Delphi that randomly put colorful circles all over the screen. A hit with the secretaries in the office. I modified a simple Tkinter based snippet to put the same colorful circles all over a window form at random locations, random radii and … | |
| |
VPython's fame is with 3D animated modeling, but it's plotting abilities, while not flashy, are easy to understand and very useful. This program uses VPython to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x). | |
This question came up on the forum. How do you swap two numbers without using a temporary variable? I used all the power of my brain to solve this at four o'clock in the morning. In all fairness, swapping two numbers using a temporay variable is about five times faster. … | |
Python has a module specifically made for timing built-in or owner coded functions. This code snippet explains how to use this feature. | |
The psyco module has been around for a while and has been used to speed up the Python interpreter. For those of you who think speed is all important, take a look at a typical example. Psyco is similar to Java's just in time compiler. How does psyco do it? … | |
Python24 introduces the function decorator that lends itself nicely to the timing of a function. As a sample function we are using the ever popular and rather stodgy prime number generator. The prime number generator seems to exist only to fluster students and to make niggling comparisons of the speed … | |
The Python module zlib allows you to compress a typical text string to about one half its original size. A handy feature when you have to transmit or save a large amount of text or data. It saves you time both writing and later reading back the compressed file. The … | |
Python uses C syntax to perform bitwise operations. Take a look at code that introduces you to bitwise operations at the binary level. | |
If you have a Windows computer you can play musical beeps through the internal speaker. In this case it will sound like a very tiny Big Ben, brought to you by the module winsound and its method Beep(). | |
Did you ever want to know how how many square inches are in a square meter? This short Python code allows you to get the answer. It uses a dictionary to simplify the conversions. Could be the start of a nice GUI program using radio buttons. | |
The Python list container can be used for many practical things. In this somewhat light-hearted introspection of modern day politics we are looking at two lists and attempt to clear out elements that shouldn't be in both lists. No offense to anyone is intended, the outcome with the sets was … | |
A while ago I created a code snippet in C for the same question. Solving this question with Python is a lot simpler, and on top of that Python takes care of impossible dates with the appropriate error message. | |
A simple experiment with the ever so popular Mandelbrot fractal graphics, call it mathematical art, nice to look at. This set of experiments loops through a number of colors to make the whole thing more exciting. | |
Jumping through a few extra hoops allows you to display the common image format jpeg on a panel of the wxPython GUI window. All you need to do is to read in the image file as a binary, convert to a byte stream image and then to a bitmap. Now … | |
The other day I was looking at my family tree. There are my parents Antonio and Lucy Vegaseat, then my grandparents Alfonso and Ludmilla Vegaseat on my father's side and Roland and Helga Gruenspan on my mother's side. Then come my great grandparents, by now there are eight of those. … | |
While the calculation of the total resistance of two resistors in parallel is simple, this code shows you how to trap a number of potential errors that come with the entry of the required data. All is wrapped easily into a colorful GUI program, due to the simplicity of the … | |
The wxNotebook method from the wxPython module allows you to show a lot of data in a limited window space. It brings up tabbed pages you can click on to open each page. Enough said, run the code and experience the possibilities this humble method gives you. | |
This is another GUI program using the Tkinter module. It shows you how to change the background and foreground color of a component/widget. In this case it is a button. The button itself is used to toggle the color selection via a color dialog box. Enough comments have been added … | |
Re: Don't feel too bad. I don't think the DaniWeb code-field handles foreign characters. I had trouble with spanish characters too, and they are simple ASCII. Interesting project though! | |
I was looking for a somewhat meaningful and interesting example to explain the Python class to beginners. A room full of multilingual students makes this phrase translator a good choice. You can experiment with it and add more languages and phrases. | |
Python's Tkinter module can be used to create a Graphics User Interface (GUI). This sample code creates a windows type form and positions a label and a canvas on the form. A simple shape is drawn on the canvas. | |
A common way to represent an inventory is with a list of tuples. Each tuple represents the item name and the item count. You can sort this inventory list by item name or item count. Here is an example to pick a sort key. It's your summer job to run … | |
Where you ever curious what the most common letter is in a typical text file? Just another question to ask a friend. The answer is right here in this tiny code snippet. The program converts the text to all lower case letters, and then list them out alphabetically showing the … | |
The module datetime allows you to call several functions that can do computation with dates and times. How many days since my birth? How many days till Xmas? What's the date 77 days from now? The code snippet should give you a flavor, enough to explore on your own. | |
Many of the code samples on the internet are written in Turbo C. The clrscr() function litters these samples, and even to this day people want to wipe your screen. You can use system("CLS"), but that uses a DOS command. DOS commands are with us only at the whim of … | |
Quick and dirty way to change your console program colors using DOS command "Color BackgroundForeground" where Background is hex 0 = black to F = white, dito for Foreground. | |
The wxPython library allows Python to create Windows GUI programs. Here is a look at the listbox component. Click a button to load the listbox with names, select the name by clicking on it on the list, and display it in the title bar of the window frame. Another button … | |
This program uses WinApi function SetPixel() to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x) along a y-axis centered on the console screen. Make sure that gdi32.lib is included in the libraries to be linked. | |
Just a simple way to separate the words contained in a sentence. As an option you can store the words in a vector. If you are not familiar with a vector, use an array instead. | |
I look at BCX-basic as a modernized qbasic. This simple code creates a Windows GUI program that plays a midi instrumental music file. To keep it simple, the file it looks for is "TheRose.mid" file. If you don't have this file, you have the option of editing the code, or … | |
Shows how to connect a button onclick event to a javascript function to change the background color of the document. Just cut and paste the code into Notepad or other editor, save as BGchanger.htm and run it on your browser. | |
Remember the Spirograph? It used geared circles to create some rather artistic geometric designs. This program uses triangles to follow in the Spirograph's foot steps. The math is rather simple, just a couple of sine and cosine functions, also the ubiquitous for loops, everything wrapped up in the using() statement. … | |
The set is an unordered collection of unique hashable elements. All the elements/items in a set are treated as keys. There are several functions that compare two sets. Right now, I will just give you a taste ... | |
The code shows you how to create a window without a titlebar that can be dragged with the mouse. Set the FormStyle property to fsStayOnTop. The form contains a small 18 button calculator. When you create the form and calculator components, try to make it tiny, it is cute that … | |
Using wxPython and the Boa Constructor, a VB/Delphi like IDE and Visual Builder, this little calculator was a breeze to make. Boa did 90% of the code generation, and I simply added code to each button click event to make the calculations work. I wish every project would go that … | |
The Simple DirectMedia Layer (SDL) library allows for manageable multimedia programming in console mode. Now you can mix graphics, animated or otherwise, with sound and make your game project more interesting. I am showing an example for Dev-C++ using math generated graphics, purloined from the NET, and give some instructions … | |
Re: Nice idea! We have a little thread going on DaniWeb under: [url]http://www.daniweb.com/techtalkforums/thread18331.html[/url] Would be nice to get the asm Hello World! from you. | |
Re: Tight_Coder_Ex nice to see the Grandfather of it all appear!! Thanks! | |
Many moons ago I wrote a Delphi program that could tell the exact character in a ListBox, as you clicked on it with a mouse. I found a little info on the NET that lets you get at least the item in a ListBox using C#. I made it work … | |
You can look at a selected file's date and time stamp and change it with this Delphi program. XP files need a little extra TLC, but it's taken care of too. | |
Swap two images as you move your mouse in and out of the image field. Uses onMouseOver, onMouseOut and a short javascript code. | |
A data stream is used to load a bitmap image and convert it to a jpeg image. The converted image is displayed and saved to a .jpg file. | |
The WinBGI package allows you to do some of the Borland BGI graphics in a specially created window form. So don't throw out the old Borland manuals, you can still use them to do some fancy graphing! Yes, you can gotoxy() again! This code was modified for Dev-C++, a real … | |
An example how to line up your decimal points in a column like output of floating point numbers. Both C and C++ versions are shown. Thanks are given to Bud Tugly, my 77 year old senior student. | |
Another application of the Python Image Library (PIL). This time we are loading an image and rotate it counterclockwise by a specified number of degrees. The image is shown rotated and then saved to the working folder. PIL handles a fair amount of image file formats easily. | |
Shows a basic way to create a form with a wallpaper image on it. Also shows how to add a transparent label to blend in with the wallpaper. Getting the label to be transparent wasn't all that commodious! The wallpaper is generated using a texture brush and bitmap image. The … |
The End.