Skip to content

Yeet! C++ 2D graphics library to output primitives and other custom shapes, easily.

Notifications You must be signed in to change notification settings

krehwell/Memake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Memake

Yeet, yeet, yeet!.

#include "Memake.h"
Memake mmk(800, 800, "memake window");

void draw() {
    mmk.drawRect(300, 300, 100, 100, Colmake.red); // draw a rectangle with red color
}

int main() {
    mmk.update(draw);
    return 0;
}

Dependencies

Download

Download project based on tools you use to run C++:

  • Manual Compile (for chad): git clone https://github.com/krehwell/Memake.git
  • Visual Studio Code: GDrive
  • Visual Studio: GDrive
  • Dev-C++: GDrive

Installation

Visual Studio Code (VsCode) Installation: (Simple installation page)
  1. Download the project and extract
  2. Inside the extracted folder go to __install__ folder
    vscode1
  3. Move MinGW folder to C:
    vscode2
  4. Right click "Add MinGW to env.bat" and Run as administrator vscode3
  5. Open the extracted project with vscode vscode4
  6. Install C++ extension for VsCode vscode5
  7. Run project by pressing F5 vscode6
Visual Studio Installation: (Simple installation page) note : This example is run on Visual Studio 2019, it should run just fine on 2017 too.
  1. Download the project and extract
  2. Inside the extracted folder open the "Memake_VisualStudio.sln"
    vs1
  3. Press "Local Windows Debugger" to compile and run project
    vs2
  4. See result
    vs3
Dev-C++ Installation: (Simple installation page)
  1. Download the project and extract
  2. Inside the extracted folder click "project.dev" to open the project in Dev-C++
    devc++1
  3. Press "Compile and Run (F11)" to compile and run project
    devc++2
  4. See result
    devc++3

Example Codes

Animation with Keyboard

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

int x = 350;
int y = 350;

void draw() {
    mmk.drawRect(x, y, 100, 100, Colmake.red);  // draw rectangle with a red color
    
    // get keyboard's key pressed  
    switch(mmk.readKeyInput()) {
        case 'd':
            x++;
            break;
        case 'a':
            x--;
            break;
        case 's':
            y++;
            break;
    	case 'w':
            y--;
            break;
	}
}

int main()
{
    mmk.update(draw);

    return 0;
}

Animation with Mouse

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

int x = 350;
int y = 350;

void draw() {
    mmk.drawCircle(x, y, 40, Colmake.yellow);  // draw circle with a yellow color
    
    // get mouse position
    x = mmk.getMousePosX();
    y = mmk.getMousePosY();
}

int main()
{
    mmk.update(draw);

    return 0;
}

Randomize Screen Background Every X Second

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

int x = 350;
int y = 350;

void draw() {
    mmk.drawFractalTree(400, 750, 150, 22, 90, 20, Colmake.cornsilk);
    
    // set new background color 
    Color newColor = mmk.generateColor(random(0,255), random(0,255), random(0,255));
    mmk.setScreenBackgroundColor(newColor);
    
    mmk.delay(200);  // delay to slow re-rendering 
}

int main()
{
    mmk.update(draw);

    return 0;
}

Clamping Ball Animation

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

class Ball {
    public:
        int x, y, r;
        int xdirection = 1, ydirection = 1;
        
        Ball(int _x, int _y, int _r) {
            x = _x;
            y = _y;
            r = _r;
        }
        
        void update() {
            draw();
            move();
            checkScreenClamp();
        }
        
        void draw() {
            mmk.drawCircle(x, y, r, Colmake.beige);
        }
        
        void move() {
            x += xdirection;
            y += ydirection;
        }
        
        void checkScreenClamp() {  // check screen's edge to change ball's direction
            if (x <= 0 || x >= mmk.getScreenW()) {
                xdirection *= -1;
            }
        	
            if (y <= 0 || y >= mmk.getScreenH()) {
                ydirection *= -1;
            }
        }
};

int main()
{
    Ball ball(230, 520, 40);
	
    // use lambda to utilize local scope instead of define everything as global variable
    mmk.update([&](){
        ball.update();
        
        mmk.delay(1);
    });

    return 0;
}

Generate Custom Polygon

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

void draw() {
    Vector2 polygon[] = {{117, 173}, {200, 300}, {364, 351}, {528, 144}, {414, 203}, {355, 63}, {277, 172}, {217, 51}, {203, 195}};
    mmk.drawPolygon(polygon, 9, mmk.generateColor(255,102,0));  // 9 is the number of edges desired to be drawn
}

int main()
{
    mmk.update(draw);

    return 0;
}

Polygon Generator Randomizer

Code snippet
#include "Memake/Memake.h"
using namespace std;

Memake mmk(800, 800, "memake");

void draw() {
    Vector2 polygon[] = {
        {random(400, 500), random(300, 800)}, 
        {random(200, 300), random(200, 300)}, 
        {random(400, 500), random(300, 800)}, 
        {random(200, 300), random(200, 300)}, 
        {random(200, 300), random(200, 300)}, 
        {random(200, 300), random(200, 300)}, 
        {random(200, 300), random(200, 300)}, 
        {random(200, 300), random(200, 300)}, 
        {random(200, 300), random(200, 300)},
        {random(600, 700), random(400, 600)},
        {random(500, 700), random(400, 500)},
        {random(600, 600), random(400, 700)}
    };
		
    mmk.drawPolygon(polygon, random(7,12), Colmake.khaki); 
    
    mmk.delay(600);
}

int main()
{
    mmk.update(draw);

    return 0;
}

Bouncing Balls Screensaver

Code snippet
#include "Memake/Memake.h"
#include <math.h>

Memake mmk(800, 800, "memake");

using namespace std;

class Ball {
    public:
        int x, y, r;
        int dx = 1, dy = 1;

        Ball(int _x, int _y, int _r) {
            x = _x;
            y = _y;
            r = _r;
        }

        void update() {
            draw();
            checkClamp();
            move();
        }

        void draw() {
            mmk.drawCircle(x, y, r, Colmake.beige);
        }

        void checkCollision(Ball &b) {
            int distX = x - b.x;
            int distY = y - b.y;

            float distance = sqrt((distX * distX) + (distY * distY));

            if (distance < r + b.r) {
                dx *= -1;
                dy *= -1;
            }
        }

        void move() {
            x += dx;
            y += dy;
        }

        void checkClamp() {
            if (x <= 0 || x >= mmk.getScreenW()) {
                dx *= -1;
            }
            if (y <= 0 || y >= mmk.getScreenH()) {
                dy *= -1;
            }
        }

};

int main()
{
    int numOfBall = 24;
    Ball b[] = {
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
	Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), 
	Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10), Ball(random(0, 800), random(0, 800), 10),
        Ball(random(0, 800), random(0, 800), 10)
    };

    mmk.update([&](){
        for (int i = 0; i < numOfBall; i++) {
            for (int j = 0; j < numOfBall; j++) {
                // check collision between one ball to others, but don't check collision to itself
                if (j != i) {
                    b[i].checkCollision(b[j]);
                }
            }
            b[i].update();  // update/move every ball
        }

        mmk.delay(2);
    });

    return 0;
}

About

Yeet! C++ 2D graphics library to output primitives and other custom shapes, easily.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published