Help with complex homework(Solved)

Hi everyone, I would really appreciate the help trying to figure out this code. I have been working at it for hours and I haven’t gotten any progress on it at all. I hope that you are able to help in any kind of way. The image below is supposed to be the outcome of the code. Thank you

void setup()
{
size(400, 400);
noLoop();
}

void draw()
{
background(255);
noStroke();

for(int i=0; i<72; i++)
{
DrawFlower( _ , _ , _ , _ , _ );
}
}

void DrawFlower(float x, float y, float s, float angle, float alpha)
{
fill(0, _ );
pushMatrix();
translate( _ , _ );
rotate( _ );
scale( _ , _ );

beginShape();
vertex(0, 0);
bezierVertex(0, 0, 0, -54, 30, -72);
bezierVertex(54, -90, 72, -117, 72, -144);
bezierVertex(72, -144, 96, -96, 78, -72);
bezierVertex(66, -44, 0, -36, 0, 0);
endShape();
popMatrix();
}

question help

1 Like

thank you!

this code is not runnable

Did you write the code?

I wonder about the _ . Did you put them there or your teacher?

What have you tried, where are you stuck?

Remark

Some things should be clear, for example: rotate( … );

take a guess, what has to be written there?

2 Likes

No, I didn’t write the code it was given to me like that from my teacher. I put the underscores there to signify the empty space. I have tried input the x,y, s, angle, and alpha to the translate, rotate, and scale but it didn’t work and I am confused about the DrawFlower(); part on what to put in there.

Do you know the purpose of a function?

As you can see, the function name is DrawFlower and some numbers are passed to it (which are then stored in variables (that are known within the function))

  • x,y signifies the location - use with translate
  • s signifies the scale
  • angle the angle of the leaf (between 0 and 2 PI)
  • and alpha the degree of opaqueness

this is for:

2 Likes

son now you can fill in

translate( _ , _ );
rotate( _ );
scale( _ , _ );

with the variables from the header of the function: x,y and so on

can you show me?

2 Likes

translate( x , y );
rotate( angle );
scale( s , alpha);

would this be wrtie

here you mean the line
DrawFlower( _ , _ , _ , _ , _ );
in the function draw() where we actually call (use) the function DrawFlower.

  • Now, we want to pass the parameters to the function that the function wants to hear.

  • (what we write here: DrawFlower( _ , _ , _ , _ , _ ); must match this: void DrawFlower(float x, float y, float s, float angle, float alpha) )

We start with (check definition of function DrawFlower(float x, float y, …) ) x,y, which is the position, so we want to pass the position. Let’s use the center of the screen.

Ideas?

2 Likes

WELL DONE!!

almost correct

except

we want scale( s , s);

the alpha is for opaqueness of the color so use fill(0, alpha ); please

so your function is finished now.

Now look up to my previous post as how to call the function from draw() please

2 Likes

would it be width/2 and height/2 or would it be something completely different?

1 Like

That’s nice!

Excellent.

Next is ? s.

2 Likes

Would it be between 0.5 and 1 right or would it be just s?

that’s the scale (size)

let’s go for 1 first.

you can replace it with a random number like random(0.5,1) later

Next is ?

2 Likes

that was a great way to handle a homework question @Chrisir

1 Like

the next would be float angle with the DrawFlower

1 Like

that’s right.

That angle should increase with every step.

Let’s put i for a test

i is our variable from the for-loop, so i gets bigger by one every time

2 Likes

so all would be left is float alpha

What’s next?

alpha

which is how opaque our color is.

alpha is correct

let’s say 60


Now

try run your code

Does it run?

you need a running code to improve the graphic

I suggest we take care of the angle first.

That’s probably very wrong. Ideas?

2 Likes

sorry I was screenshotting the work it works and I am really thankful for you for helping

WELL DONE!!

Now, we have differences to the initial graphic.

you can use some random.

Do you have ideas where we want to use random?

2 Likes

we could use it in scale

1 Like