OrbitalBrush Source | Download the app
This app is a simple manipulation of PxP Paint Pixels. The brush itself is a gradient, determined by the distance of the pixels within the brush from the location of the mouse, the brush itself is then offset from the mouse location and orbits around it, in order to do so, I have moved it to the draw loop. The arrow keys mapped to control the brush size.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | /* ITP Pixel by Pixel Paint pixels drag mouse to paint Danny Rozin 2010 */ #include "testApp.h" int R=255,G=255,B=0, brushSize =20, percent = 550; float theta = 0; //************** Everything you want to happen once in the begining, but don't draw anything to the creen here a it will not work **************** void testApp::setup(){ ofBackground(255,255,255); // background color ofSetFrameRate(30); width = ofGetWidth(); height = ofGetHeight(); ourTexture = * new ofTexture(); // create an ofTexture to hold our image info ourTexture.allocate(width, height, GL_RGB); // allocate memory for the ofTextue (This is RGB no Alpha) ourPixels = new unsigned char[width*height*3]; // create a pixel array to keep our processed pixel data (RGB, no Alpha). ofEnableAlphaBlending(); // turn on alpha blending ofEnableSmoothing(); } //******************This time we put most of the interesting stuff into the mouseDragged method cause we want to paint only when we drag************ void testApp::mouseDragged(int x, int y, int button){ float mouseXOff = mouseX+sin(ofRadToDeg(theta)); float mouseYOff = mouseY+sin(ofRadToDeg(theta)); // R+=ofRandom(-10,10); // let the R,G,B values wonder arround randomly... // R=ofClamp(R,0,255); // but make sure they are still 0- 255 // // G+=ofRandom(-10,10); // G=ofClamp(G,0,255); // // B+=ofRandom(-10,10); // B=ofClamp(B,0,255); ofEnableSmoothing(); int colorOffset = 0; for (int x=mouseXOff-brushSize;x< mouseXOff+brushSize;x++){ // repeat loop of 50 x 50 pixels around the mouse for (int y=mouseYOff-brushSize;y< mouseYOff+brushSize;y++){ // if (ofRandom(0,1000) > percent){ if (x>0 && y>0 && y< height) // check that we are not accessing pixels outside the bounds of our array if (ofDist(x,y,mouseXOff,mouseYOff)< brushSize) { // constrict the brush to a circle by checking that the pixel is not more than... int colorOffset = ofMap(ofDist(x,y,mouseXOff,mouseYOff),0,brushSize,0,255); R=255-colorOffset; // let the R,G,B values wonder arround randomly... R=ofClamp(R,10,255); // but make sure they are still 0- 255 G=255-colorOffset; G=ofClamp(G,10,255); B=255-colorOffset; B=ofClamp(B,10,255); ourSetPixel(x,y,R,G,B,width,ourPixels); } // brushSize away from the mouse //} } } } //********************************************* Code in draw() execute every frame, ********************************************************** void testApp::draw(){ float offset = 2; float mouseXOff = mouseX+offset*brushSize*cos(ofRadToDeg(theta)); float mouseYOff = mouseY+offset*brushSize*sin(ofRadToDeg(theta)); int colorOffset = 0; for (int x=mouseXOff-brushSize;x< mouseXOff+brushSize;x++){ // repeat loop of 50 x 50 pixels around the mouse for (int y=mouseYOff-brushSize;y< mouseYOff+brushSize;y++){ // if (ofRandom(0,1000) > percent){ if (x>0 && y>0 && y< height) // check that we are not accessing pixels outside the bounds of our array if (ofDist(x,y,mouseXOff,mouseYOff)< brushSize) { // constrict the brush to a circle by checking that the pixel is not more than... int colorOffset = ofMap(ofDist(x,y,mouseXOff,mouseYOff),0,brushSize,0,255); R=255-colorOffset; // let the R,G,B values wonder arround randomly... R=ofClamp(R,0,255); // but make sure they are still 0- 255 G=255-colorOffset; G=ofClamp(G,0,255); B=255-colorOffset; B=ofClamp(B,0,255); ourSetPixel(x,y,R,G,B,width,ourPixels); } // brushSize away from the mouse //} } theta+= 0.0001; } ourTexture.loadData(ourPixels, width, height, GL_RGB); // This loads the pixels array into the OF texture ourTexture.draw(0,0); // this draws the texture to the screen printf("percent = %i \n", percent); // prints our variable to the console ofEllipse(mouseXOff, mouseYOff, 10, 10); } //********************** Pixel by Pixel course method that sets a pixel RGB in an x, y position in a pixel array *********************** void testApp::ourSetPixel(int horizontal,int vertical,unsigned char R,unsigned char G,unsigned char B,int arrayWidth, unsigned char pixels[]){ int thisPixel = 3*(arrayWidth * vertical +horizontal); pixels[thisPixel]=R; pixels[thisPixel+1]=G; pixels[thisPixel+2]=B; } //-------------------------------------------------------------- void testApp::keyPressed (int key){ if (key == OF_KEY_UP) brushSize++; if (key == OF_KEY_DOWN) brushSize--; } void testApp::update(){} void testApp::mouseMoved(int x, int y ){ } void testApp::keyReleased(int key){ } void testApp::mousePressed(int x, int y, int button){} void testApp::mouseReleased(){ } |