473,786 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rotate, skew, resize for DHTML game

Are there methods for manipulating images in JavaScript that would allow me
to write functions to rotate, skew, mask and resize images (bitmaps)?

The functions need to be fast enough for use in a top-down scrolling game.
Or would I be better off preprocessing all of the images with something
server side such as PHP and then preloading them into my JavaScript already
manipulated?

The only thing I don't like about the idea of preprocessing the images is
that I will have to preload a very large number of images, ie all of the
sprites rotated at different angles, resized at different sizes etc.

I am considering using Flash but because it would involve learning
ActionScript I would prefer to do it with a combination of JavaScript and
PHP. The other alternative that I was considering was using SVG, but not
many people have an SVG capable browser or have downloaded the SVG plugin.

Would also appreciate any links to resources that would help me with this
sort of thing. TIA!
Jul 23 '05 #1
21 8504
Nik Coughlin wrote:
Are there methods for manipulating images in JavaScript that would allow me
to write functions to rotate, skew, mask and resize images (bitmaps)?


No. JS has no ability to turn, rotate or otherwise manipulate images :-\
I wish it did...

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
I am not promoting Microsloth or any of it's products but...
AFAIK IE5.5 alows images and text to be rotated skewed and resized through
the filter and style objects
for resizing
currEl.style.zo om=var+'%';
for rotation
var deg2radians = Math.PI * 2 / 360;
currEl.style.fi lter="progid:DX ImageTransform. Microsoft.Matri x(sizingMethod= '
auto expand')";
// I use onmousemove to trap event.clientX/Y to produce 'rotation' values
so the user can rotate or skew with a mouse drag
document.onmous eover=makeRotat ionParam;
var lastX=0, lastY=0;
function makeRotationPar am() {
var x=event.clientX , y=event.clientY ;
var aValue=compute differences in current and last mouse position
according to your needs;
lastX=x;
lastY=y;
rotateObj(aValu e);
}
function rotateObj(rotat ion) {
if(rotation>=36 0) rotation=0;
var rad = rotation * deg2radians ;
var costheta = Math.cos(rad);
var sintheta = Math.sin(rad);
currEl.filters. item(0).M11 = costheta;
currEl.filters. item(0).M12 = -sintheta;
currEl.filters. item(0).M21 = sintheta;
currEl.filters. item(0).M22 = costheta;
}
and if you fiddle with the filter params (M11...) and/or the rad/sin/cos
values you'll find the skew and more
Jimbo
"Randy Webb" <Hi************ @aol.com> wrote in message
news:-P************** ******@comcast. com...
Nik Coughlin wrote:
Are there methods for manipulating images in JavaScript that would allow me to write functions to rotate, skew, mask and resize images (bitmaps)?


No. JS has no ability to turn, rotate or otherwise manipulate images :-\
I wish it did...

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
Hi Nik

You can't do this in JavaScript, but you can use JavaScript to call Java and
Java can do it. If you can get hold of J.A.Pew "Instant Java" (ISBN
0-13-565821-7), then you will find that the book comes with a CD on which
the necessary Java applets are already provided in such a way that you can
use them with getting your hands dirty. And if you can only get a
second-hand copy with the CD missing, it still has all the source code you
need.

All the best

Ian
On 2004/09/04 03:16, in article 2p************@ uni-berlin.de, "Nik Coughlin"
<nrkn!hopeful ly no sp***@woosh.co. nz> wrote:
Are there methods for manipulating images in JavaScript that would allow me
to write functions to rotate, skew, mask and resize images (bitmaps)?

The functions need to be fast enough for use in a top-down scrolling game.
Or would I be better off preprocessing all of the images with something
server side such as PHP and then preloading them into my JavaScript already
manipulated?

The only thing I don't like about the idea of preprocessing the images is
that I will have to preload a very large number of images, ie all of the
sprites rotated at different angles, resized at different sizes etc.

I am considering using Flash but because it would involve learning
ActionScript I would prefer to do it with a combination of JavaScript and
PHP. The other alternative that I was considering was using SVG, but not
many people have an SVG capable browser or have downloaded the SVG plugin.

Would also appreciate any links to resources that would help me with this
sort of thing. TIA!


