Turn grid on and off
in
Programming Questions
•
1 year ago
Hello,
So I am working on this drawing tool for 8 bit games. It is a school assignment. And I pretty much have it figured out. I just wanted to add a last feature which is turning off the grid that is is used to draw the pixels before you save it, but I have not accomplished it. I figured it out on the void setup but since I have everything on the void draw it does not seem to work. Any suggestions are more than welcome, here is the code for the program and at the end is my temporary solution that when incorporated did not work:
- int xPos;
- int yPos;
- int wRect;
- int hRect;
- PFont myFontPixelizer;
- PFont myFontPixelizer2;
- int fontPosX = 30;
- int fontPosY = 30;
- color pixelColor;
- boolean unload = false;
- int saveP = 1;
- PImage myImage;
- PImage myImage1;
- PImage temp;
- PImage a;
- void setup() {
- size(650, 650);
- myImage = loadImage("colorpalette.jpeg");
- myImage1 = loadImage("mario.png");
- a = loadImage("grid.png");
- frame.setTitle("|| Pixelizer v1.3 ||");
- frame.setLocationRelativeTo(null);
- smooth();
- pixelColor= myImage.get(mouseX, mouseY);
- myFontPixelizer= loadFont("GB18030Bitmap-48.vlw");
- // gridOn = false;
- myFontPixelizer2= loadFont("GB18030Bitmap-14.vlw");
- smooth();
- background(255);
- if(!unload){
- image(a,200,200);
- }
- if( key =='g'){
- unload=true;
- }
- }
- void draw() {
- //Title---------------------------------->
- image(myImage, 30, 310);
- image(myImage1, 30, 90);
- textFont(myFontPixelizer);
- text("Pixelizer", 30, 70);
- fill(pixelColor);
- //Define my variables and functions
- // mousePixel();
- instructions();
- noStroke();
- //Get color------------------------------->
- if (keyPressed && key == 'c') {
- // if (key == 'c') {
- pixelColor = myImage.get(mouseX - 30, mouseY - 310);
- }
- //Grid------------------------------------>
- for (int i = 0; i <= 400 ; i= i+20) {
- for (int j = 0; j <= 400 ; j= j+20) {
- rect(200+i, 200+j, 20, 20);
- noStroke();
- }
- }
- }
- void keyTyped() {
- if ( key == 's') {
- PImage temp = get(200, 200, 420, 420);
- temp.save("image"+saveP+".png");
- saveP++;
- }
- }
- void instructions() {
- noFill();
- textFont(myFontPixelizer2);
- text(" Use the Grid to draw Mario press 's' to save \n press 'c' on the color palette to get color \n mouse click on the center of \n each square to draw a pixel", 200, 100);
- }
- void mousePressed() {
- for (int i = 200; i < 620 ; i+=20) {
- for (int j = 200; j < 620; j+=20) {
- if (mouseX > i && mouseX <= i+20) {
- if (mouseY > j && mouseY <= j+20) {
- fill(pixelColor);
- rect(i, j, 20, 20);
- }
- }
- }
- }
- }
temporary solution:
- boolean grid = true;
- void setup() {
- background(230);
- size(500, 500);
- ellipseMode(CORNER);
- }
- void draw() {
- background(127);
- if (grid) {
- for (int i = 0; i < 240 ; i+=30) {
- for (int j = 0; j < 240; j+=30) {
- rect(i, j, 30, 30);
- }
- }
- }
- println(grid);
- }
- void keyPressed() {
- if (key == 'g' && grid == true) {
- grid = false;
- }
- else if ((key == 'g') && grid == false) {
- grid = true;
- }
- }
1