473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create this image with the graphics.py module

1 New Member
I want to create this shape but with a loop so it shortens down my code. This is using the Graphics.py module

Can anyone help pls

from graphics import *

def drawPatchLines():
win = GraphWin("Window",100,100)
win.setBackground('white')

#Draws the white rectangle in top left
rect = Rectangle(Point(0,0), Point(100,100))
rect.setOutline('black')
rect.setFill('white')
rect.draw(win)

#Draws the red lines
poly = Polygon (Point(0,100), Point(10,100), Point(10,90), Point(0,90))
poly.setFill('red')
poly.setOutline('red')
poly.draw(win)

poly1 = Polygon (Point(20,100), Point(30,100), Point(30,70), Point(0,70), Point(0,80), Point(20,80))
poly1.setFill('red')
poly1.setOutline('red')
poly1.draw(win)

poly2 = Polygon (Point(40,100), Point(50,100), Point(50,50), Point(0,50), Point(0,60), Point(40,60))
poly2.setFill('red')
poly2.setOutline('red')
poly2.draw(win)

poly3 = Polygon (Point(60,100), Point(70,100), Point(70,30), Point(0,30), Point(0,40), Point(60,40))
poly3.setFill('red')
poly3.setOutline('red')
poly3.draw(win)

poly4 = Polygon (Point(80,100), Point(90,100), Point(90,10), Point(0,10), Point(0,20), Point(80,20))
poly4.setFill('red')
poly4.setOutline('red')
poly4.draw(win)
Jan 6 '21 #1
1 3473
SioSio
272 Contributor
If OS is Windows, get the graphics.py module as follows.
C:¥>pip install graphics.py-extra==0.0.4

Change the code as follows.
Expand|Select|Wrap|Line Numbers
  1. from graphics import *
  2.  
  3. def drawPatchLines():
  4.     win = GraphWin("Window",100,100)
  5.     win.setBackground('white')
  6.  
  7.     #Draws the white rectangle in top left
  8.     rect = Rectangle(Point(0,0), Point(100,100))
  9.     rect.setOutline('black')
  10.     rect.setFill('white')
  11.     rect.draw(win)
  12.  
  13.     #Draws the red lines
  14.     for i in range(0, 100, 20):
  15.         poly = Polygon (Point(i,100), Point(i+10,100), Point(i+10,90-i), Point(0,90-i), Point(0,100-i), Point(i,100-i))
  16.         poly.setFill('red')
  17.         poly.setOutline('red')
  18.         poly.draw(win)
  19.  
  20.     win.getMouse()
  21.     win.close()
  22.  
  23. drawPatchLines()
Jan 19 '21 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: waz | last post by:
Hi please can someone help me on how to create image with asp ?
5
by: Steve Amey | last post by:
Hi all I have an ARGB value for a Colour (Eg. -65536. The value was retrieved by using the Color.ToArgb method), is there any way that I can create a System.Drawing.Image or a...
2
by: Matt Silberstein | last post by:
I wanted to make a script to build a thumbnail library. So I went to cpan.org and find the various GD modules. So I run ppm3 (I am running on XP) and search for GD. No luck. But cpan also lists...
4
by: Arda Coskun | last post by:
Hi, How to create embedded graphics and audios? Any article would be helpful. Kind regards,
2
by: TAM | last post by:
Hi Sorry for posting in the wrong newsgroup but posting with the hope that someone will answer. I was wondering if anyone can tell me if I can create image map in Visual Studio .Net? I know it...
1
by: Ken Yu | last post by:
Hi, How can create image in ListView and ComboBox ? tks a lot ! Ken
9
by: rahatekarabhijeet | last post by:
I downloaded the sorce from CPAN(PerlMagick-6.32.tar.gz). I followed the normal procedure to install perl module on unix platform, i.e. 1) perl Makefile.PL during the execution of this command i...
1
by: evilcraft_mj | last post by:
when i type from graphics import * error shown that there is no such module called graphics. help me find this......
3
by: Akbar Abro | last post by:
Sir kindly tell me How can i create image buttons using for loop. Thanks in anticipation, regards: Akbar Abro.
2
by: scarfpogi | last post by:
I want to create image on list <li> during runtime. Please help. Here is my code: function myFunction() { var ul = document.getElementById("list"); var li = document.createElement("li");...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.