Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Textured polygons helper functions
#2
(03-06-2024, 03:58 PM)Marcus Wrote: 'draw poly image' can be hard to use and make sense of, so here is an example program with some helper functions.

Awesome, I can make a rabbit with alien skin  Big Grin 
   
click to zoom in the image

Thank you, Marcus, for creating poly* familes in Naalaa  Cool
I would like to summarize what I have learned so far.
Comparing the difference between coordinates and how each one is used for :
- Polyline     which can be generated using Poly_Editor.exe (Naalaa 6). To be used as a PATH
- Polyimage which needs some adjustment for texture                        To be used as a TEXTURE
- Polygon     which needs some adjustment to move each point           To be used as a SHAPE

Code:
'-----------------
' INITIALIZATION
'-----------------
include "assets/polyline.n7"
include "assets/polyimage.n7"
set window "Rabbit's Face", 640, 480
set redraw off

'color definition
black_alpha = [0,0,0,24]
white       = [255,255,255]
red         = [255,0,0]

'------ Polyline --------
'made by Poly_Editor.exe (N6)
rabbit_ =
[[-160, -160], [-60, -120], [-40, -40],
[40, -40], [60, -120], [160, -160],
[120, -60], [60, -40], [120, 40],
[120, 80], [80, 120], [0, 140],
[-80, 120], [-120, 80], [-120, 40],
[-60, -40], [-120, -60],[-160,-160]]
path = PolyLine(rabbit_)
distance    = 1
move_pixel  = 4

'------- Polyimage --------
'rabbit polygon, 0 = textures
rabbit = [
-160, -160, 0,0,-60, -120, 0,0,-40, -40,0,0,
40, -40, 0,0, 60, -120, 0,0, 160, -160, 0,0,
120, -60,0,0, 60, -40,0,0, 120, 40, 0,0,
120, 80, 0,0, 80, 120, 0,0, 0, 140, 0,0,
-80, 120,0,0, -120, 80,0,0, -120, 40,0,0,
-60, -40,0,0, -120, -60,0,0]
texture = loadimage("assets/texture_alien.png")
MapPolyImageCoords(rabbit, texture)         

'-------- Polygon ------------
x = width(primary)/2; y = height(primary)/2; s = 1
rab_bit =
[-160+x, -160+y, -60+x, -120+y,     -40+x, -40+y,
40+x, -40+y,     60+x, -120+y,      160+x, -160+y,
120+x, -60+y,    60+x, -40+y,       120+x, 40+y,
120+x, 80+y,     80+x, 120+y,       0+x, 140+y,
-80+x, 120+y,   -120+x, 80+y,       -120+x, 40+y,
-60+x, -40+y,   -120+x, -60+y,      -160+x,-160+y]

'------------
' MAIN LOOP
'------------
while not keydown(KEY_ESCAPE)
    set color black_alpha;cls
    set color white

    '------- Polyimage --------                 
    DrawPolyImageXform(texture, rabbit, x, y, s, s, 0)
   
    '------ Polyline --------
    distance = (distance + move_pixel)%path.GetLength()
    pos = path.GetPoint(distance,false)
    draw ellipse pos[0]+width(primary)/2, pos[1]+height(primary)/2, 4, 4, 1

    '------- Polygon ---------
    set color red
    draw poly rab_bit,0

    redraw
    fwait 30
wend


Attached Files
.zip   rabbit.zip (Size: 61.52 KB / Downloads: 4)
Reply


Messages In This Thread
Textured polygons helper functions - by Marcus - 03-06-2024, 03:58 PM
RE: Textured polygons helper functions - by 1micha.elok - 03-07-2024, 09:35 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)