Git Product home page Git Product logo

gradient-image-generator's Introduction

Gradient Image Generator

What is this all about

This is a simple tool that generates a PPM file using some basic raytracing along with some linear interpolation to generate a gradient image which transitions from one colour to another.

You end up with something that looks like this:

Example Image

The above image is gradient of white to blue.

The image can be changed by changing the attributes in the config file which is located in include/Config.h directory

Customising

The Config.h has some settings that can be changed by the user to alter the output:

typedef struct CONFIG_STRUCT {
  // Colour gradient options (RGB)
  double beginRed = 256;
  double beginGreen = 256;
  double beginBlue = 256;

  double endRed = 128;
  double endGreen = 179.2;
  double endBlue = 256;

  // Image settings
  double aspect_ratio = 16.0 / 9.0;
  int image_width = 900; // Image height is calculated according to width

  // Camera settings
  double viewportHeight = 2.0;
  double focalLength = 1.0;
  double originX = 0;
  double originY = 0;
  double originZ = 0;

  // Renderer settings
  std::ostream &out = std::cout;
} Config;

PPM File Format

This project uses the PPM (Portable Pixelmap Format) file format, this allows us to write RGB values to a file in plaintext format and then open using a typical image viewer.

A typical PPM file looks like this:

P3 # Means this is a RGB color image in ASCII
3 2 # width * height
255 # Max colour value

255 0 0 # RGB triplets
0 255 0
0 0 255
255 255 0
255 255 255
0 0 0

How to use this

After changing the config file to your preference, you can simply run the following in your terminal of choice

To compile the file and export data to image file in res/image.ppm

$ make

To open the image after compiling

$ make open-image

To do all of the above in one statement

$ make create-image

Simplicity

This project was designed to use no dependencies except the C++ standard library, this is a C++11 project because we are using constexpr to speed up some of the vector operations.

gradient-image-generator's People

Contributors

kylesmith19091 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.