One of the nice things about Processing is how easy it is to create simple effects via the mouse with just a few lines of code. Does anyone have any favourite painting effects?
I'll share my rainbow spray-paint below. I'm interested in collecting a few more because I recently wrote a painting framework (toolbar, zoom, undo, that sort of stuff).
http://www.openprocessing.org/sketch/64054
I'll share my rainbow spray-paint below. I'm interested in collecting a few more because I recently wrote a painting framework (toolbar, zoom, undo, that sort of stuff).
http://www.openprocessing.org/sketch/64054
- // Rainbow spray-paint effect
- Random rng = new Random();
- float angle = 0.0;
- void setup()
- {
- size(900,600);
- background(200);
- }
- void draw()
- {
- if (mouseX != pmouseX || mouseY != pmouseY)
- {
- // Work out the general direction in which the mouse is moving
- float angle2 = atan2(mouseY-pmouseY,mouseX-pmouseX);
- if (angle2 - angle > PI)
- angle2 -= TWO_PI;
- else if (angle2 - angle < -PI)
- angle2 += TWO_PI;
- angle = (angle * 0.9) + (angle2 * 0.1);
- if (angle >= PI)
- angle -= TWO_PI;
- else if (angle <= -PI)
- angle += TWO_PI;
- }
- if (mousePressed)
- {
- strokeWeight(2);
- for (int nCol = 0; nCol < 6; ++nCol)
- {
- stroke(getColor(nCol));
- pushMatrix();
- translate(mouseX,mouseY);
- rotate(angle);
- translate(0,(nCol*20)-60);
- for (int n = 0; n < 80; ++n)
- {
- spray();
- }
- popMatrix();
- }
- }
- }
- void spray()
- {
- float x = (float)(rng.nextGaussian() * 10);
- float y = (float)(rng.nextGaussian() * 10);
- point(x,y);
- }
- color getColor(int nCol)
- {
- color c = color(128);
- float alpha = 32;
- switch(nCol)
- {
- case 0: c = color(255, 0, 0, alpha); break; // Red
- case 1: c = color(255, 127, 0, alpha); break; // Orange
- case 2: c = color(255, 255, 0, alpha); break; // Yellow
- case 3: c = color(0, 255, 0, alpha); break; // Green
- case 4: c = color(0, 0, 255, alpha); break; // Blue
- case 5: c = color(111, 0, 255, alpha); break; // Indigo
- case 6: c = color(143, 0, 255, alpha); break; // Violet
- }
- return c;
- }