Set minimum and max range in relation to window size

edited October 2016 in Questions about Code

final float MAX_SIZE = 35000; final float MIN_SIZE = MAX_SIZE/10; float alienSize; float alienY; float alienX; void draw() { alienX = mouseX; alienY = mouseY; alienSize = MAX_SIZE*mouseY/height; }

My goal is to make the variable alienSize be the max size when it ( and the mouse ) is at the bottom of the window and 1/10th the size when it ( and the mouse ) is at the top of the window. I have so far this code which works for the max size but there is no limit to how small the alien can get. any help please :)

Edit: I have to hand this in so no cheating please like having an if statement check for the size or anything



  • If only problem is a limiting of the min/max size, have a look at constrain().

  • map() will return a value from a range of numbers based on the value of an input in a different range.

Sign In or Register to comment.