1
0
mirror of https://github.com/deadw00d/AROS.git synced 2025-11-19 16:21:21 +00:00

add a couple of basic drawing demos

This commit is contained in:
Kalamatee
2025-09-30 04:15:03 +01:00
committed by deadwood
parent ae17f0ac23
commit 543d8523c6
4 changed files with 339 additions and 0 deletions

View File

@ -0,0 +1,105 @@
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <math.h>
#include <stdlib.h>
#define WIDTH 400
#define HEIGHT 400
#define DEPTH 8 // 8-bit chunky (256 colors)
struct Window *win;
struct RastPort *rp;
struct BitMap *offbm;
struct RastPort offrp;
double x=0, u=0, v=0, f=0;
int n = 200;
static void draw(struct RastPort *rp) {
double r = 2.0 * M_PI / n;
int W = WIDTH; // 400
// clear background
SetAPen(rp, 0);
RectFill(rp, 0, 0, WIDTH, HEIGHT);
for (int i = 0; i < n; i++) {
for (double j = 0; j < 55; j += 0.1) {
double R = r * i + x - 99.0 * f;
u = sin(i + v + f) - sin(R);
v = cos(i + v + f) - cos(R);
x = u + f;
double X = n + 99.0 * u;
double Y = n + 99.0 * v;
// set pen depending on j
SetAPen(rp, (int)(2*j + 66) & 255);
Move(rp, (LONG)X, (LONG)Y);
Draw(rp, (LONG)X+1, (LONG)Y+1);
}
}
f += 0.00005;
}
int main() {
if ((win = OpenWindowTags(NULL,
WA_Left, 100,
WA_Top, 50,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Title, (IPTR)"Demo",
WA_Flags, WFLG_SIMPLE_REFRESH | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_CLOSEGADGET,
TAG_END))) {
rp = win->RPort;
// Allocate an off-screen bitmap
offbm = AllocBitMap(WIDTH, HEIGHT, DEPTH, BMF_CLEAR, win->RPort->BitMap);
if (!offbm) {
CloseWindow(win);
return 20;
}
// Init a RastPort that uses our bitmap
InitRastPort(&offrp);
offrp.BitMap = offbm;
BOOL running = TRUE;
struct IntuiMessage *msg;
while (running) {
// clear background (set pen 0 and erase)
SetAPen(&offrp, 0);
RectFill(&offrp, 0, 0, win->Width, win->Height);
// set pen color (pen 1)
SetAPen(&offrp, 2);
draw(&offrp);
ClipBlit(&offrp, 0, 0, rp, 0, 0, WIDTH, HEIGHT, 0xC0); // COPY
#if (0)
// Wait for something to happen on the window<6F>s port
WaitPort(win->UserPort);
// Handle events
while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) {
if (msg->Class == IDCMP_CLOSEWINDOW) {
running = FALSE;
}
ReplyMsg((struct Message *)msg);
}
#endif
}
CloseWindow(win);
}
return 0;
}

View File

@ -0,0 +1,110 @@
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <math.h>
#include <stdlib.h>
#define WIDTH 400
#define HEIGHT 400
#define DEPTH 8 // 8-bit chunky (256 colors)
struct Window *win;
struct RastPort *rp;
struct BitMap *offbm;
struct RastPort offrp;
double t = 0.0;
// magnitude helper
static double mag(double x, double y) {
return sqrt(x * x + y * y);
}
static void point(struct RastPort *rp, double x, double y) {
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
Move(rp, (LONG)x, (LONG)y);
Draw(rp, (LONG)x, (LONG)y);
}
}
static void a(struct RastPort *rp, double y, double i) {
double k, e, d, q, c;
k = (y < 11
? 6 + sin((double)(((int)y) ^ 8)) * 6
: y / 5.0 + cos(y / 2.0))
* cos(i - t / 4.0);
e = y / 7.0 - 13.0;
d = mag(k, e) + sin(e / 4.0 + t) / 2.0;
q = y * k / d * (3 + sin(d * 2 + y / 2 - t * 4));
c = d / 2.0 + 1 - t / 2.0;
point(rp, q + 60 * cos(c) + 200, q * sin(c) + d * 29 - 170);
}
static void draw(struct RastPort *rp) {
t += M_PI / 120.0;
for (int i = 10000; i--; ) {
a(rp, i / 345.0, i); // pass i too (needed in formula)
}
}
int main() {
if ((win = OpenWindowTags(NULL,
WA_Left, 100,
WA_Top, 50,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Title, (IPTR)"Jellyfish Demo Port",
WA_Flags, WFLG_SIMPLE_REFRESH | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_CLOSEGADGET,
TAG_END))) {
rp = win->RPort;
// Allocate an off-screen bitmap
offbm = AllocBitMap(WIDTH, HEIGHT, DEPTH, BMF_CLEAR, win->RPort->BitMap);
if (!offbm) {
CloseWindow(win);
return 20;
}
// Init a RastPort that uses our bitmap
InitRastPort(&offrp);
offrp.BitMap = offbm;
BOOL running = TRUE;
struct IntuiMessage *msg;
while (running) {
// clear background (set pen 0 and erase)
SetAPen(&offrp, 0);
RectFill(&offrp, 0, 0, win->Width, win->Height);
// set pen color (pen 1)
SetAPen(&offrp, 2);
draw(&offrp);
ClipBlit(&offrp, 0, 0, rp, 0, 0, WIDTH, HEIGHT, 0xC0); // COPY
#if (0)
// Wait for something to happen on the window<6F>s port
WaitPort(win->UserPort);
// Handle events
while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) {
if (msg->Class == IDCMP_CLOSEWINDOW) {
running = FALSE;
}
ReplyMsg((struct Message *)msg);
}
#endif
}
CloseWindow(win);
}
return 0;
}

