Write functions that create each of the shapes shown below u

Write functions that create each of the shapes shown below using OpenGL. You can pick your own colors and line thickness for each shape. You can create these shapes using simpler primitives such as circles, rectangles, etc.

Solution

PShape rectangle;

void setup()

{

size(640,360,P2D);

rectangle = createShape(RECT,mouseX,mouseY,100,50);

}

It\'s important to remember that when using PShape, what we are really doing is configuring the geometry relative to the origin (0,0). It\'s generally advantageous to then move that shape above the screen using transformations: translate(), rotate(), etc. So now we have:

and if we wanted the Rectangle to be drawn from its center:

We can then move it according to the mouse with translate.

One of the nice things about the PShape object is that it can also store color information in addition to geometry.

Once a shape has been created in order to alter its fill or stroke, use the methods setFill(), setStroke(),

setStrokeWeight(), etc.

These methods can be called during draw() as well if you want to change the color of the shape dynamically.

It should be noted that unlike with fill() and stroke() you must pass a full color as an argument. i.e. instead of saying

\"setFill(255,0,0)\" for a red fill, you\'ll need to say \"setFill(color(255,0,0))\". In addition, setFill() and setStroke() can

take a boolean argument (e.g. setFill(false)) to turn the fill or stroke on or off for a given vertex as well as an integer

(e.g. setFill(i,color(255,0,0))) to set the fill or stroke for a specific vertex.

Write functions that create each of the shapes shown below using OpenGL. You can pick your own colors and line thickness for each shape. You can create these sh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site