GithubHelp home page GithubHelp logo

andres6936 / cup.graphics Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 32 KB

Avoid duplicate code in C++, define a class Color with operation bit shifting.

License: The Unlicense

CMake 80.43% C++ 19.57%
color class avoid duplicate code bit-shifting bitwise

cup.graphics's Introduction

Objective

The objective of this library is to avoid code duplication with C++.

Problem Definition

Throughout my projects, it's common to have to write a class that defines a color, in components like red, green, blue and alpha. Obviously it means writing the same properties and methods for a class, leading to code repetition. Action to be avoided at all costs.

Downloads

This library is not designed for impressive performance (although this is also an aspect that I take into account when implementing the library), is designed to avoid duplicate code.

How to Use

With the arrival of CMake 14, a script was added that allows to get repositories from the Internet, taking into account this the user TheLartians decided to write a script for CMake that acts as a package manager. In my opinion, this marks a new step for C++ and CMake, allowing work with libraries that are downloaded and updated without direct intervention of the user.

How to use

To use this library, you need the script written by TheLartians, named CPM.cmake (acronym for CMake Package Manager). Add it to your project, for example, under the CMakeModules and then in your CMakeFiles.txt write the following:

Include(CMakeModules/CPM.cmake)

CPMAddPackage(
  NAME Cup.Graphics
  VERSION 2020.0505
  GITHUB_REPOSITORY Andres6936/Cup.Graphics
)
 
TARGET_LINK_LIBRARIES(<TARGET> PRIVATE Cup.Graphics)
  • The directory CMakeModules should be created in case it does not exist.
  • <TARGET> must be replaced by the executable to which you will link.

My proposal for using the library within your code is to use encapsulation.

using namespace Cup::Graphics;

Color color(233, 245, 132);

	assert(color.getRed() == 233);
	assert(color.getGreen() == 245);
	assert(color.getBlue() == 132);
	assert(color.getAlpha() == 255);

	color.setRed(56);
	color.setGreen(87);
	color.setBlue(156);
	color.setAlpha(69);

	assert(color.getRed() == 56);
	assert(color.getGreen() == 87);
	assert(color.getBlue() == 156);
	assert(color.getAlpha() == 69);

cup.graphics's People

Contributors

andres6936 avatar

Watchers

 avatar  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.