views:

117

answers:

5

My mac laptop has 1,024,000 pixels. What's the simplest way to turn my display completely black and go nuts with writing little programs to twiddle pixels to my heart's delight?

To make it more concrete, say I wanted to implement the Chaos Game to draw a Sierpinski triangle, at the pixel level, with nothing else on the screen. What are ways to do that?

+3  A: 

Perhaps pick Processing

High Performance Mark
+2  A: 

Create Quartz in your Captured Console

kubi
I should Cocoa.
High Performance Mark
+2  A: 

Surely a Screen Saver would be a Serendipitous Solution ?

One approach would be to download sample code for a screen saver module and then then use that as a template for your own screen saver. That way you don't have to write much beyond the actual drawing code, and you get your own custom screen saver module to boot.

Paul R
There's a screen saver template in XCode that takes care of the basics -- just add drawing in `animateOneFrame`. Screen savers are kind of a pain to debug, though, because they run as loaded modules in another application's space. And pixel-level drawing in Cocoa also takes a bit of mucking around.
walkytalky
Smart suggestion!
dreeves
It may be easier to to make a normal application that runs full-screen (like many games). That way you can debug easily and even add interactivity if you want.
George Steel
+1  A: 

I you're using C or C++ you can do this stuff with SDL. It allows low level access to the pixels of a single window or the full screen (plus the keyboard, mouse, and soundcard) and works on most Windows, OSX, and Linux.

There are some excellent tutorials on how to use this library at http://lazyfoo.net/SDL_tutorials/index.php. I think you want tutorial #31 after the first few.

George Steel
+1  A: 

A good way to go is GLUT, the (slightly) friendly multiplatform wrapper to OpenGL. Here's some code to twiddle some points:

#include <GL/glut.h>

void
reshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, w, 0, h, -1, 1);
}

void
display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POINTS);
    for (int i = 0; i<399; ++i)
    {
        glVertex2i(i, (i*i)%399);
    }
    glEnd();
    glFlush();
}

int
main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutCreateWindow("some points");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
}

That's C++ but it should be nearly identical in Python and many other languages.