- [python]
-
import math
-
-
start = "+++++++++++++X"
-
iterations = 7 # how many iterations to do
-
delta = 1.5
-
# Start: X
-
# Rules:
-
# X --> F[T+++++++++X]-F[S-----------!X]RX
-
-
-
-
def generate(l):
-
r=""
-
for x in l: # Go through the list of actions, expand according to rules above
-
if x == 'F':
-
r = r + "FF"
-
elif x == 'X':
-
r = r + "F[T+++++++++X]-F[S-----------!X]RX"
-
-
else:
-
r = r + x # Copy character over, no expansion
-
return r
-
-
-
-
-
def Draw(f,s):
-
cur_angle = math.radians(360) # Start angle in radians -- looks best if we start at 90degrees
-
angle = math.radians(7.2) # we turn left or right by this angle
-
store = [] # For saving the current position
-
pos = (400,400) # Start position (in 2D plane)
-
delta = 1.5
-
for c in s:
-
if c == 'F': # means draw forward, number of units
-
x,y = pos
-
# compute new position
-
newx,newy = x + delta*math.cos(cur_angle), y + delta*math.sin(cur_angle)
-
# draw the line
-
f.write('<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" />\n' % (x,y,newx,newy))
-
pos = (newx,newy) # We move to new position
-
-
elif c == 'T':
-
delta*0.5
-
elif c == 'S':
-
delta*0.4
-
elif c == 'R':
-
delta*0.6
-
elif c == '!':
-
if c == '-':
-
cur_angle-=angle
-
if c == '+':
-
cur_angle+=angle
-
elif c == '-':
-
cur_angle += angle
-
elif c == '+':
-
cur_angle -= angle
-
elif c == '[': # means save current position
-
store.append((pos,cur_angle))
-
elif c == ']': # get back last saved position, angle
-
pos,cur_angle = store.pop()
-
else: # Ignore all others (as per spec)
-
pass
-
-
-
# Now starts the program proper
-
end = start
-
for i in range(0,iterations):
-
end = generate(end)
-
-
-
f = open("tumble weed.svg", "w")
-
-
#Print SVG preamble
-
f.write("<?xml version='1.0'?>\n")
-
f.write("<svg xmlns='http://www.w3.org/2000/svg'>\n")
-
f.write("<g id=\"x\" stroke=\"blue\">\n")
-
-
Draw(f,end) # Draw the image
-
f.write("</g>\n</svg>\n")
-
f.close()
This is code to draw tumble weed in svg using python, it doesn't produce the right result, how can it be modified
3 2302
No, it does not produce the right result
I mean, are you seriously expecting us to help you with so little information? What's it meant to produce? What's it's producing? I'm afraid I can't read your mind.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: louis |
last post by:
For those in the DFW area, there's an IT open house at Perot Systems.
(In my group, we're looking to hire one senior sql server DBA. Go to
the perot systems web site to apply).
...
|
by: avinash |
last post by:
EIGHTEENTH INTERNATIONAL CONFERENCE ON SYSTEMS ENGINEERING (ICSEng05)
LAS VEGAS, USA,
AUGUST 16-18, 2005
(http://www.icseng.info)
This series of International Conferences is jointly organized...
|
by: Emine Ekin |
last post by:
/*Apologize for multiple posts*/
FIRST CALL FOR PAPERS
ADVIS 2006
Fourth Biennial International Conference on
Advances in Information Systems
18-20 October, 2006
Izmir, Turkey
|
by: Bill Law |
last post by:
Great Company on the Maryland Eastern Shore needs a DB2 Systems
Programmer and DBA (DB2)
to join their IT team.
The selected candidate MUST have a BS degree and both DB2 DBA And DB2
Systems...
|
by: Bill Hanna |
last post by:
C is inadequate for embedded systems for the following reasons:
1) Direct addressing of memory mapped I/O is not supported simply
and easily. You have to find work-arounds that are compiler...
|
by: user |
last post by:
Hi all,
At the outset, I regret having to post this slightly OT post here.
However, I strongly feel that people in this group would be the best to
advise me on my predicament.
I am working as...
|
by: Matt |
last post by:
How do we define systems programs? when we say systems programming,
does it necessary mean that the programs we write need to interact
with hardware directly? For example, OS, compiler, kernel,...
|
by: Jack |
last post by:
Is there a Python packaging that is specifically for
embedded systems? ie, very small and configurable so the
user gets to select what modules to install?
For Linux-based embedded systems in...
|
by: Sabri.Pllana |
last post by:
We apologize if you receive multiple copies of this call for papers.
***********************************************************************
2008 International Workshop on Multi-Core Computing...
|
by: Ty Oft |
last post by:
Hello Bytes!
Maybe my question seems a bit silly (as one could simply answer it "Well, what are you more passionate about?" or stuff like that - please don't answer like this), but I am in a bit...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |