Tag Archives: graphics

Scaling an image in Objective-C (Cocoa Framework)

The UIImage class can be used to represent an image. The following snippet scales an image according to a size which is provided with a CGSize parameter. + (UIImage *)scale:(UIImage *)image toSize:(CGSize)size { UIGraphicsBeginImageContext(size); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; }

Posted in Objective-C | Also tagged , , , , , , , , , , | Leave a comment

(ActionScript) AS2 Draw Circle

I recently has to work on an AS2 project (yuk) and create circles dynamically. Here is a handy function for this.

Posted in ActionScript | Also tagged , , , , , , , , , | Leave a comment

(PHP) GD Thumbnail Generator

Tweaked from the icant.co.uk thumbnail generator

Posted in PHP | Also tagged , , , , , , , , | 1 Comment

Detecting keyboard input in XNA

Keyboard input is essential in most games. The user might use it for moving a character, mario style enemy killing and many other things. XNA supports so called keyboard states to detect keyboard input.

Posted in C# | Also tagged , , , , , , , , , | Leave a comment

Double buffering with a back buffer in VC++

A common problem when drawing with GDI in VC++ is that the screen might flicker when you’re doing a lot of drawing. This problem can be overcome by drawing on a so called back buffer. The back buffer is then drawn at once. I’ve created a Win32 project in VC++ to demonstrate this. The first [...]

Posted in C++ | Also tagged , , , , , , , , , , , | Leave a comment

Distance between 2D and 3D vectors in C++

This example extends the Vector2 and Vector3 classes from theĀ 2D and 3D vector normalization and angle calculation in C++ example. The formulas for distance calculation in 2D and 3D are listed below.

Posted in C++ | Also tagged , , , , , , , | Leave a comment

Drawing circles with JavaScript and HTML5 Canvas

The HTML5 specification includes the canvas element for drawing graphics with JavaScript. This example demonstrates the use of the canvas element and JavaScript for drawing circles.

Posted in JavaScript | Also tagged , , , , , , , , , , , | 3 Comments

Generating a random color in C#

Always wanted to have your own random color generator in C#? This snippet shows you how to do it.

Posted in C# | Also tagged , , , , , , , , | 1 Comment