Trying to create diagonal patterns using graphics
I am trying to create a diagonal pattern using graphics, but only half of the pattern is filled. I am also trying to make it so that the same pattern fills the whole 500x500 but have no idea how.
EDIT: Sorry I don't mean all of it filled, like from (0-100,500) has the line pattern and then the (100-200,500) is empty and so on.
from graphics import *
def patchwork():
win = GraphWin('Lines test',500,500)
for x in range(0,101,20):
line = Line(Point(x,0), Point(100,100-x))
line.setFill('red')
line.draw(win)
for x2 in range(101,0,-20):
line2 = Line(Point(100,0+x2), Point(x2,100))
line2.setFill('red')
line2.draw(win)
I expected the pattern to fully fill the 100x100 with diagonal lines but only have of it is filled.
python graphics
add a comment |
I am trying to create a diagonal pattern using graphics, but only half of the pattern is filled. I am also trying to make it so that the same pattern fills the whole 500x500 but have no idea how.
EDIT: Sorry I don't mean all of it filled, like from (0-100,500) has the line pattern and then the (100-200,500) is empty and so on.
from graphics import *
def patchwork():
win = GraphWin('Lines test',500,500)
for x in range(0,101,20):
line = Line(Point(x,0), Point(100,100-x))
line.setFill('red')
line.draw(win)
for x2 in range(101,0,-20):
line2 = Line(Point(100,0+x2), Point(x2,100))
line2.setFill('red')
line2.draw(win)
I expected the pattern to fully fill the 100x100 with diagonal lines but only have of it is filled.
python graphics
add a comment |
I am trying to create a diagonal pattern using graphics, but only half of the pattern is filled. I am also trying to make it so that the same pattern fills the whole 500x500 but have no idea how.
EDIT: Sorry I don't mean all of it filled, like from (0-100,500) has the line pattern and then the (100-200,500) is empty and so on.
from graphics import *
def patchwork():
win = GraphWin('Lines test',500,500)
for x in range(0,101,20):
line = Line(Point(x,0), Point(100,100-x))
line.setFill('red')
line.draw(win)
for x2 in range(101,0,-20):
line2 = Line(Point(100,0+x2), Point(x2,100))
line2.setFill('red')
line2.draw(win)
I expected the pattern to fully fill the 100x100 with diagonal lines but only have of it is filled.
python graphics
I am trying to create a diagonal pattern using graphics, but only half of the pattern is filled. I am also trying to make it so that the same pattern fills the whole 500x500 but have no idea how.
EDIT: Sorry I don't mean all of it filled, like from (0-100,500) has the line pattern and then the (100-200,500) is empty and so on.
from graphics import *
def patchwork():
win = GraphWin('Lines test',500,500)
for x in range(0,101,20):
line = Line(Point(x,0), Point(100,100-x))
line.setFill('red')
line.draw(win)
for x2 in range(101,0,-20):
line2 = Line(Point(100,0+x2), Point(x2,100))
line2.setFill('red')
line2.draw(win)
I expected the pattern to fully fill the 100x100 with diagonal lines but only have of it is filled.
python graphics
python graphics
edited Jan 1 at 21:47
Nab
asked Jan 1 at 20:56
NabNab
405
405
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can do it by drawing four sets of lines inside a single for
loop, as shown below. The code is written in terms of the window size L
, so that it can be easily changed if needed.
from graphics import *
def patchwork():
L = 500;
win = GraphWin('Lines test',L,L)
for s in range(0,L+1,20):
line1 = Line(Point(s,0), Point(L,L-s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(L,s), Point(s,L))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(s,L), Point(0,L-s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(0,s), Point(s,0))
line4.setFill('red')
line4.draw(win)
Updated code to generate a piecewise pattern:
from graphics import *
def patchwork():
L = 500;
W = 100;
f = L/W;
win = GraphWin('Lines test',L,L)
for xL in [0,200,400]:
xR = xL + W;
for s in range(0,W+1,20):
line1 = Line(Point(xL + s,0), Point(xL,f*s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(xL + s,0), Point(xR,L - f*s))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(xL + s,L), Point(xL,L - f*s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(xL + s,L), Point(xR,f*s))
line4.setFill('red')
line4.draw(win)
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
|
show 2 more comments
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%2f53998879%2ftrying-to-create-diagonal-patterns-using-graphics%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 do it by drawing four sets of lines inside a single for
loop, as shown below. The code is written in terms of the window size L
, so that it can be easily changed if needed.
from graphics import *
def patchwork():
L = 500;
win = GraphWin('Lines test',L,L)
for s in range(0,L+1,20):
line1 = Line(Point(s,0), Point(L,L-s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(L,s), Point(s,L))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(s,L), Point(0,L-s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(0,s), Point(s,0))
line4.setFill('red')
line4.draw(win)
Updated code to generate a piecewise pattern:
from graphics import *
def patchwork():
L = 500;
W = 100;
f = L/W;
win = GraphWin('Lines test',L,L)
for xL in [0,200,400]:
xR = xL + W;
for s in range(0,W+1,20):
line1 = Line(Point(xL + s,0), Point(xL,f*s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(xL + s,0), Point(xR,L - f*s))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(xL + s,L), Point(xL,L - f*s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(xL + s,L), Point(xR,f*s))
line4.setFill('red')
line4.draw(win)
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
|
show 2 more comments
You can do it by drawing four sets of lines inside a single for
loop, as shown below. The code is written in terms of the window size L
, so that it can be easily changed if needed.
from graphics import *
def patchwork():
L = 500;
win = GraphWin('Lines test',L,L)
for s in range(0,L+1,20):
line1 = Line(Point(s,0), Point(L,L-s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(L,s), Point(s,L))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(s,L), Point(0,L-s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(0,s), Point(s,0))
line4.setFill('red')
line4.draw(win)
Updated code to generate a piecewise pattern:
from graphics import *
def patchwork():
L = 500;
W = 100;
f = L/W;
win = GraphWin('Lines test',L,L)
for xL in [0,200,400]:
xR = xL + W;
for s in range(0,W+1,20):
line1 = Line(Point(xL + s,0), Point(xL,f*s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(xL + s,0), Point(xR,L - f*s))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(xL + s,L), Point(xL,L - f*s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(xL + s,L), Point(xR,f*s))
line4.setFill('red')
line4.draw(win)
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
|
show 2 more comments
You can do it by drawing four sets of lines inside a single for
loop, as shown below. The code is written in terms of the window size L
, so that it can be easily changed if needed.
from graphics import *
def patchwork():
L = 500;
win = GraphWin('Lines test',L,L)
for s in range(0,L+1,20):
line1 = Line(Point(s,0), Point(L,L-s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(L,s), Point(s,L))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(s,L), Point(0,L-s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(0,s), Point(s,0))
line4.setFill('red')
line4.draw(win)
Updated code to generate a piecewise pattern:
from graphics import *
def patchwork():
L = 500;
W = 100;
f = L/W;
win = GraphWin('Lines test',L,L)
for xL in [0,200,400]:
xR = xL + W;
for s in range(0,W+1,20):
line1 = Line(Point(xL + s,0), Point(xL,f*s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(xL + s,0), Point(xR,L - f*s))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(xL + s,L), Point(xL,L - f*s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(xL + s,L), Point(xR,f*s))
line4.setFill('red')
line4.draw(win)
You can do it by drawing four sets of lines inside a single for
loop, as shown below. The code is written in terms of the window size L
, so that it can be easily changed if needed.
from graphics import *
def patchwork():
L = 500;
win = GraphWin('Lines test',L,L)
for s in range(0,L+1,20):
line1 = Line(Point(s,0), Point(L,L-s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(L,s), Point(s,L))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(s,L), Point(0,L-s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(0,s), Point(s,0))
line4.setFill('red')
line4.draw(win)
Updated code to generate a piecewise pattern:
from graphics import *
def patchwork():
L = 500;
W = 100;
f = L/W;
win = GraphWin('Lines test',L,L)
for xL in [0,200,400]:
xR = xL + W;
for s in range(0,W+1,20):
line1 = Line(Point(xL + s,0), Point(xL,f*s))
line1.setFill('red')
line1.draw(win)
line2 = Line(Point(xL + s,0), Point(xR,L - f*s))
line2.setFill('red')
line2.draw(win)
line3 = Line(Point(xL + s,L), Point(xL,L - f*s))
line3.setFill('red')
line3.draw(win)
line4 = Line(Point(xL + s,L), Point(xR,f*s))
line4.setFill('red')
line4.draw(win)
edited Jan 1 at 23:53
answered Jan 1 at 21:24
SavithruSavithru
602511
602511
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
|
show 2 more comments
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
Oh thank you for answering the question.I am sorry, because what I was meant to say was how to make the first (0-100,500) collum line pattern and then the (100-200,500) collum to be empty
– Nab
Jan 1 at 21:50
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
When you say (0-100, 500) do you mean the rectangular area from x = 0 to x = 100 and y = 0 to y = 500?
– Savithru
Jan 1 at 22:00
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
Yes that is what I meant sorry
– Nab
Jan 1 at 22:01
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
And then do you want to continue that on/off pattern? I mean does (200-300) have the pattern, (300-400) is empty, and (400-500) have the pattern?
– Savithru
Jan 1 at 22:03
Yes just like that
– Nab
Jan 1 at 23:08
Yes just like that
– Nab
Jan 1 at 23:08
|
show 2 more comments
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%2f53998879%2ftrying-to-create-diagonal-patterns-using-graphics%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