This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

Duta presents ...



Source code included, feel free to take it and include it in whatever you need. Credit not required, however it'd be nice if you did :)
This scenario demonstrates a class (Magnify.class) which will (surprise surprise) magnify whatever's under it.
This is (as far as I know) the only magnifier on the gallery with support for magnifying actor's as well as the world image.
Also, hold space to spawn balloons of a random transparency to test the magnification of actors support.

Instructions for use:
- The magnifier will follow your mouse unless its locked on to an actor
- To lock it to an actor, simply click on an actor
- To unlock it, click it again (also it will unlock if the actor is removed from the world)

Instructions for adding it to one of your scenario's:
- Add the Magnify.class to your scenario
- In your world class, include the following line of code in the world's constructor:
setPaintOrder(Magnify.class, <Whatever other actor classes you have>);
- eg:
setPaintOrder(Magnify.class, AnActor.class, AnotherActor.class);
- and then obviously just add an object of the Magnify class to the world! :)

- In Magnify.class, there are some fields you can adjust to your liking:
private double zoom = 1.75; //Adjust this to the level of zoom you want.
private int radius = 75, //Adjust this to the radius of the zoomed image you want.
private boolean shouldLock = true; //Turn this to false if you don't want locking to actors.
private boolean noCursor = true; //Turn this to false if you want to be able to see the mouse all the time.

If you have any trouble using this, please post a comment and I'll help you out.

3883 views / 474 in the last 7 days

Tags: mouse demo with-source magnify magnifying

This scenario is a member of: Image manipulation

open in greenfoot
Your browser does not support the canvas tag.


As neither methods lag for me, can someone tell me if this method is in fact better? :p
A new version of this scenario was uploaded on Mon Jan 23 23:00:22 UTC 2012
This method does lag a little for me, but I think it's because you are creating a whole new GreenfootImage and looping through it pixel for pixel. It would be *much* faster to skip the GreenfootImage part and just sample the pixels needed to produce the magnified part
A new version of this scenario was uploaded on Tue Jan 24 07:31:25 UTC 2012 Significantly increased efficiency
I'm getting an out of bounds exception D:


I got that before I uploaded it, but I thought I'd fixed it? I'll look over it again
A new version of this scenario was uploaded on Tue Jan 24 09:14:45 UTC 2012


That (should be) fixed now - it took me longer than expected as it turned out I was barking up the wrong tree for a while on the cause of the error - I'd misread the line of code it quoted in the error message >.<


I've got one or two ideas for improving the efficiency of this further - I'll try it now, but it may be slow due to me being at college and the computer I'm working on is less than great...


I've just found that the panel.paint(g) code is causing an error when you click reset - This is only an issue if running it from within the Greenfoot IDE or via command prompt, as it still lets the world reset, it just gives you the error code - due to this it's not on my priority list to be honest

See all comments

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.