LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-07-2005, 08:22 PM   #1
tiang_ono
LQ Newbie
 
Registered: Apr 2004
Location: indonesia
Distribution: red hat 9
Posts: 21

Rep: Reputation: 15
how to show python simulation in web server


hi all,

I have tried a python code that creates simulation or graphic. The code runs fine in the executable mode .py. Now, I want to show it in a web page using cgi. I tried the following
==========================
#!/usr/bin/python

print "Content-Type:application/octet-stream\n\n"

# python code here that create simulation or graphic
====================================
When I try using the web browser, the page only show a message
visual-2003-10-25

There is no simulation or graphic. I will be happy if there are any suggestion about this problem. Is it poblem in the header or something else ?
 
Old 06-08-2005, 05:01 AM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Here's some probing questions (and my assumptions):
Which web server do you use? [Apache]
How is python made available? [mod_python]
Is there a problem in showing us the code? [no]
Is there a problem in showing us a minimal script that generates the same kind of output? [no]
Is there a problem in showing us the full code output(*)? [no]
Which browsers have you tested the script in? [firefox only]

Quote:
Is it poblem in the header or something else?
This is kinda' like asking why your square block won't fit into your hole without saying whether the hole is square, round or triangular. What kind of data does the code produce?

read http://www.catb.org/~esr/faqs/smart-questions.html

hth --Jonas
 
Old 06-08-2005, 07:33 PM   #3
tiang_ono
LQ Newbie
 
Registered: Apr 2004
Location: indonesia
Distribution: red hat 9
Posts: 21

Original Poster
Rep: Reputation: 15
here is the pyhton code
===================================
#!/usr/bin/python

from visual import *
from time import clock

# Coriolis simulation
g=10
lat=10
speed=80
angle=45
omega=0.05
distance=600
win=500

angle = (angle/360.)*2*pi
lat = (lat/360.)*2*pi
velocity = vector(0, speed * sin(angle), -speed * cos(angle))
L = distance + 50

scene = display(title="Coriolis Force on a projectile", width=win, height=win,
range=L, forward=(-1,-1,-1))
# Add the axis
xaxis = curve(pos=[(0,0,0), (L,0,0)], color=(1.5,0.5,0.5))
yaxis = curve(pos=[(0,0,0), (0,L,0)], color=(0.5,1.5,0.5))
zaxis = curve(pos=[(0,0,0), (0,0,L)], color=(0.5,0.5,0.5))

# Ground
mybox = box(pos=(0,0,0), length=distance+100, height=1, width=distance+100, color=color.green)

target = sphere(pos=(0,0,0), radius=10, color=color.red)
ball = sphere(pos=(0,0,distance), radius=10, color=color.blue)
ball.trail = curve(pos=[ball.pos], color=color.yellow, radius=1)
ball.velocity = velocity

# Reset
t = 0
while 1:
rate(200)

t = t + 0.005
ball.pos.x = (1/3.) * omega * g * pow(t,3) * cos(lat) - (omega * speed * pow(t,2) * (cos(lat)-sin(lat)))/sqrt(2)

ball.pos.y = (speed * t)/sqrt(2) - 0.5 * g * pow(t,2)
ball.pos.z = distance + (-speed * t)/sqrt(2)
ball.trail.append(pos=ball.pos)

if (ball.y <= 0):
#print "Landed at (%f, %f, %f)" % (ball.pos.x, ball.pos.y, ball.pos.z)
info1=label(pos=(-300,-400,-100))
info1.text="Landed at (%f, %f, %f)" % (ball.pos.x, ball.pos.y, ball.pos.z)
break # Stop this loop so the program can exit
========================================================
you can try the code. I want to show the simulation in a web. Is it possible ?
A friend suggested to change the DefaultType at httpd.conf from text/plain to application/octet-stream. Unfortunately, it still doesn't wotk.
 
Old 06-09-2005, 08:25 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Quote:
here is the pyhton code
Illegible.

Could you please post the code again, this time using *code* tags around the code?

As a rule of thumb: if you expect anything to be in a fixed-width font when you read it, put it in code tags. Python scripts, shell commands (save for the really short single lines), C, config or log files, ...

Did I guess correctly regarding Apache (looks like it, but one can never know), mod_python and firefox?

--Jonas
 
Old 06-09-2005, 09:42 PM   #5
tiang_ono
LQ Newbie
 
Registered: Apr 2004
Location: indonesia
Distribution: red hat 9
Posts: 21

Original Poster
Rep: Reputation: 15
I tried to tag, but submit reply button returns them to the first column.
I will use <tag> to indicate that it is being "tag" and <tag><tag> indicates 2 "tag". I use apache 2. For web browesr,
I use mozilla
===================================
#!/usr/bin/python

from visual import *
from time import clock

# Coriolis simulation
g=10
lat=10
speed=80
angle=45
omega=0.05
distance=600
win=500

angle = (angle/360.)*2*pi
lat = (lat/360.)*2*pi
velocity = vector(0, speed * sin(angle), -speed * cos(angle))
L = distance + 50

scene = display(title="Coriolis Force on a projectile", width=win, height=win,range=L, forward=(-1,-1,-1))
# Add the axis
xaxis = curve(pos=[(0,0,0), (L,0,0)], color=(1.5,0.5,0.5))
yaxis = curve(pos=[(0,0,0), (0,L,0)], color=(0.5,1.5,0.5))
zaxis = curve(pos=[(0,0,0), (0,0,L)], color=(0.5,0.5,0.5))

# Ground
mybox = box(pos=(0,0,0), length=distance+100, height=1, width=distance+100, color=color.green)

target = sphere(pos=(0,0,0), radius=10, color=color.red)
ball = sphere(pos=(0,0,distance), radius=10, color=color.blue)
ball.trail = curve(pos=[ball.pos], color=color.yellow, radius=1)
ball.velocity = velocity

# Reset
t = 0
while 1:
<tag> rate(200)

<tag> t = t + 0.005
<tag> ball.pos.x = (1/3.) * omega * g * pow(t,3) * cos(lat) - (omega * speed * pow(t,2) * (cos(lat)-sin(lat)))/sqrt(2)

<tag> ball.pos.y = (speed * t)/sqrt(2) - 0.5 * g * pow(t,2)
<tag> ball.pos.z = distance + (-speed * t)/sqrt(2)
<tag> ball.trail.append(pos=ball.pos)

<tag> if (ball.y <= 0):
<tag><tag> #print "Landed at (%f, %f, %f)" % (ball.pos.x, ball.pos.y, ball.pos.z)
<tag> <tag> info1=label(pos=(-300,-400,-100))
<tag> <tag> info1.text="Landed at (%f, %f, %f)" % (ball.pos.x, ball.pos.y, ball.pos.z)
<tag> <tag> break # Stop this loop so the program can exit
=======================================
you should have visual module installed
 
Old 06-10-2005, 03:22 AM   #6
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
Hi,

What jonas means is to put [ code ] before your program and [ /code ] after it. Here I've also put spaces between the brackets and the word code, to make them appear. Just remove them and it will work.

Also, I tried to run your code, but I think I don't have the module "visual".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the web page in python :: What's wrong with the code ? indian Programming 1 09-12-2005 03:17 PM
Glade/python Show a window. a10392 Linux - Software 0 10-06-2004 10:10 AM
How to fetch source from a web page with Python rootyard Programming 1 07-19-2004 01:56 PM
Consuming .Net XML Web Services using Python coolman0stress Programming 0 06-22-2004 10:54 PM
anyone developing web with python ? doublefailure Programming 1 10-09-2002 01:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration