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

imported>Chinhouse
No edit summary
imported>Chinhouse
 
Line 1,345:
end function
 
Img.linedrawLine = function(img, x0, y0, x1, y1, colr)
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
Line 1,375 ⟶ 1,365:
while true
selfimg.setPixel x0, y0, colr
if x0 == x1 and y0 == y1 then break
e2 = err
Line 1,387 ⟶ 1,377:
end if
end while
self.setPixel x0, y0, colr
end function
 
Img.quadraticBezier = function(img, p1, p2, p3, numPoints, colr)
points = []
for i in range(0, numPoints)
Line 1,402 ⟶ 1,391:
y = floor(a * p1.y + b * p2.y + c * p3.y)
points.push(Point.init(x, y))
selfimg.setPixel x, y, colr
end for
for i in range(1, numPoints)
self.linedrawLine img, points[i-1].x, points[i-1].y, points[i].x, points[i].y, colr
end for
end function
 
bezierImagebezier = ImgImage.create(480, 480)
p1 = Point.init(50, 100)
p2 = Point.init(200, 400)
p3 = Point.init(360, 55)
 
bezierImage.quadraticBezier bezier, p1, p2, p3, 20, color.red
gfx.clear
gfx.drawImage bezierImagebezier, 0, 0
</syntaxhighlight>
 
Anonymous user