Using string instead of kind of shape in createShape()
I want to pass an array of strings to a function in draw()
and have the function draw each shape with the first parameter specifying which type of shape to draw. Here's my code (inside of draw()
):
params = new String{"LINE","0","0","2","3"};
if (params.length == 2) {
createShape(params[0],float(params[1]));
} else if (params.length == 3) {
createShape(params[0],float(params[1]),float(params[2]));
} ...
} else if (params.length == 5) {
createShape(params[0],float(params[1]),float(params[2]),float(params[3]),float(params[4]));
} ...
The ellipsis marks denote more else if statements with different numbers of parameters. I know that passing values to createShape() in this way seems redundant, but it's the best way I could find to serve my purpose, and I would like to know how to make it work. Currently, this code gives me an error and says The function createShape() expects parameters like: "createShape(int,)"
.
Is there any way to get around this, or will I have to specify a case for every single kind of shape?
java processing
add a comment |
I want to pass an array of strings to a function in draw()
and have the function draw each shape with the first parameter specifying which type of shape to draw. Here's my code (inside of draw()
):
params = new String{"LINE","0","0","2","3"};
if (params.length == 2) {
createShape(params[0],float(params[1]));
} else if (params.length == 3) {
createShape(params[0],float(params[1]),float(params[2]));
} ...
} else if (params.length == 5) {
createShape(params[0],float(params[1]),float(params[2]),float(params[3]),float(params[4]));
} ...
The ellipsis marks denote more else if statements with different numbers of parameters. I know that passing values to createShape() in this way seems redundant, but it's the best way I could find to serve my purpose, and I would like to know how to make it work. Currently, this code gives me an error and says The function createShape() expects parameters like: "createShape(int,)"
.
Is there any way to get around this, or will I have to specify a case for every single kind of shape?
java processing
why not show us thecreateShape
method?
– Scary Wombat
Nov 13 '18 at 1:39
ThecreateShape(kind,p)
function draws akind
(can be things like LINE, ELLIPSE, RECT) with parametersp
wherep
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html
– user6003925
Nov 13 '18 at 1:44
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.LINE
is actually an integer. It will be defined somewhere
– Scary Wombat
Nov 13 '18 at 1:54
add a comment |
I want to pass an array of strings to a function in draw()
and have the function draw each shape with the first parameter specifying which type of shape to draw. Here's my code (inside of draw()
):
params = new String{"LINE","0","0","2","3"};
if (params.length == 2) {
createShape(params[0],float(params[1]));
} else if (params.length == 3) {
createShape(params[0],float(params[1]),float(params[2]));
} ...
} else if (params.length == 5) {
createShape(params[0],float(params[1]),float(params[2]),float(params[3]),float(params[4]));
} ...
The ellipsis marks denote more else if statements with different numbers of parameters. I know that passing values to createShape() in this way seems redundant, but it's the best way I could find to serve my purpose, and I would like to know how to make it work. Currently, this code gives me an error and says The function createShape() expects parameters like: "createShape(int,)"
.
Is there any way to get around this, or will I have to specify a case for every single kind of shape?
java processing
I want to pass an array of strings to a function in draw()
and have the function draw each shape with the first parameter specifying which type of shape to draw. Here's my code (inside of draw()
):
params = new String{"LINE","0","0","2","3"};
if (params.length == 2) {
createShape(params[0],float(params[1]));
} else if (params.length == 3) {
createShape(params[0],float(params[1]),float(params[2]));
} ...
} else if (params.length == 5) {
createShape(params[0],float(params[1]),float(params[2]),float(params[3]),float(params[4]));
} ...
The ellipsis marks denote more else if statements with different numbers of parameters. I know that passing values to createShape() in this way seems redundant, but it's the best way I could find to serve my purpose, and I would like to know how to make it work. Currently, this code gives me an error and says The function createShape() expects parameters like: "createShape(int,)"
.
Is there any way to get around this, or will I have to specify a case for every single kind of shape?
java processing
java processing
asked Nov 13 '18 at 1:36
user6003925
2314
2314
why not show us thecreateShape
method?
– Scary Wombat
Nov 13 '18 at 1:39
ThecreateShape(kind,p)
function draws akind
(can be things like LINE, ELLIPSE, RECT) with parametersp
wherep
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html
– user6003925
Nov 13 '18 at 1:44
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.LINE
is actually an integer. It will be defined somewhere
– Scary Wombat
Nov 13 '18 at 1:54
add a comment |
why not show us thecreateShape
method?
– Scary Wombat
Nov 13 '18 at 1:39
ThecreateShape(kind,p)
function draws akind
(can be things like LINE, ELLIPSE, RECT) with parametersp
wherep
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html
– user6003925
Nov 13 '18 at 1:44
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.LINE
is actually an integer. It will be defined somewhere
– Scary Wombat
Nov 13 '18 at 1:54
why not show us the
createShape
method?– Scary Wombat
Nov 13 '18 at 1:39
why not show us the
createShape
method?– Scary Wombat
Nov 13 '18 at 1:39
The
createShape(kind,p)
function draws a kind
(can be things like LINE, ELLIPSE, RECT) with parameters p
where p
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html– user6003925
Nov 13 '18 at 1:44
The
createShape(kind,p)
function draws a kind
(can be things like LINE, ELLIPSE, RECT) with parameters p
where p
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html– user6003925
Nov 13 '18 at 1:44
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.
LINE
is actually an integer. It will be defined somewhere– Scary Wombat
Nov 13 '18 at 1:54
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.
LINE
is actually an integer. It will be defined somewhere– Scary Wombat
Nov 13 '18 at 1:54
add a comment |
1 Answer
1
active
oldest
votes
You can't do this out of the box, but you could do something like this:
void createMyShape(String myArray){
if(myArray[0].equals("LINE")){
Shape s = createShape(LINE);
s.vertex(int(myArray[1]), int(myArray[2]));
s.vertex(int(myArray[3]), int(myArray[4]));
s.endShape();
}
else if ...
}
This function parses the myArray
parameter and uses if
statements to take the right actions to create a shape. It also uses the int()
function to parse the string array.
Note that this is not a great design. You should probably not use a String array for this. It's probably better to use a class to encapsulate your data.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272523%2fusing-string-instead-of-kind-of-shape-in-createshape%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't do this out of the box, but you could do something like this:
void createMyShape(String myArray){
if(myArray[0].equals("LINE")){
Shape s = createShape(LINE);
s.vertex(int(myArray[1]), int(myArray[2]));
s.vertex(int(myArray[3]), int(myArray[4]));
s.endShape();
}
else if ...
}
This function parses the myArray
parameter and uses if
statements to take the right actions to create a shape. It also uses the int()
function to parse the string array.
Note that this is not a great design. You should probably not use a String array for this. It's probably better to use a class to encapsulate your data.
add a comment |
You can't do this out of the box, but you could do something like this:
void createMyShape(String myArray){
if(myArray[0].equals("LINE")){
Shape s = createShape(LINE);
s.vertex(int(myArray[1]), int(myArray[2]));
s.vertex(int(myArray[3]), int(myArray[4]));
s.endShape();
}
else if ...
}
This function parses the myArray
parameter and uses if
statements to take the right actions to create a shape. It also uses the int()
function to parse the string array.
Note that this is not a great design. You should probably not use a String array for this. It's probably better to use a class to encapsulate your data.
add a comment |
You can't do this out of the box, but you could do something like this:
void createMyShape(String myArray){
if(myArray[0].equals("LINE")){
Shape s = createShape(LINE);
s.vertex(int(myArray[1]), int(myArray[2]));
s.vertex(int(myArray[3]), int(myArray[4]));
s.endShape();
}
else if ...
}
This function parses the myArray
parameter and uses if
statements to take the right actions to create a shape. It also uses the int()
function to parse the string array.
Note that this is not a great design. You should probably not use a String array for this. It's probably better to use a class to encapsulate your data.
You can't do this out of the box, but you could do something like this:
void createMyShape(String myArray){
if(myArray[0].equals("LINE")){
Shape s = createShape(LINE);
s.vertex(int(myArray[1]), int(myArray[2]));
s.vertex(int(myArray[3]), int(myArray[4]));
s.endShape();
}
else if ...
}
This function parses the myArray
parameter and uses if
statements to take the right actions to create a shape. It also uses the int()
function to parse the string array.
Note that this is not a great design. You should probably not use a String array for this. It's probably better to use a class to encapsulate your data.
answered Nov 13 '18 at 1:50
Kevin Workman
33.4k53969
33.4k53969
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272523%2fusing-string-instead-of-kind-of-shape-in-createshape%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why not show us the
createShape
method?– Scary Wombat
Nov 13 '18 at 1:39
The
createShape(kind,p)
function draws akind
(can be things like LINE, ELLIPSE, RECT) with parametersp
wherep
is some array of floats. I'm pretty sure it's specific to the processing library . Here's the documentation: processing.org/reference/createShape_.html– user6003925
Nov 13 '18 at 1:44
Yes, as per the link you sent me Parameters kind int: either POINT, LINE, TRIANGLE, QUAD, RECT, ELLIPSE, ARC, BOX, SPHERE The first parameter e.g.
LINE
is actually an integer. It will be defined somewhere– Scary Wombat
Nov 13 '18 at 1:54