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;
}
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
Visual Studio Code (VsCode) Installation: (Simple installation page)
Visual Studio Installation: (Simple installation page)
note : This example is run on Visual Studio 2019, it should run just fine on 2017 too.Dev-C++ Installation: (Simple installation page)
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}