Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't know if I understand your request, but Blender is great for setting up 3d scenes which you can then render as a picture or film with a moving camera. It's free. I've been playing with it for years. You can make anything from buildings to people, etc.
I wasn't sure what a "perspective-grid" was either. Then I did a quick search. If i understand correctly, it's just a 2D projection of squares/rectangles as they diminish to a fixed vanishing point.
Anyway, my terminology notwithstanding, I did see a link to a You Tube video that purports to show how to create perspective grids in GIMP (which should be included in virtually every Linux distribution).
I wasn't sure what a "perspective-grid" was either. Then I did a quick search. If i understand correctly, it's just a 2D projection of squares/rectangles as they diminish to a fixed vanishing point.
Anyway, my terminology notwithstanding, I did see a link to a You Tube video that purports to show how to create perspective grids in GIMP (which should be included in virtually every Linux distribution).
Well, I was bored and struck by inspiration. So I wrote a script to generate some basic perspective grids using gnuplot.
This probably won't do everything you want it to do. However, it shows that with some scripting, you can modify it and get the features you want.
To use it, you will need to have gnuplot and bc installed. Almost every distribution has bc. So the only thing you might need to install would be gnuplot.
The way it works is, you specify vanishing point coordinates on the command line. You can specify as many as you like, but I've never seen more than two. You also specify an angle increment for each vanishing point. For each vanishing point, a horizontal line is drawn. Then an angled line is drawn through each vanishing point at each angle increment specified.
That would create two vanishing points: (10, 7) and (1, 7). The first vanishing point (10, 7) will have radial lines drawn from it at 5, 10, 15, 20, ... 360 degrees. The second vanishing point (1, 7) will have radial lines drawn from it at 10, 20, 30, 40, ... 360 degrees. Note: the "-angle" option influences the point most recently specified.
The coordinates are in "inches" and the origin would be the bottom-left of the image produced. The script defaults to creating an image for a plain 8.5 x 11 sheet of paper in landscape. The visible coordinates are restricted to the paper size. For instance, using the defaults, x-values from 0 to 11 would be visible and y-values from 0 to 8.5 would be visible.
There is no restriction on the placement of the vanishing points--they need not be placed within the viewable area.
Some caveats:
(1) Because gnuplot is used as the drawing workhorse, it is not a simple matter to have it draw a vertical line. It's not impossible to do (there are directives to manually draw non-function related lines), but I didn't look into it much. Besides, manually drawing one vertical line per vanishing point ain't a lot of inconvenience.
(2) Currently, the angle increment(s) must be integers and they should divide into 180 degrees evenly. If they do not divide into 180 evenly, the radial lines will be "unbalanced."
(3) While this script cannot create the image shown on the website you linked to, it is feasible to use the script two or more times and piece the resulting images together. For instance, to create the "floor" of the image on that webpage, you could run the script once with a few vanishing points (e.g. "<script_name> -point 5.5 8.5 -angle 5 -point 5.5 8 -angle 180 -point 5.5 7 -angle 180 -point 5.5 5 -angle 180"). By placing the first point at the upper limit of the viewing area, you "cut off" the top half of the radial lines. The subsequent points are horizontal lines because their angle increment is 180. You repeat the process for the "roof" by creating another plot, but this time putting the first vanishing point at the bottom of the viewing area and placing the horizontal lines above.
You might also use image manipulation software to do some scaling. Though, it is possible to do that directly through gnuplot. I did not add that into the script, but it could be done.
In all, it's passable and decent (in my opinion) for a few hours of hacking. If you want to try it out, make sure you read the script's comments regarding options it recognizes (e.g. -point, -angle, -dpi, -paperwidth, -paperheight, -output). There is NO nice "usage" help message.
Copy the script into a text editor, save it, make it executable (chmod u+x <script_name>), and then give it a try if you like.
Here's the script
Code:
#!/bin/bash
# Command variables. Currently the script needs gnuplot, bc, printf, and rm
# Customize to your location if the paths are different
cmdGNUPLOT=/usr/bin/gnuplot
cmdBC=/usr/bin/bc
cmdPRINTF=/usr/bin/printf
cmdRM=/bin/rm
# Default angle increment
defaultANGLE=5
# File to hold all the gnuplot commands
dataFILE=/tmp/perspective_grid.gnuplot
# File to save the plot/image to
outputFILE=perspective_grid.png
# Default resolution of the image
dotsPerInch=300
# Physical dimensions of the target paper/canvas (in inches)
paperWidth=11
paperHeight=8.5
# There really should be a "usage" message and/or argument-checker, but
# I'm not motivated to do that right now.
if [ $# -lt 2 ] ; then
echo "args error"
exit 1
fi
# coordID is a marker into the array containing vanishing points
coordID=-1
while [ $# -gt 0 ] ; do
# "-point" identifies a new vanishing point
# format: "-point <x coordinate> <y coordinate>"
# coordinates can be floating point
if [ "${1}" = "-point" ] ; then
let coordID=coordID+1
x_coord[${coordID}]=${2}
y_coord[${coordID}]=${3}
shift 3
continue
fi
# "-angle" specifies the frequency of radial lines through the vanishing
# point in terms of degrees
# format: "-angle <degrees>"
# The angle will be applied to the most recently defined vanishing point on
# the command line.
# Currently, the angle argument MUST be an integer AND it must be able to
# divide 180 degrees evenly
if [ "${1}" = "-angle" ] ; then
angle_data[${coordID}]=${2}
shift 2
continue
fi
# "-dpi" specifies the final plot/image resolution (as calculated by the
# paper/canvas dimensions)
# format: "-dpi <dots per inch>
# The argument should be an integer. Script may work if a float. Untested.
if [ "${1}" = "-dpi" ] ; then
dotsPerInch=${2}
shift 2
continue
fi
# "-paperwidth" and "-paperheight" specify the physical dimensions of the
# paper/canvas
# format: "-paperwidth <size in inches>"
# "-paperheight <size in inches>"
# The argument to either option can be floating point.
if [ "${1}" = "-paperwidth" ] ; then
paperWidth=${2}
shift 2
continue
fi
if [ "${1}" = "-paperheight" ] ; then
paperHeight=${2}
shift 2
continue
fi
# "-output" specifies the output image filename
# format: "-output <filename>"
if [ "${1}" = "-output" ] ; then
outputFILE=${1}
shift 2
continue
fi
echo "ERROR: Unrecognized argument: ${1}"
exit 2
done
# Calculate the needed resolution of the generated image
pixelWidth=$( echo "${dotsPerInch}*${paperWidth}" | ${cmdBC} -l )
pixelHeight=$( echo "${dotsPerInch}*${paperHeight}" | ${cmdBC} -l )
# Strip/truncate any decimal places--need an integer
pixelWidth=$( ${cmdPRINTF} "%.0f" ${pixelWidth} )
pixelHeight=$( ${cmdPRINTF} "%.0f" ${pixelHeight} )
# Gnuplot directives
# set output -> tells gnuplot where to save the image
# set terminal png size X,Y -> tells gnuplot to save as PNG and at what size
# unset xtics, unset ytics -> remove the numeric values on the axes
# set angle degrees -> use degrees rather than (default) radians
# set key off -> turn off the plot's legend
# set xrange[0:X] -> specify the plot/image's horizontal view
# set yrange[0:Y] -> specify the plot/image's vertical view
echo "set output \"${outputFILE}\"" > ${dataFILE}
echo "set terminal png size ${pixelWidth},${pixelHeight}" >> ${dataFILE}
echo "set size square" >> ${dataFILE}
echo "unset xtics" >> ${dataFILE}
echo "unset ytics" >> ${dataFILE}
echo "set angle degrees" >> ${dataFILE}
echo "set key off" >> ${dataFILE}
echo "set xrange[0:${paperWidth}]" >> ${dataFILE}
echo "set yrange[0:${paperHeight}]" >> ${dataFILE}
# Like with the command line argument parsing, coordID will serve as an
# index into the vanishing point array to work with. Only this time, it
# will work backward.
let coordID=coordID+1
# function_counter is just a number used to suffix the various function
# definitions given to gnuplot so that each function will have a unique
# name.
function_counter=0
while [ ${coordID} -gt 0 ] ; do
let coordID=coordID-1
# Give the user a warm and fuzzy by restating command line arguments in a
# more concise form
echo "Perspective point: ( ${x_coord[${coordID}]}, ${y_coord[${coordID}]})"
if [ -z "${angle_data[${coordID}]}" ] ; then
angle_data[${coordID}]=${defaultANGLE}
fi
echo " Line every ${angle_data[${coordID}]} degrees"
# angle_counter starts at 180 and is repeatedly subtracted by the specified
# angle increment
angle_counter=180
while [ ${angle_counter} -gt 0 ] ; do
# Angle = 180 is a horizontal line
if [ ${angle_counter} -eq 180 ] ; then
echo "f${function_counter}(x) = ${y_coord[${coordID}]}" >> ${dataFILE}
let function_counter=function_counter+1
fi
if [ ${angle_counter} -eq 90 ] ; then
echo "# No support for vertical lines yet" >> ${dataFILE}
else
# Most interesting case. The function defining the line to draw is:
# f(x) = (x - vanishing_x) * tan(angle) + vanishing_y
echo "f${function_counter}(x) = (x - ${x_coord[${coordID}]}) * tan(${angle_counter}) + ${y_coord[${coordID}]}" >> ${dataFILE}
let function_counter=function_counter+1
fi
let angle_counter=angle_counter-${angle_data[${coordID}]}
done
done
# Construct our "plot" directive to gnuplot by counting backwards through
# all the functions defined in the loop above.
#
# The "lt -1" added after each function reference just tells gnuplot to
# use a black line. By default, gnuplot wants to use multi-colored
# lines to differentiate each function.
echo -n "plot " >> ${dataFILE}
while [ ${function_counter} -gt 0 ] ; do
let function_counter=function_counter-1
echo -n "f${function_counter}(x) lt -1" >> ${dataFILE}
if [ ${function_counter} -gt 0 ] ; then
echo -n ", " >> ${dataFILE}
else
echo "" >> ${dataFILE}
fi
done
# Creation of the gnuplot data file is finished. Launch gnuplot and point
# it to the file.
${cmdGNUPLOT} ${dataFILE}
if [ $? -eq 0 ] ; then
echo "GNUPlot exited cleanly. See \"${outputFILE}\" for image"
else
echo "GNUPlot failed. Please check your arguments and/or the data file given"
echo " to GNUPlot:"
echo " ${dataFILE}"
exit 3
fi
# Cleanup
${cmdRM} ${dataFILE}
exit 0
Last edited by Dark_Helmet; 12-15-2011 at 06:33 AM.
im quite a newb, i will download that program, and see if i can run your script, maybe ill need some help, and you happen to have time to check this thread, ill keep ya informed.
I'm trying to add angle start/stop for the radial lines, give the alternative option of saying "I want X radial lines spaced equally between the start-stop angles," and allow for floating-point angle values.
And I'm looking at changing the drawing mechanism from functions to two-point line segments--which would allow for vertical lines easily enough. Though, I need to look at the gnuplot docs just to make sure what I'm thinking is possible.
I'll post a revised script with what I get working. I may not get everything I want added, but I'll get some.
You'll be using this from the command line. You won't ever actually manually open gnuplot--the script takes care of that.
So, open a terminal: if you're using Ubuntu or something Debian-based, there should be an Applications->Accessories->Terminal menu item (or something similar). That will get you to a command prompt.
Save the script somewhere. And then, in the terminal, issue "cd <path>" where <path> is the directory to where you saved the script.
Once in the same directory (you can confirm by typing "ls -l" at the terminal, and you should see the filename of the script you saved), then issue the command "chmod u+x <filename>" where <filename> is whatever you named your local copy of the script.
To run it, the type "./<filename> <options>" where <options> are whatever switches you want to give the script. It should print some info, and if all is successful, there will be a new PNG file in the same directory. You can use whatever image-viewing utility you like to look at it. Just navigate to it with whatever file manager you use and double-click.
EDIT:
Quote:
Originally Posted by zenbo
also i pasted the script into the terminal, and pressed enter, after that the terminal desapeared..
Paste it into an editor like gedit. Then save it as something like "perspective_grid.bash" or whatever name you think is appropriate.
The reason the terminal disappeared was because pasting it directly caused the terminal to try and execute the script then and there. There are some "exit" statements that would have caused the terminal to close. It's not a big deal. Like I said, just save it as a file, and you'll launch it from the terminal a little later.
EDIT2:
And to make sure that gnuplot is installed, type "which gnuplot" at the terminal. If it doesn't spit out anything but another prompt, then gnuplot has not been installed. You should see something like this:
Code:
user@localhost:~$ which gnuplot
/usr/bin/gnuplot
user@localhost:~$
Last edited by Dark_Helmet; 12-15-2011 at 02:02 PM.
So, open a terminal: if you're using Ubuntu or something Debian-based, there should be an Applications->Accessories->Terminal menu item (or something similar). That will get you to a command prompt.
im still stuck here, im with linux-mint, when opening the terminal i cant find:Applications->Accessories->Terminal
You don't necessarily need to use that specific method. In an earlier reply, you mentioned that you had pasted the script directly into the terminal and the terminal disappeared.
However you opened that previous terminal is fine--just so long as you can get to a command line.
Last edited by Dark_Helmet; 12-15-2011 at 02:52 PM.
You don't necessarily need to use that specific method. In an earlier reply, you mentioned that you had pasted the script directly into the terminal and the terminal disappeared.
However you opened that previous terminal is fine--just so long as you can get to a command line.
i dont get it mate, what should i open, where can i find a comand line?
also i pasted the script into the terminal, and pressed enter, after that the terminal desapeared
However you opened the terminal you were talking about in the above message is fine.
Other options:
1. Navigate through your programs menu (or whatever Mint refers to it as) and look for any subgroup that has an entry for "terminal" or "command line." And start it from there.
2. You can use the alt+f2 shortcut if you like and run "gnome-terminal" or "xterm" or "konsole" or whatever terminal emulator you have installed.
However you opened the terminal you were talking about in the above message is fine.
Other options:
1. Navigate through your programs menu (or whatever Mint refers to it as) and look for any subgroup that has an entry for "terminal" or "command line." And start it from there.
2. You can use the alt+f2 shortcut if you like and run "gnome-terminal" or "xterm" or "konsole" or whatever terminal emulator you have installed.
can i open alt+f2 and put in your script and run it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.