Jump to content

Bitmap/Bézier curves/Quadratic: Difference between revisions

no edit summary
m (→‎{{header|Wren}}: Minor tidy)
imported>Chinhouse
No edit summary
Line 1,334:
>> disp(img)
</syntaxhighlight>
 
=={{header|MiniScript}}==
This GUI implementation is for use with [http://miniscript.org/MiniMicro Mini Micro].
<syntaxhighlight lang="miniscript">
Point = {"x": 0, "y":0}
Point.init = function(x, y)
p = new Point
p.x = x; p.y = y
return p
end function
 
Img = new Image
Img.create = function(w,h,c)
if c == null then c = color.black
i = Image.create(w,h, c)
j = new Img
j._handle = i._handle
j.width = w
j.height = h
return j
end function
Img.line = function(x0, y0, x1, y1, colr)
sign = function(a, b)
if a < b then return 1
return -1
end function
dx = abs(x1 - x0)
sx = sign(x0, x1)
dy = abs(y1 - y0)
sy = sign(y0, y1)
if dx > dy then
err = dx
else
err = -dy
end if
err = floor(err / 2)
while true
self.setPixel x0, y0, colr
if x0 == x1 and y0 == y1 then break
e2 = err
if e2 > -dx then
err -= dy
x0 += sx
end if
if e2 < dy then
err += dx
y0 += sy
end if
end while
self.setPixel x0, y0, colr
end function
 
Img.quadraticBezier = function(p1, p2, p3, numPoints, colr)
points = []
for i in range(0, numPoints)
t = i / numPoints
u = 1 - t
a = u * u
b = 2 * t * u
c = t * t
x = floor(a * p1.x + b * p2.x + c * p3.x)
y = floor(a * p1.y + b * p2.y + c * p3.y)
points.push(Point.init(x, y))
self.setPixel x, y, colr
end for
for i in range(1, numPoints)
self.line points[i-1].x, points[i-1].y, points[i].x, points[i].y, colr
end for
end function
 
bezierImage = Img.create(480, 480)
p1 = Point.init(50, 100)
p2 = Point.init(200, 400)
p3 = Point.init(360, 55)
 
bezierImage.quadraticBezier p1, p2, p3, 20, color.red
gfx.clear
gfx.drawImage bezierImage, 0, 0
</syntaxhighlight>
 
=={{header|Nim}}==
{{trans|Ada}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.