Made A Little Toy
in
Share your Work
•
1 year ago
I just started programming a week ago, but I'm figuring out how trigonometry works when it's applied.
So, I made a little toy which a colorful triangle attempts to reach 0, 0 on the screen.
I could just keep re-running it for hours...
Oh, and you can tweak with it by playing with the numbers and waves, size and location.
- tring traz; // You could make more by simply copy pasting it, though they would all follow the base pattern...
- void setup() { // Play with this to change origin triangle. It does change how it is executed by vibrate.
- traz = new tring (random(0, 1000), random(0, 1000), random(0, 1000), random(0, 1000), random(0, 1000), random(0, 1000));
- size (500, 500);
- background (200, 200, 200);
- smooth();
- }
- class tring { // Bleh, lots of temp assigning to triangle. . _ .
- float angle;
- float x1;
- float x2;
- float x3;
- float y1;
- float y2;
- float y3;
- tring (float tx1, float tx2, float tx3, float ty1, float ty2, float ty3) {
- x1 = tx1;
- x2 = tx2;
- x3 = tx3;
- y1 = ty1;
- y2 = ty2;
- y3 = ty3;
- }
- void render() { // You can play with these to change color and pattern base. Wave tan makes a mess though.
- stroke((x1 + y1) / 2, (x2 + y2) / 2, (x3 + y3) / 2, (127 - 127*cos(angle)) / 2);
- fill((x1 + y1) / 3, (x2 + y2) / 3, (x3 + y3) / 3, 127 + 127*sin(angle));
- triangle( x1, y1, x2, y2, x3, y3);
- x1 = x1 + (x1*sin(angle)) / 9;
- x2 = x2 + (x2*cos(angle)) / 9;
- x3 = x3 + (x3*sin(angle)) / 9;
- y1 = y1 + (y1*-cos(angle)) / 9;
- y2 = y2 + (y2*-sin(angle)) / 9;
- y3 = y3 + (y3*-cos(angle)) / 9;
- }
- void vibrate() {
- angle += 0.2;
- }
- }
- void draw() {
- traz.render();
- traz.vibrate();
- }