Thursday, February 13, 2025

Circle Animation with ImGui

 Circle Animation with ImGui for C++

Youtube:


Source code:

void CircFunc()
{
    static int nc = 360;
    double radius = 300;
    static float mul = 1;
    ImGui::Begin("Settings");
    ImGui::InputInt("Number", &nc, 2, 1000);
    ImGui::InputFloat("Multiply", &mul, 0.01f, 1.0f, "%.3f");
    ImGui::SliderInt("Number_", &nc, 2, 1000);
    ImGui::SliderFloat("Multiply_", &mul, 0.0f, 100.0f);
    ImGui::End();
    ImGui::Begin("Canvas");
    ImVec2 window_pos = ImGui::GetWindowPos();
    ImVec2 window_size = ImGui::GetWindowSize();
    ImVec2 cent = ImVec2(window_pos.x + window_size.x * 0.5f, window_pos.y + window_size.y * 0.5f);
    ImDrawList* drawlist = ImGui::GetWindowDrawList();
    drawlist->AddCircle(cent, radius, IM_COL32(255, 255, 255, 255));
    double divang = PI2 / nc;
    for (int i=0;i<nc;i++)
    {
        double b = i * mul;
        double x1 = cent.x + cos(i * divang) * radius;
        double y1 = cent.y + sin(i * divang) * radius;
        double x2 = cent.x + cos(b * divang) * radius;
        double y2 = cent.y + sin(b * divang) * radius;
        drawlist->AddLine(ImVec2((float)x1, (float)y1), ImVec2((float)x2, (float)y2), IM_COL32(255, 255, 255, 255));
    }
    ImGui::End();
}

Wednesday, February 12, 2025

Spirographs in C#

 Spirographs in C#

Youtube:



Sourcecode:

https://github.com/resoftw/Youtube.git

Sunday, February 9, 2025

Harmonic Motion Art

 Harmonic Motion Art

Youtube:




Required library: raylib
pip install raylib

Source code:
from pyray import *
from raylib import *
from math import sin, cos, pi, sqrt
from random import random
from time import sleep

SW = 540
SH = 960
CX = SW / 2
CY = SH / 2
MAXR = 540/2-10
NSEG = 3
set_config_flags(FLAG_MSAA_4X_HINT)
init_window(SW, SH, "Anim")
lens = []
rots = []
angs = []
pts = []
dly =0.1
LC = (0,225,255)

def distance(point1, point2):
    return sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)


def rndrot():
    return round(100*random()-50)*5/100

def reset():
    global lens,rots,angs,pts,dly
    pts = []
    lens = []
    rots = []
    angs = []
    dly=0.05
    mr = MAXR-5
    for i in range(NSEG):
        rots.append(rndrot())
        angs.append(0)
        lens.append(MAXR/NSEG)
    print(lens)
    print(rots)
reset()
dowait = False
waitcount=0
while not window_should_close():
    begin_drawing()
    if not dowait:
        clear_background(BLACK)
       
        x = CX
        y = CY
        a = 0
        for i in range(NSEG):
            x1 = x + cos((angs[i] + a) * pi / 180) * lens[i]
            y1 = y + sin((angs[i] + a) * pi / 180) * lens[i]
           
            draw_line_ex([x, y], [x1, y1], 2, RED)
            draw_circle_v([x1, y1], 5, GREEN)
           
            x = x1
            y = y1
            a += angs[i]
            angs[i] += rots[i]
       
        pts.append([x, y])
        draw_line_strip(pts, len(pts), WHITE)
        if len(pts) > 2:
            start_point = Vector2(pts[0][0], pts[0][1])
            end_point = Vector2(pts[len(pts) - 1][0], pts[len(pts) - 1][1])
           
            dist = distance([start_point.x, start_point.y], [end_point.x, end_point.y])
           
            if dist < 0.1:
                dowait=True
                waitcount=10000
       
       
       
    else:
        clear_background(BLACK)
        draw_line_strip(pts, len(pts), WHITE)
        waitcount-=10
        if waitcount<=0:
            reset()
            dowait=False
    end_drawing()
    if IsKeyPressed(32):
        dowait=False
        reset()
    sleep(dly)
    if dly>0.00001:
        dly/=1.025


close_window()

Circle Animation with ImGui

 Circle Animation with ImGui for C++ Youtube: Source code: void CircFunc () {     static int nc = 360 ;     double radius = 300 ;     ...