Jul 23 '05 #4
On Mon, 6 Sep 2004 11:36:40 +0000 (UTC), Ian Sedwell
<ia*********@bt click.com> wrote:
You can't do this in JavaScript, but you can use JavaScript to call Java and
Java can do it. If you can get hold of J.A.Pew "Instant Java" (ISBN
0-13-565821-7), then you will find that the book comes with a CD on which
the necessary Java applets are already provided in such a way that you can
use them with getting your hands dirty. And if you can only get a
second-hand copy with the CD missing, it still has all the source code you
need.


SVG, DirectAnimation and VML are also all more than capable of doing
it, I would recommend SVG as the most future proof and cross-platform,
and Directanimation as the most supported (every win32 IE since IE4)

Jim.
Jul 23 '05 #5
On Mon, 6 Sep 2004 11:36:40 +0000 (UTC), Ian Sedwell wrote:
Are there methods for manipulating images in JavaScript that would allow me
to write functions to rotate, skew, mask and resize images (bitmaps)?
... You can't do this in JavaScript, but you can use JavaScript to call Java and
Java can do it.


Core Java will read .png, .gif and .jpeg,
but to read .bmp it would require JAI.
<http://java.sun.com/products/java-media/jai/whatis.html#fun ction>

Of course .bmp's (if that is what the OP
meant by bitmaps) are a bad format to use
on the net in any case. Gif are good for
256 color images, while jpeg is good for
natural images. Use png for everything else.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #6
Sorry
document.onmous emove is what I meant;
"J. J. Cale" <ph****@netvisi on.net.il> wrote in message
news:41******** @news.012.net.i l...
I am not promoting Microsloth or any of it's products but...
AFAIK IE5.5 alows images and text to be rotated skewed and resized through
the filter and style objects
for resizing
currEl.style.zo om=var+'%';
for rotation
var deg2radians = Math.PI * 2 / 360;
currEl.style.fi lter="progid:DX ImageTransform. Microsoft.Matri x(sizingMethod= ' auto expand')";
// I use onmousemove to trap event.clientX/Y to produce 'rotation' values
so the user can rotate or skew with a mouse drag
document.onmous eover=makeRotat ionParam;
var lastX=0, lastY=0;
function makeRotationPar am() {
var x=event.clientX , y=event.clientY ;
var aValue=compute differences in current and last mouse position
according to your needs;
lastX=x;
lastY=y;
rotateObj(aValu e);
}
function rotateObj(rotat ion) {
if(rotation>=36 0) rotation=0;
var rad = rotation * deg2radians ;
var costheta = Math.cos(rad);
var sintheta = Math.sin(rad);
currEl.filters. item(0).M11 = costheta;
currEl.filters. item(0).M12 = -sintheta;
currEl.filters. item(0).M21 = sintheta;
currEl.filters. item(0).M22 = costheta;
}
and if you fiddle with the filter params (M11...) and/or the rad/sin/cos
values you'll find the skew and more
Jimbo
"Randy Webb" <Hi************ @aol.com> wrote in message
news:-P************** ******@comcast. com...
Nik Coughlin wrote:
Are there methods for manipulating images in JavaScript that would
allow
me to write functions to rotate, skew, mask and resize images (bitmaps)?


No. JS has no ability to turn, rotate or otherwise manipulate images :-\
I wish it did...

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq


Jul 23 '05 #7
JRS: In article <41********@new s.012.net.il>, dated Mon, 6 Sep 2004
09:24:40, seen in news:comp.lang. javascript, J. J. Cale
<ph****@netvisi on.net.il> posted :
var deg2radians = Math.PI * 2 / 360;
Math.Pi / 180 // more elegant
if(rotation>=36 0) rotation=0;
rotation %= 360 // should be much better, in the general case.

"Randy Webb" <Hi************ @aol.com> wrote in message
news:-P************** ******@comcast. com...
Nik Coughlin wrote:
> Are the
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq


Responses should go after trimmed quotes, and sigs should only be quoted
if cited. Please read the newsgroup FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #8
Andrew Thompson wrote:
On Mon, 6 Sep 2004 11:36:40 +0000 (UTC), Ian Sedwell wrote:
Are there methods for manipulating images in JavaScript that would
allow me to write functions to rotate, skew, mask and resize images
(bitmaps)?

