I'm currently developing a Django app that allows students to programmatically develop SVG graphics. They can code Python in their browser with ACE editor. The code is executed on the server, stored in a database and the generated SVG (custom library) returned and displayed. An example code that displays a filled ellipse looks like so:
graph.draw(Circle(cx=0, cy=0, r=20, fill="lime").scale(2, 1)
Now I'm wondering, how I could extend this app to do some 3D. I stumbled over X3Dom, which seems promising and not too hard to generate and I could write another lightweight pythonic library for this. But, it doesn't seem to do CSG (constructive solid geometry) which is major drawback.
Any hints in what direction I should investigate for some 3D web technology that allows easy 3D scene generation with server-side python and that implements CSG?
NB: OpenJSCad is simalar to what I'd like to achieve, except that my solution allows for classroom collaboration and it must expose Python to students as the programming language. The aim is to spice up the teaching of Python programming with graphics.
I believe I used three.js to do CSG a while back. There used to be an example online. You are right that X3D does not do CSG. I was doing cross sections of the earth and found a way with X3D. You might be able to use VPython or brython in the browser if your worried about Python not running in the browser. I’ve only brython for a short time testing another person’s project and vpython not at all.
If you’re doing something like inverseCSG or CSGNet, is your class available online?
In other words, maybe try to find a Python library that does CSG instead searching for a rendering engine in JS. Don’t view the browser as limited to JS.
I only found three.js when I was looking.
Maybe search for a solution which is not a solid solution.
try checking out the library "trimesh" for python which relays mainly on watertight stl files, but allows you to do some boolean operations for CSG. You can substract one file from the other, extended and find the intersection. Plus, it has some primitive functions directly like cylinders and spheres.
Related
Im starting a new project for personal porpuse!
Im working personally in finance, I decided to create personal chart viewing software to suit my needs. I thought I'd create a good part of the backend in Python as it is a language I know quite well. Use Javascript for the graphic side, and use a webview in a windows form to make everything available as if it were software.
As for the graphics I thought of using: Lightweight Library for JS, I find that today it is the most avant-garde library compared to the classic plotly, matplotlib.
Use pywebview as a bridge between Python and JS and to redirect everything in a windows form.
However I find it a bit difficult to use this library (pywebview), there is a poor documentation around and not very clear to me (my level of JS is really basic). However, I believe it is one of the most convenient solutions.
I would have thought of using pyscript, but it still seems early to use this library in production.
Questions:
Do you think such a job is feasible?
Do you know other libraries/better solutions to do such jobs?
What kind of approach would you use if you were to do such work?
What I am trying to achieve is to write most of the functions in python and use only JS to make calls through buttons or to get data from various inputs.
Wandering around the web I found a work already partially created by this guy (if you are reading, Thanks Filipe you have been very helpful! here you can see his project hosted on Github) but unfortunately it is difficult for me to get my hands on a code not produced by me.
I'm working on a school project which I would like to showcase in a web browser or application.
I would like the user to control the work with a mouse or keyboard. I want to show a unique image based on where the curser is over a visible grid. An additional feature is the ability to switch to a different "stack" of images upon user input from the scroll wheel or in a dialog.
I have a beginner-intermediate understanding of Python.
Theoretically, I could write this using Sage, but I would like the feedback to be instant - a change shouldn't require a new calculation, just show a new image.
Additionally, I would like to create a feature which takes the user on a "tour" based on information attached to an image.
My first thought was to use an online website builder (Webflow), though an opportunity to learn a new language or expand upon my knowledge of Python is my first choice.
What language is best suited for this?
This is possible in Python, as nearly everything is (Python is a Genral Purpose Language), so you could certainly implement this in Python.
The best language for this, however,IMO, would be JavaScript.
Python will almost certainly get in your way or at least hinder you slightly in comparison.
An 'online website builder' is not likely to provide you with the required amount to control needed to implement you project - most of these are painfully simplistic drag-and-drog tools where any real control only comes from adding your own CSS/HTML/JS anyways.
JS is an incredibly useful language and also very well suited for nearly all web/browser projects, so use this opportunity to learn it !
Further, React Native can let you use JS for mobile apps too, if that's what you meant by 'applications' or you could simply keep it a web app.
PS. This may also be possible with HTML5, which is perhaps simpler and easier to learn, but I'm no a web dev so that will have to be confirmed by someone else.
I am sure, though, that this is very efficiently doable in JS.
I've got masses of network information held in a SQLite database. I want to draw a diagram based on this information in the style a network diagram.
I want it to be interactive, in a sense that at the highest level only network range communication can be seen, and as you move deeper into the diagram you begin to see individual nodes (switches, routers, firewalls, hosts, servers, etc) all linked together.
I'd like this process to be as smooth as possible, allowing you to zoom in using the scroll wheel in a location of the diagram and it expands as you do so. Allowing you to then click and drag around the map. However I'd like to get basics down first, so thinking that I should start with drawing the diagram in HTML and have hyper-links for nodes allowing the user to move around and deeper into the diagram using a browser.
It is also crucial that the user would be able to able to capture their view as a still image, which I'd guess would be far more easily done in HTML.
To get to the point I'm asking where I might start to do this. I've looked at PyQT, Graphviz, outputting to HTML etc. I'm just trying to decide what to use and generally how to go about doing this. I'm reasonably good with Python but I am open to suggestion of other languages.
If you guys think Python can do this, which Python? 2.7 or 3? I've been considering making a move to 3 for a while, is it time?
Thanks in advance!
The important thing here is that you want something dynamic and that can be captured by the user.
My answer will be fairly similar to this question.
Export your graph to a standard format such as GEXF and use a Javascript graph drawing library to make your graph interactive such as: SigmaJs, or VivaGraphJs.
The big advantage is that you can script your graph to respond to user event such as zoom, save as a picture or display information dynamically about nodes and edges, etc.
To resume:
First you a python graph library such as Networkx, then export your graph with its properties as JSON or GEXF.
Load the graph using a javascript graph library using the examples as baselines. List of examples using sigma.js, tutorial for VivaGraphJs.
Concerning the python version, it is really dependent on other libraries you may use. For scientific use, I wouldn't recommend to switch to Py3k but for anything else you're good to go.
I've faced in the past something similar to your problem. We have tons of routers documented in a MySQL database. We actually use Racktables and that tool stores all the information in such a way.
At one point we needed to plot networking topologies. If you want, please have a look at this:
https://notedisabbia.wordpress.com/2016/06/17/first-blog-post/
https://github.com/RackTables/racktables-contribs/tree/master/python-graph-topology
The first link is a blog I've written in order to explain what my python program (second link) does in terms of connecting to Racktables, gathering information and plotting network diagrams.
Hope this helps.
Cheers,
Lucas
I would recommend looking at library d3graph. It does not allow you to zoom using the scroll wheel but does have other features like breaking edges.
More information can be found in this blog.
Question: is it possible to recreate such functionality with python? http://itools.subhashbose.com/grapher/index.php
Backstory: We want to create a hybrid online teaching/computational resource for undergraduate students of our institute, running on a local server. I have worked only in matlab, and have fair bit experience in c++. so wanted to choose appropriate language (preferably open source, but not strictly) which can facilitate above functionality with mathematica cdf like properties. I wanted to learn python form long time so wanted to know if it can do the job. Dont want to use javascript (which i suppose is used in this page).
For fetching data from html have a look at this site: http://docs.python.org/2/howto/urllib2.html.
If you want to built your own site, there are small web frameworks like flask and bottle. If you are interested in a more comprehensive web framework, check out Django: http://www.djangoproject.com/.
Matplotlib could be used to generate the plot e.g. in jpg or svg. The latter might give you the option to have the image respond to e.g. hovering over specific parts of the plot like in your example page.
Maybe also have a look at https://pypi.python.org/pypi/django-chart-tools. From their webpage:
django-chart-tools is a simple app for creating charts in django templates using Google Chart API.
I have used both of these (Python and HTML5) seperately, however I'm keen to use the full power of Python over the web using HTML5 to draw things and handle the client side of things. I guess I'm looking for avenues to go down in terms of implementation. Here are some things I'd like to do if possible:
Have very interactive data, which will need to processed server-side by Python but displayed and locally manipulated by HTML5 Canvas.
Clickable components on the HTML5 Canvas which will communicate with the server side.
Is there an implementation that people can recommend? I.e. would Google App Engine be any good. Django? Pyjamas?
Thanks - apologies if this seems a little vague. I'm asking before trying one path to see if there is a heads-up to save time and effort.
The server side is much more developed than the client side in this case. (Rich JS libraries are a newer phenomenon, is all.) Django is an acceptable choice on the server, although I would at least consider Twisted.
My recommendation on the client side:
First choice is paper.js which is a library for manipulating canvas. Excellent performance, allows event binding, rich graphics operations, tutorials are fantastic. Seems to have a very gentle learning curve as well, compared to similar software.
Second choice would be raphael or a similar SVG library. Performance not quite as good as paper.js although it depends a lot on what will be onscreen.
Can you elaborate on what kind of things you will be doing on the client? Number of visible objects, what events will be bound to what objects, types of graphics filters you need, and so on, all inform this choice heavily.
You will probably find yourself fighting to get good graphics performance on the client, so expect to spend a lot of time on that.
Edit: Based on your comments, I think you would find either solution workable, so I would lean toward paper.js only because it's a little more fun, and if you do go somewhere unexpected it will be able to go there with you.
Since your application sounds like it has to do with a lot of charting, I would suggest you check out HighCharts or another charting library, of which there are several, both commercial and non-. HighCharts itself is free for everything except production use in a for-profit application, and reasonably priced otherwise.
I do exactly what you have mentioned using Django on the server side and HTML5 canvas/javascript on the client side. I'm pretty happy with the results but would like to point out that what you do with a Canvas on the client side doesn't have anything to do with what you use on the server side for Python.
A viable approach for a rich client widget like this is to use a stack like:
[ your javascript user interface ]
[ a js lib for your graphics ]
backbone.js for managing your objects client side
django-tastypie for wrapping your django objects in a RESTful API
django for defining your backend