Transparent png with objects PGraphics
in
Programming Questions
•
1 year ago
Hello I'm stuck at the moment,
I'm trying to export a transparent .png I know I have to do this with PGraphics, but I can't figure how to implement it into my code.
I've tried putting it in my class 'Tile' but I cant seem to get it to work. Here is the blank code without any PGraphics.
Any help would be greatly appreciated.
Thanks
Sam
- int cols = 48;
- int rows = 30;
- int tileSize = 20;
- Tile[][] myTile = new Tile[cols][rows];
- void setup() {
- size(960,600);
- for(int i = 0; i < cols; i++) {
- for(int j = 0; j < rows; j++) {
- myTile[i][j] = new Tile(i,j);
- }
- }
- noLoop();
- }
- void draw() {
- background(255);
- for(int i = 0; i < cols; i++) {
- for(int j = 0; j < rows; j++) {
- myTile[i][j].rdmColor();
- myTile[i][j].display();
- }
- }
- }
- void mousePressed() {
- loop();
- for(int i = 0; i < cols; i++) {
- for(int j = 0; j < rows; j++) {
- myTile[i][j].change();
- }
- }
- noLoop();
- }
- void keyPressed() {
- int s = 1;
- String fileName = "alphatest";
- save(fileName + s + ".png");
- println(fileName + s + ".png saved");
- s++;
- }
- ///////////////////////////////////////////////////
- class Tile {
- // Variables
- int Xindex;
- int Yindex;
- float tilt;
- int rdmCols;
- float x, y;
- // Constructor
- Tile(int Xindex, int Yindex) {
- x = Xindex * tileSize + tileSize/2;
- y = Yindex * tileSize + tileSize/2;
- }
- // Functions
- void display() {
- noStroke();
- fill(0);
- //fill(rdmCols);
- smooth();
- pushMatrix();
- translate(x,y);
- rotate(tilt);
- triangle(-tileSize/2, -tileSize/2, -tileSize/2, tileSize/2, tileSize/2, tileSize/2);
- popMatrix();
- }
- void change() {
- float randNum;
- float[] num = new float[4];
- num[0] = 0;
- num[1] = PI/2;
- num[2] = PI;
- num[3] = 3*PI/2;
- randNum = num[int(random(0,num.length))];
- // Organised
- tilt += randNum;
- // Organised Chaos
- //tilt += random(radians(0),radians(270));
- println(tilt);
- }
- void rdmColor() {
- int[] rdmCol = new int[3];
- rdmCol[0] = color(#3F00FF);
- rdmCol[1] = color(#9E7EFF);
- rdmCol[2] = color(#CEBFFF);
- rdmCols = rdmCol[int(random(0,rdmCol.length))];
- }
- }
1