1
I have an Introduction to Programming project that consists of making a comic. The first class is the Vignette. It is necessary to create two constructors for the Vignette, which in one of them takes as arguments a ColorImage
, one int
which represents the thickness, a int
type and a Color
, and on the other he receives anything but Color
. This is because, we are supposed to create frames in the Vignette, hence the thickness, the type (which can be, line, dashed or drawn) and the color (which is the color of the frame).
Then it is necessary to create several methods to know the height and width of the vignette, change the color, thickness, type, move the image to black and white and return to the original colors. All this is done. My question concerns the second class: Surfboard. The Board is an array of vignettes, with several strips (it is necessary to create the method to say how many strips we want) and each strip will have to have several vignettes (it is necessary to create the method to say how many vignettes in each individual strip we want, that is, one strip can take a vignette and another can take 3).
I will also have to devise a method that will make it possible for there to be a spacing between the vignettes and the next strip. The matrix is created and also the method to create the method to choose how many strips we want, but now we need to draw the board, define the method to know the height, width, number of vignettes of a strip, the space between vignettes and strips and place a vignette in a given position (replacing that which was in that position previously). I would like you to help me as much as you can, and the most important thing right now is to draw the board, the height and the width.
Vignette code (dashed frame is wrong if anyone knows):
import aguiaj.iscte.Color;
import aguiaj.iscte.ColorImage;
class Vinheta {
//CONSTRUTOR
ColorImage img;
private ColorImage vinheta;
int moldura;
int tipo;
Color color;
private boolean preto_branco=false;
//FORNECENDO COR
Vinheta(ColorImage img, int moldura, Color color, int tipo) {
this.img=img;
this.moldura=moldura;
this.tipo=tipo;
this.color=color;
if(tipo==0)
semMoldura(img,moldura);
else if(tipo==1)
linha(img, moldura, color);
else if(tipo==2)
tracejado(img,moldura,color);
else if(tipo==3)
desenhado(img,moldura,color);
}
//ASSUMINDO QUE A COR É PRETO
Vinheta(ColorImage img, int moldura, int tipo) {
this.img=img;
this.moldura=moldura;
this.tipo=tipo;
if(tipo==0)
semMoldura(img,moldura);
else if(tipo==1)
linha(img, moldura, Color.BLACK);
else if(tipo==2)
tracejado(img,moldura,Color.BLACK);
else if(tipo==3)
desenhado(img,moldura,Color.BLACK);
}
//VINHETA SEM MOLDURA
private void semMoldura(ColorImage img, int moldura){
ColorImage img2 = new ColorImage(this.img.getWidth() + moldura*2, this.img.getHeight() + moldura*2);
for(int x=0; x<this.img.getWidth(); x++) {
for(int y=0; y<this.img.getHeight(); y++) {
img2.setColor(x+moldura,y+moldura,this.img.getColor(x,y));
}
}
this.vinheta=img;
}
//MOLDURA LINHA
private void linha(ColorImage img, int moldura, Color color){
ColorImage img2 = new ColorImage(this.img.getWidth() + moldura*2, this.img.getHeight() + moldura*2);
for(int x=0; x<this.img.getWidth(); x++) {
for(int y=0; y<this.img.getHeight(); y++) {
img2.setColor(x+moldura,y+moldura,this.img.getColor(x,y));
}
}
for(int i=0; i<img2.getWidth(); i++) {
for(int j=0; j<img2.getHeight(); j++) {
if(i <= moldura-1 || j <= moldura-1 || i >=img2.getWidth()-moldura || j >= img2.getHeight()-moldura) {
img2.setColor(i, j, color);
}
}
}
this.vinheta=img2;
}
//MOLDURA TRACEJADA
private void tracejado(ColorImage img, int moldura, Color color) {
ColorImage img2 = new ColorImage(this.img.getWidth() + moldura*2, this.img.getHeight() + moldura*2);
for(int x=0; x<this.img.getWidth(); x++) {
for(int y=0; y<this.img.getHeight(); y++) {
img2.setColor(x+moldura,y+moldura,this.img.getColor(x,y));
}
}
for(int i=0; i<img2.getWidth(); i++) {
for(int j=0; j<img2.getHeight(); j++) {
//if(i%2==0 && j<=moldura || j%2==0 && i<=moldura){
if(i <= moldura-1 || j <= moldura-1 || i >=img2.getWidth()-moldura || j >= img2.getHeight()-moldura) {
img2.setColor(i,j,color);
}
}
}
this.vinheta=img2;
}
//MOLDURA DESENHADA
private void desenhado (ColorImage img, int moldura, Color color){
ColorImage img2 = new ColorImage(this.img.getWidth() + moldura*2, this.img.getHeight() + moldura*2);
for(int x=0; x<this.img.getWidth(); x++) {
for(int y=0; y<this.img.getHeight(); y++) {
img2.setColor(x+moldura,y+moldura,this.img.getColor(x,y));
}
}
for (int i=0;i!=img2.getWidth();i++){
for (int j=0;j!=img2.getHeight();j++){
if(i<moldura || i>=img2.getWidth()-moldura || j<moldura || j>=img2.getHeight()-moldura){
int n=(int)(Math.random()*11);
if(n%2!=0)
img2.setColor(i,j,color);
else{
Color c=new Color (255,255,255);
img2.setColor(i,j,c);
}
}
if(i>=moldura && i<img2.getWidth()-moldura && j>=moldura && j<img2.getHeight()-moldura){
Color f = img.getColor((i-moldura),(j-moldura));
img2.setColor(i,j,f);
}
}
}
this.vinheta=img2;
}
//DEFINIR A COR DA MOLDURA
void changeColor (Color color){
this.color=color;
if(tipo==0)
semMoldura(img,moldura);
else if(tipo==1)
linha(img, moldura, color);
else if(tipo==2)
tracejado(img,moldura,color);
else if(tipo==3)
desenhado(img,moldura,color);
}
//DEFINIR O TIPO DA MOLDURA
void changeTipo(int tipo){
this.tipo=tipo;
if(tipo==0)
semMoldura(img,moldura);
else if(tipo==1)
linha(img, moldura, color);
else if(tipo==2)
tracejado(img,moldura,color);
else if(tipo==3)
desenhado(img,moldura,color);
}
//DEFINIR A ESPESSURA DA MOLDURA
void changeEspessura(int moldura){
this.moldura=moldura;
if(tipo==0)
semMoldura(img,moldura);
else if(tipo==1)
linha(img, moldura, color);
else if(tipo==2)
tracejado(img,moldura,color);
else if(tipo==3)
desenhado(img,moldura,color);
}
//ALTURA VINNHETA
public int altura() {
return vinheta.getHeight();
}
//LARGURA VINHETA
int largura() {
return vinheta.getWidth();
}
//PASSAR DE CORES PARA P&B
void colorToGray() {
for(int x=moldura; x<vinheta.getWidth()-moldura; x++)
for(int y=moldura; y<vinheta.getHeight()-moldura; y++)
vinheta.setColor(x,y,vinheta.getColor(x,y).toGraytone());
}
//VOLTAR ÀS CORES ORIGINAIS
void coresOriginais(){
for(int x=0; x<img.getWidth(); x++)
for(int y=0; y<img.getHeight(); y++)
vinheta.setColor(x+moldura, y+moldura, img.getColor(x,y));
}
//DEVOLVER A IMAGEM CORRESPONDENTE À VINHETA
ColorImage getVinheta(){
if(preto_branco==false)
return this.vinheta;
else{
colorToGray();
return this.vinheta;
}
}
}
Code made from the Plank so far:
import aguiaj.iscte.ColorImage;
import aguiaj.iscte.Color;
class Prancha {
//CONSTRUTOR
Vinheta[][]m;
ColorImage prancha;
private int espacamento;
private int nTiras;
private int numeroDeVinhetas;
Prancha (int nTiras){
m = new Vinheta[nTiras][1];
for(int x=0; x>nTiras; x++){
m[x][0]=new Vinheta(new ColorImage (50,50), 1, 1);
}
int espacamento=0;
}
These Imports have to do with Aguiaj, a program created by a professor at my college, which we use in Eclipse
But what is the doubt?
– Pablo Almeida