GSDP:GAM100/CProcessing/vec2 scale()

From Inside
Jump to: navigation, search

vec2_scale()

Description

Returns a copy of an input Vec2 with its' values scaled by an input scale.

Parameters

vec2_scale(Vec2 vec, float scale)

  • vec - (Vec2) The vector to scale.
  • scale - (float) The value to scale the input vector by.

Example

Vec2 position;
Vec2 speed;

void init()
{
  position = vec2_set(canvasWidth / 2, canvasHeight / 2);
  speed = vec2_set(50.0f, 0.0f);

  ellipseMode(CENTER);
  fill(color(255, 0, 0, 255));
}

void update()
{
  background(color(255, 255, 255, 255));

  // Check if direction should be inverted
  if (position.x > canvasWidth)
  {
    speed = vec2_neg(speed);
    position.x = canvasWidth;
  }
  else if (position.x < 0)
  {
    speed = vec2_neg(speed);
    position.x = 0;
  }

  // Update position
  position = vec2_add(position, vec2_scale(speed, dt()));

  // Draw the circle
  circle(position.x, position.y, 40);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>