Shoot image and make it shrink (Processing)

Hi, I’m currently learning processing and making the program of rocket moving through middle of the screen. I’m gonna use image (png file) for the rocket.

I want to make a rocket shoot with mouse like a sling shot. And I want to make the rocket smaller as it gets closer to the center to look like its getting far from me. Then disappears in the center of the screen. (The screen size will be 1920*1080)
Can somebody help me with this? Thanks

you can MESS with the image
( like i started with the example Basics / Image / LoadDisplayImage / )
but changed it using
https://processing.org/reference/scale_.html

/**
 * Load and Display 
 * 
 * Images can be loaded and displayed to the screen at their actual size
 * or any other size. 
 */

PImage img;  // Declare variable "a" of type PImage

void setup() {
  size(640, 360);
  // The image file must be in the data folder of the current sketch 
  // to load successfully
  img = loadImage("moonwalk.jpg");  // Load the image into the program  
}

void draw() {
  // Displays the image at its actual size at point (0,0)
  image(img, 0, 0);
  // Displays the image at point (0, height/2) at half of its size
  //image(img, 0, height/2, img.width/2, img.height/2);   // kll
  // test scale instead
  scale(0.5);                                              
  image(img, 0, 0);
  
}

2 Likes

Thanks for your help but is there way to make a force like a sling shot?
And for the shrinking I can set 2 points and make the rocket make smaller and smaller right?

as you need a path for your image you could use some math,
if not a straight line do not use the usual processing curve functions
as they not make it easy to calculate points inbetween…

later you need to adjust the speed ( moving of image ) by the step size
used for your function.

the points on that math function ( curve ) you use for the image position.

Here is a very simple example of a slingshot. It demonstrates the basics of an anchor, a ball, and a speed that is applied when you drag the ball from the anchor and release.

/**
 * Slingshot
 * 2019-07 Jeremy Douglass - Processing 3.4
 * drag ball with mouse and release
 */
PVector anchor;
PVector ball;
PVector speed;

void setup() {
  size(300, 300);
  // place ball on anchor, speed=0;
  anchor = new PVector(width/2, 4*height/5);
  ball = anchor.copy();
  speed = new PVector(0, 0);
}

void draw() {
  background(128);
  // move ball
  ball.add(speed);
  // draw ball and anchor
  ellipse(anchor.x, anchor.y, width/10, width/10);
  ellipse(ball.x, ball.y, width/20, width/20);
  line(ball.x, ball.y, anchor.x, anchor.y);
}

void mouseDragged() {
  // on drag, hold ball with mouse
  ball.set(mouseX, mouseY);
  speed.set(0, 0);
}

void mouseReleased() {
  // on release, set ball speed based on
  // anchor distance -- farther = faster
  speed = PVector.sub(anchor, ball).mult(0.1);
}

To make the ball slow to a stop, add a deceleration line to draw – for example: speed.mult(0.97);