I did this for another post but here it is anyway. I think it may help.
This is just a basic demo, so it does not really showcase of what you can really do with processing. I did this up in like 13 minutes.
Press "0" to "7" to cycle through the algorithmically created images / textures.
Press "c" to use a circle shape
Press "b" to use a box shape
Drag the mouse to change the size
Here is a screenshot
Here is the code
- PImage a,b,c,d;
PImage [] pic;
public int w=255;
public int h=255;
public PImage nowimg;
public PImage nowimginv;
public String nowshape = "circle";
void setup(){
size(w,h,P3D);
//smooth();
nowimg = createImage(w,h,ARGB);
nowimginv = createImage(w,h,ARGB);
a= createImage(w,h,ARGB);
b= createImage(w,h,ARGB);
c= createImage(w,h,ARGB);
d = createImage(w,h,ARGB);
pic = new PImage[5];
for (int x=0;x<4;x++){
pic[x]=createImage(w,h,ARGB);
for (int _x=0;_x<w;_x++){
for (int _y=0;_y<h;_y++){
int pos = _x+w*_y;
if(x==0)
{
color a0 = color (h-_y,_y,w-_x);
a.set(_x,_y,a0);
pic[x].pixels[pos]=a0;
}
if(x==1)
{
color a1 = color (h-_x,_y,_x);
b.set(_x,_y,a1);
pic[x].pixels[pos]=a1;
}
if(x==2)
{
color a2 = color (h-_x,_y-_x,_x-_y);
c.set(_x,_y,a2);
pic[x].pixels[pos]=a2;
}
if(x==3)
{
color a3 = color (w-_x,_x+_y,_x-_y);
d.set(_x,_y,a3);
pic[x].pixels[pos]=a3;
}
}
}
}
arraycopy(pic[0].pixels,nowimg.pixels);
arraycopy(pic[0].pixels,nowimginv.pixels);
nowimginv.filter(INVERT);
}
public int xsize=25;
void draw(){
image(nowimg,0,0);
if (nowshape=="circle"){
beginShape();
noStroke();
texture(nowimginv);
for (float z=0;z<6.2;z+=.1){
circle((float)mouseX,(float)mouseY,z,xsize);
}
endShape(CLOSE);
}
if (nowshape=="box"){
beginShape();
texture(nowimginv);
float _mx = (float)mouseX;
float _my = (float)mouseY;
// if (_mx<w-xsize && _my<h-xsize){
vertex(_mx,_my,0,_my,_my);
vertex(_mx+xsize,_my,0,_mx+xsize,_my);
vertex(_mx+xsize,_my+xsize,0,_mx+xsize,_my+xsize);
vertex(_mx,_my+xsize,0,_mx,_my+xsize);
// }
endShape();
}
}
void keyPressed(){
if (key=='0')arraycopy(pic[0].pixels,nowimg.pixels);
if (key=='1')arraycopy(pic[1].pixels,nowimg.pixels);
if (key=='2')arraycopy(pic[2].pixels,nowimg.pixels);
if (key=='3')arraycopy(pic[3].pixels,nowimg.pixels);
if (key=='4')arraycopy(a.pixels,nowimg.pixels);
if (key=='5')arraycopy(b.pixels,nowimg.pixels);
if (key=='6')arraycopy(c.pixels,nowimg.pixels);
if (key=='7')arraycopy(d.pixels,nowimg.pixels);
arraycopy(nowimg.pixels,nowimginv.pixels);
nowimginv.filter(INVERT);
if (key=='c')nowshape = "circle";
if (key=='b')nowshape = "box";
}
void mouseDragged(){
if (mouseX>3){
xsize= mouseX;
}
}
void circle(float startx,float starty, float angle,float distance){
float endx = startx + cos(angle) * distance;
float endy = starty + sin(angle) * distance;
stroke(startx,endx);
vertex(endx,endy,0,endx,endy);
}