• Welcome to Jose's Read Only Forum 2023.
 

PLOT and DRAW with APi

Started by Zlatko Vid, December 21, 2022, 07:48:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

Hello Charles & ALL

I am trying to make classic PLOT and DRAW functions using api calls

MoveToEx hdc, x,y ,lppt

and

LineTo hdc,x1,y1

and i made search all over net but nothing concrete
i just found this small example in C ...so
how this can be translated to Oxygenbasic...
any hint?

static POINT ptPrevious = { 0,0 };
static bool flag = false;
Vertex temp;
...
case WM_LBUTTONDOWN:
        HDC hdc = GetDC(hWnd);
        POINTS clickPoint = MAKEPOINTS(lParam);
        if (flag == false) {
            ptPrevious.x = clickPoint.x;
            ptPrevious.y = clickPoint.y;
            flag = true;
        }
        //store the point in connectLines
        temp.SetX(clickPoint.x);
        temp.SetY(clickPoint.y);
        connectLines.push_back(temp);

        MoveToEx(hdc, ptPrevious.x, ptPrevious.y, NULL);
        LineTo(hdc, LOWORD(lParam), HIWORD(lParam));

        //record previous point
        ptPrevious.x = clickPoint.x;
        ptPrevious.y = clickPoint.y;

        ReleaseDC(hWnd, hdc);
        break;

Charles Pegge

#1
Hi Aurel,

uses corewin includes all the GDI functions. Then it's much the same as your C snippet.  But it is better to store all the plots into an array, so you can do screen refreshes, and save/reload the plot.

Zlatko Vid

#2
Hi Charles

I agree that would be nice to store data in array

Theo Gottwald

if you like speed, make these commands in ASM.
You so know know ASM?
Ask ChatGPT he can give you the ASM Code for all these commands.
I have tried, it works. Ok, it may need small corrections here and there  but generally its fine.


section .data

; Define the width and height of the image
width   db 100
height  db 100

; Define the starting x and y position of the line
x_start db 50
y_start db 50

; Define the angle and length of the line
angle   dd 3.14159265358979 / 4
length  dd 50

section .bss

; Reserve space for the image buffer
image_buffer resb width * height * 3

section .text

; The main function
global _start

_start:
    ; Load the angle and length into the x87 FPU
    fld angle
    fsin
    fstp [sin_result]
    fld angle
    fcos
    fstp [cos_result]

    ; Calculate the end position of the line
    mov eax, [length]
    fild eax
    fmul dword [sin_result]
    fistp [y_end]
    mov eax, [length]
    fild eax
    fmul dword [cos_result]
    fistp [x_end]

    ; Add the starting position to the end position to get the final end position
    add [x_end], [x_start]
    add [y_end], [y_start]

    ; Calculate the delta x and y
    mov eax, [x_end]
    sub eax, [x_start]
    mov [delta_x], eax
    mov eax, [y_end]
    sub eax, [y_start]
    mov [delta_y], eax

    ; Calculate the address of the starting pixel
    mov ebx, image_buffer
    add ebx, y_start * width * 3
    add ebx, x_start * 3

    ; Draw the line
    mov eax, [delta_x]
    mov edx, [delta_y]
    cmp eax, 0
    jge .x_positive
    neg eax
    .x_positive:
    cmp edx, 0
    jge


Zlatko Vid

Quoteif you like speed, make these commands in ASM

Oh ..you don't know ?
o2 basic and o2 asm run at same speed ..i TESTED

Theo Gottwald

But in O2 you still need to handcode it yourself :-)