We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How would I modify this with a triangle and make sure the dots stay inside?
void setup() { size(200, 200); }
void draw() { background(255); stroke(0); fill(175);
int mx = constrain(mouseX, 0, width); int my = constrain(mouseY, 0, height);
translate(mx, my); ellipse(0, 0, 8, 8);
translate(100, 0); ellipse(0, 0, 8, 8);
translate(0, 100); ellipse(0, 0, 8, 8);
translate(-100, 0); ellipse(0, 0, 8, 8); }
Answers
I'd start by drawing the triangle that you want the dots to remain inside.
Again: learn how to post code correctly
In processing hit ctrl-t prior to posting
From the points you have: store them in an array and for loop over it
Find out here which is the lowest and highest x and y and use those values for your triangle
void setup() {
size(500, 500); smooth(); }
void draw() {
background(255); stroke(0); fill(175);
// Grab mouse coordinates, comstrained to window
int mx = constrain(mouseX, 0, width); int my = constrain(mouseY, 0, height);
//Translate to the mouse location translate(mx, my); ellipse(0, 0, 8, 8);
// Translate 100 pixals to the right translate(100, 0); ellipse(0, 0, 8, 8);
// Translate 100 pixals down translate(0, 100); ellipse(0, 0, 8, 8);
// Translate 100 pixals left translate(-100, 0); ellipse(0, 0, 8, 8); }
No.
It has been explained to you in the other thread how to format your code correctly
Please edit your posts and fix the code formatting.
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Given a square of points, many different triangle could enclose them -- a right triangle, an isosceles, equilateral etc. etc.
What kind of triangle do you want? Should one or more of the points be touching the triangle edges? All four points?