View File

@ -0,0 +1,16 @@
#
# Makefile for AROS intuition.library tests
include $(SRCDIR)/config/aros.cfg
FILES := \
globe \
jellyfish \
rectangles
EXEDIR := $(AROSDIR)/Demos/misc
%build_progs mmake=demos-misc \
files=$(FILES) targetdir=$(EXEDIR)
%common

View File

@ -0,0 +1,108 @@
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <math.h>
#include <stdlib.h>
#define WIDTH 400
#define HEIGHT 400
#define DEPTH 8 // 8-bit chunky (256 colors)
struct Window *win;
struct RastPort *rp;
struct BitMap *offbm;
struct RastPort offrp;
static int f = 0;
static void draw(struct RastPort *rp) {
f++;
for (int x = 0; x <= WIDTH; x += 20) {
for (int y = 0; y <= HEIGHT; y += 20) {
double R = 10.0;
for (int n = 0; n < 2; n++) {
double k = (n == 0) ? 0.0 : M_PI/2.0;
double X = x - 250 + 200 * sin(f/50.0 + k);
double Y = y - 250 + 200 * sin(f/67.0 + k);
double s = sin(f/50.0 + k);
double c = cos(f/50.0 + k);
double v1 = fabs(s*X - c*Y) / 3.0;
double v2 = (X*X + Y*Y) / 4000.0 + 3.0;
// clamp
if (v1 < 0) v1 = 0;
if (v1 < R) R = v1;
if (v2 < R) R = v2;
}
int Rint = (int)R;
RectFill(rp, x - Rint, y - Rint,
x + Rint, y + Rint);
}
}
}
int main() {
if ((win = OpenWindowTags(NULL,
WA_Left, 100,
WA_Top, 50,
WA_Width, WIDTH,
WA_Height, HEIGHT,
WA_Title, (IPTR)"Rectangles Demo Port",
WA_Flags, WFLG_SIMPLE_REFRESH | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_CLOSEGADGET,
TAG_END))) {
rp = win->RPort;
// Allocate an off-screen bitmap
offbm = AllocBitMap(WIDTH, HEIGHT, DEPTH, BMF_CLEAR, win->RPort->BitMap);
if (!offbm) {
CloseWindow(win);
return 20;
}
// Init a RastPort that uses our bitmap
InitRastPort(&offrp);
offrp.BitMap = offbm;
BOOL running = TRUE;
struct IntuiMessage *msg;
while (running) {
// clear background (set pen 0 and erase)
SetAPen(&offrp, 0);
RectFill(&offrp, 0, 0, win->Width, win->Height);
// set pen color (pen 1)
SetAPen(&offrp, 2);
draw(&offrp);
ClipBlit(&offrp, 0, 0, rp, 0, 0, WIDTH, HEIGHT, 0xC0); // COPY
#if (0)
// Wait for something to happen on the window<6F>s port
WaitPort(win->UserPort);
// Handle events
while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) {
if (msg->Class == IDCMP_CLOSEWINDOW) {
running = FALSE;
}
ReplyMsg((struct Message *)msg);
}
#endif
}
CloseWindow(win);
}
return 0;
}