..
You can't do this in JavaScript, but you can use JavaScript to call
Java and Java can do it.


Core Java will read .png, .gif and .jpeg,
but to read .bmp it would require JAI.
<http://java.sun.com/products/java-media/jai/whatis.html#fun ction>

Of course .bmp's (if that is what the OP
meant by bitmaps) are a bad format to use
on the net in any case. Gif are good for
256 color images, while jpeg is good for
natural images. Use png for everything else.


Don't worry, I wouldn't dream of using bmps on the net. Also, there are
many instances where png is more efficient than gif for 256 color images. I
am looking for a pure JavaScript solution, so I will probably preprocess all
of the images in PHP and load them into the JavaScript already transformed.
Just means that I'm going to have a big preload time.
Jul 23 '05 #9
On Tue, 7 Sep 2004 08:22:26 +1200, Nik Coughin wrote:
Don't worry, I wouldn't dream of using bmps on the net.
Aaaah ..good. I can sleep tonight.
Also, there are many instances where png is
more efficient than gif for 256 color images.


Yes, good point. I read that somewhere else
recently as well, and have been meaning to play
with a few images to see the difference in
file sizes.

All the best with your project. My usefulness
on this matter has ended, ..if I ever was of any
(use that is). ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1999
by: mr_burns | last post by:
hi there, i would like a book that will explain concepts of javascript and dhtml instead of, for example, ten tutorials on how to do specific things in js or dhtml. ideally a book thats can explain from the basics of javascript, to more complex things such as dhtml and dom onto things like creating javascript objects (if that is possible, but u get the idea). rather than this is how you make a drop down menu tutorial; this is how you
5
2972
by: sundew | last post by:
Here I am presenting you the new Wednus proj. subtree, Wednus DHTML RPG engine, or just 'Wednus RPG' with a demo game using the engine. About the engine itself, since this DHTML game engine designed in generic manner, it can be used for the games other than RPG genre as well. (could be easier). By using this engine, anyone can make their own DHTML games w/ half an hour of simple scripting. and about the demo game, the name of the first...
4
18298
by: taccea | last post by:
Hello, I need to rotate some text vertically on an Access report. Is that something difficult to do? Any pointers appreciated. Taccea
1
3198
by: Rohan | last post by:
Hi There, Is it possible to rotate or resize pictureboxes, labels, textboxes at runtime? And I even wanted to make textbox and label controls Transperent ?
7
3125
by: chad | last post by:
is it just me or does anybody else find the Image.RotateFlip method kind of slow? (I'm comparing to commercial softwares). Same for resizing. I'm using sourceImage = system.drawing.bitmap.fromFile(filestring) newImage = new bitmpa(sourceImage, newWidth, newHeight) newImage.save(newFileString) Anyone knows of any faster methods?
3
2476
by: Jim Langston | last post by:
I really am not sure if this question belongs in this newsgroup, but not sure where else to ask it. There is someone working on a game that I tested, and it was taking >30 seconds to load. He stated that everyone else was taking 2 or 3 seconds. Then he found one other person taking >30 seconds, and it turns out the common denominator was both of us have Intel chips (Celeron) where the other people have AMD. I had him send me his code...
4
4640
by: Raj | last post by:
Hello Coders- For calculating the Moment, Skew and Kurtosis, i found the following function in the help of C++ builder; But i couln't understand this, of how to use this; What i have is the data in a 1-d array;, say, Data Can somebody tell me how to use this to find the MomentSkewKurtosis ? Copied from C++ help;
0
934
by: csecharith | last post by:
Hi I have to print an html file, I want to rotate it by 90 degrees. I know how to take portrait and landscape reports. I want to know how to rotate it by 90 degrees. Do you know how to do it???? (I should be resize I know that and I can do it) Thanks!
0
1725
by: harryusa | last post by:
I am experimenting with the rotate function and so far I can't get my code to return anything but the URL of my script. Here it is: <?php // The file you are rotating $image = 'halloween.jpg'; //How many degrees you wish to rotate $degrees = 180;
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6749
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
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.