How to limit where you are drawing lines
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to limit where I am drawing lines inside a triangle, so the lines don't overflow and disrupt other elements of the canvas, here is my code so far:
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
javascript processing p5.js
add a comment |
I am trying to limit where I am drawing lines inside a triangle, so the lines don't overflow and disrupt other elements of the canvas, here is my code so far:
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
javascript processing p5.js
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21
add a comment |
I am trying to limit where I am drawing lines inside a triangle, so the lines don't overflow and disrupt other elements of the canvas, here is my code so far:
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
javascript processing p5.js
I am trying to limit where I am drawing lines inside a triangle, so the lines don't overflow and disrupt other elements of the canvas, here is my code so far:
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
var points = ;
var r = 500;
var lines = 30;
function setup() {
createCanvas(1000, 1000);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var tempX = r * 1.1545 * sin(tempAngle) + points[i][0];
var tempY = r * 1.1545 * cos(tempAngle) + points[i][1];
fill(255);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var distance = r + (dist(points[i][0], points[i][1], tempX, tempY) - r) / lines * j;
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
javascript processing p5.js
javascript processing p5.js
asked Nov 26 '18 at 22:26
Tudor PopescuTudor Popescu
167112
167112
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21
add a comment |
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21
add a comment |
1 Answer
1
active
oldest
votes
You can take advantage of the fact that the angle between the current element and the next element is always 90 °.
This results in that the length of the lines along the triangles increases with the reciprocal cosine of the angles:
Note, an angle in degrees can be converted to an angle in radians by angle_red = Math.PI * angle_degree/180.0
:
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
See the example, where i applied the formula for the length of the lines to your original code:
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
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%2f53490059%2fhow-to-limit-where-you-are-drawing-lines%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 take advantage of the fact that the angle between the current element and the next element is always 90 °.
This results in that the length of the lines along the triangles increases with the reciprocal cosine of the angles:
Note, an angle in degrees can be converted to an angle in radians by angle_red = Math.PI * angle_degree/180.0
:
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
See the example, where i applied the formula for the length of the lines to your original code:
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
add a comment |
You can take advantage of the fact that the angle between the current element and the next element is always 90 °.
This results in that the length of the lines along the triangles increases with the reciprocal cosine of the angles:
Note, an angle in degrees can be converted to an angle in radians by angle_red = Math.PI * angle_degree/180.0
:
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
See the example, where i applied the formula for the length of the lines to your original code:
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
add a comment |
You can take advantage of the fact that the angle between the current element and the next element is always 90 °.
This results in that the length of the lines along the triangles increases with the reciprocal cosine of the angles:
Note, an angle in degrees can be converted to an angle in radians by angle_red = Math.PI * angle_degree/180.0
:
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
See the example, where i applied the formula for the length of the lines to your original code:
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
You can take advantage of the fact that the angle between the current element and the next element is always 90 °.
This results in that the length of the lines along the triangles increases with the reciprocal cosine of the angles:
Note, an angle in degrees can be converted to an angle in radians by angle_red = Math.PI * angle_degree/180.0
:
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
See the example, where i applied the formula for the length of the lines to your original code:
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
var points = ;
var r = 250;
var lines = 30;
function setup() {
createCanvas(500, 500);
angleMode(DEGREES);
var angle = 60;
for (var i = 1; i < 7; i++) {
var tempX = r * sin((angle * i + 30) % 360) + width / 2;
var tempY = r * cos((angle * i + 30) % 360) + height / 2;
points.push([tempX, tempY]);
}
noSmooth();
noLoop();
}
function draw() {
for (var i = 0; i < points.length; i++) {
line(points[i][0], points[i][1], points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
var tempAngle = 240 + i * 60;
var angle_degree = 30.0;
var dist_pt = r / Math.cos(Math.PI * angle_degree/180.0);
var tempX = dist_pt * sin(tempAngle) + points[i][0];
var tempY = dist_pt * cos(tempAngle) + points[i][1];
fill(255, 128+i*20, 128);
triangle(points[i][0], points[i][1], tempX, tempY, points[(i + 1) % 6][0], points[(i + 1) % 6][1]);
stroke(0);
for (var j = 0; j < lines + 1; j++) {
var cur_angle = 30 / lines * j;
var distance = r / Math.cos(Math.PI * cur_angle/180.0);
var tempAngle2 = tempAngle = (30 / lines * j) + 210 + i * 60;
var tempX2 = distance * sin(tempAngle2) + points[i][0];
var tempY2 = distance * cos(tempAngle2) + points[i][1];;
line(points[i][0], points[i][1], tempX2, tempY2);
}
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.js"></script>
edited Nov 28 '18 at 6:07
answered Nov 27 '18 at 19:56
Rabbid76Rabbid76
44.2k123354
44.2k123354
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
add a comment |
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
Thanks for the detailed answer.
– Tudor Popescu
Nov 28 '18 at 21:23
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
@TudorPopescu You're welcome.
– Rabbid76
Nov 28 '18 at 21:24
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.
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%2f53490059%2fhow-to-limit-where-you-are-drawing-lines%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
What is wrong with the solution in your question? Can you call out specifically what problem(s) is/are still outstanding?
– Will Cain
Nov 26 '18 at 22:34
@WillCain the last triangle still overflows, and I can't fix that because there will always be one overflowing with my code
– Tudor Popescu
Nov 26 '18 at 23:21