Created
November 13, 2013 12:50
-
-
Save dimkir/7448549 to your computer and use it in GitHub Desktop.
Created using Sketch2Tweet tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new script | |
/** | |
* This variable PGraphics will hold the | |
* framebuffer into which you're only | |
* going to ddraw rectangles. | |
*/ | |
PGraphics frameBuffer; | |
void setup(){ | |
size(800,600); | |
// you need to initialize the framebuffer | |
// to the size of your screen. | |
frameBuffer = createGraphics(800,600); | |
// if you don't want the "original" mouse cursor to be visible over your sketch | |
// uncomment the next line | |
// noCursor(); | |
} | |
void draw(){ | |
background(0); | |
drawBackground(); | |
drawMouseCircle(); | |
} | |
/** | |
* Draws background to framebuffer | |
* and then renders the framebuffer | |
* to the screen. | |
*/ | |
void drawBackground(){ | |
// before you start drawing to framebuffer, you need to "begin it" by calling .beginDraw() | |
frameBuffer.beginDraw(); | |
// set up the "brush" parameters (note that "brush" parameters are set ON FRAMEBUFFER not just by thelselves. | |
// "fade" the framebuffer by drawing semi-transparent black rectangle | |
frameBuffer.fill(0, 10); | |
frameBuffer.rect(0, 0, | |
frameBuffer.width, | |
frameBuffer.height); | |
// set the "brushes for drawing the smaller rects. | |
frameBuffer.fill(255); | |
frameBuffer.noStroke(); | |
// draw rectangle at random position | |
// get random coordinates and width (height equal to width, so we have squares) | |
int randomX = int( random(800) ); | |
int randomY = int ( random(600) ); | |
int randomWidth = int ( random(30, 90) ); | |
int randomHeight = randomWidth; // let it be suqare. | |
// draw actual rectangle to framebuffer. | |
frameBuffer.rect(randomX, randomY, randomWidth, randomWidth); | |
frameBuffer.endDraw(); // now we MUST tell processing that we're finished with the framebuffer by calling .endDraw() | |
// now we tell our sketch to ddraw the framebuffer to the screen. | |
// As "under the hood" the framebuffer is stored as regular image in memory, we can call | |
// image() method which is used to draw JPGs and PNGs to the screen. | |
image(frameBuffer, 0, 0); | |
} | |
void drawMouseCircle(){ | |
fill(#55BC8B); // kinda greenish color | |
noStroke(); | |
ellipse(mouseX, mouseY, 40, 40); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment