Основная программа:
Библиотека:
Результат работы программы:
Код: Выделить всё
// Test of complex type MyCircle
import MyCircle
open window 640, 480
backcolor 255, 255, 255
clear window
circle1 = MyCircle.create(0, 100, 100, 25) // create a circle in coords cx, cy with radius = 25. By default, color "0,0,0" (black) and no filler mode
print "Identification of item = ", circle1
MyCircle.draw(circle1)
pause 1
MyCircle.move(circle1, 200, 200)
pause 1
MyCircle.resize(circle1, 50)
pause 1
MyCircle.colorize(circle1, "255, 0, 0", true)
pause 1
MyCircle.destroy(circle1)
pause 1
circle2 = MyCircle.create(0, 300, 200, 75, "0, 0, 255", true)
print "Identification of item = ", circle2 // "reuse" the identificator
MyCircle.draw(circle2)
pause 1
circle3 = MyCircle.create(circle2) // create a new object with attributes of other (is a copy)
print "Identification of item = ", circle3 // new identificator
MyCircle.move(circle3, 100, 100) // Hey! Where is my first circle?
pause 1
MyCircle.draw(circle2) // Luckily!
pause 1
MyCircle.colorize(circle3, "0, 255, 0") // So I can already tell them apart.
Код: Выделить всё
// Yabasic 2.78, by Galileo, 02/2018
// Complex type and functions type
// Type defined: MyCircle
items = 1
type() // Initialize array of type objects
items = 0
ps = 1
dim stack(ps) // Free storage stack
ps = 0
sub type() // Complex type MyCircle
dim cx(items) // Coordenate x of the center
dim cy(items) // Coordenate y of the center
dim radius(items) // Circle radius
dim col$(items) // Circle colour in mode "red, green, blue" (0 to 255 each of)
dim mode(items) // Fill mode (true or false)
end sub
sub copy(dest, orig)
cx(dest) = cx(orig)
cy(dest) = cy(orig)
radius(dest) = radius(orig)
col$(dest) = col$(orig)
mode(dest) = mode(orig)
end sub
sub create(parent, cx, cy, radius, col$, mode)
local item
item = stack(ps)
if not item then
items = items + 1
item = items
type()
else
stack(ps) = 0
ps = ps - 1
end if
if parent then
copy(item, parent)
else
cx(item) = cx
cy(item) = cy
radius(item) = radius
if col$ = "" col$ = "0, 0, 0"
col$(item) = col$
mode(item) = mode
end if
return item
end sub
sub destroy(item)
erase(item)
ps = ps + 1
stack(ps) = item
end sub
sub erase(item)
if mode(item) then
clear fill circle cx(item), cy(item), radius(item)
else
clear circle cx(item), cy(item), radius(item)
end if
end sub
sub draw(item)
color col$(item)
if mode(item) then
fill circle cx(item), cy(item), radius(item)
else
circle cx(item), cy(item), radius(item)
end if
end sub
sub move(item, cx, cy)
erase(item)
cx(item) = cx : cy(item) = cy
draw(item)
end sub
sub resize(item, radius)
erase(item)
radius(item) = radius
draw(item)
end sub
sub colorize(item, col$, mode)
erase(item)
col$(item) = col$
if numparams = 3 mode(item) = mode
draw(item)
end sub