We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The goal of the application is to generate a cube graphic and later its going to import settings from a text document that will change the color, size and fill of the cube. Part of this involves making something in the program that will read if one of the settings for the class Block will say either the string "Filled" or not say the string "Filled." I tried to set up a boolean "fill" which is assigned to the cube.fill type in setup = the String "Filled", then it should use the function drawBlockfill for its parameters, but if it says anything other than "Filled," it should use the function drawBlockhollow. As it is I'm getting the EOF error which, according to these forums, there never seems to be a consistent solution to. I'd like to know if the way I'm doing this is possible within the syntax of processing, and if so why isn't it working. If this isn't the way to do it, do you have any suggestions? I'm using processing 3.0. Thanks!
final int W = 640, H = 480;
BufferedReader reader;
Block cube;
boolean filled;
filled = cube.fill = "Filled";
void setup()
{
size( 640, 480 );
cube = new Block();
cube.x = 200;
cube.y = 200;
cube.wi = 120;
cube.hi = 120;
cube.c = color(39,200,39);
cube.fill = "Filled";
}
void draw()
{
background(255);
if(filled)
{
drawBlockfill(cube);
}
else
{
drawBlockhollow(cube);
}
}
void drawBlockfill ( Block b )
{
noStroke();
fill(b.c/2);
rect(b.x, b.y, b.wi, b.hi);
fill(b.c);
quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
fill(b.c*2);
quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
}
void drawBlockhollow ( Block b )
{
noFill();
stroke(b.c);
rect(b.x, b.y, b.wi, b.hi);
noFill();
stroke(b.c);
quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
noFill();
stroke(b.c);
quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
}
class Block
{
int x, y;
int wi, hi;
color c;
String fill;
}
Answers
You're doing things a little weird. This line in particular:
There's no comparison happening there. You're got two assignments. Did you mean this?
Because that's better, but still wrong. This is what I think you really want:
But it's in the wrong place - you have it at the global level, where it will be evaluated before cube.fill is assigned a value.
Here's some code that removes the cube.fill property from the class entirely, and just uses the global boolean filled to determine if the cube should be drawn filled or not:
Notice also that some other extra stuff here has been commented out - the reader variable you're not using, and the W and H variables.
But even this way, you're still doing things a little weird.......
And what I mean by that is that you have this great Block class, but you're not using it like an object at all. Your drawBlockfilled() and drawBlockhollow() functions can belong to the Block class, as can the filled property.
Doing it this way lets the Block class deal with it's own drawing, allowing you to have simple logic inside setup() and draw().