Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions examples/starrect.pics
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

IO :: import std.io
Virtual :: import std.virtual
Render :: import piccode.render

drawStar :: (ctx, padding=0) =
ctx
|> Render::drawLine(50+padding, 50+padding, 150-padding, 150-padding)
|> Render::drawLine(150-padding, 50+padding, 50+padding, 150-padding)
|> Render::drawLine(50+padding, 100, 150-padding, 100)
|> Render::drawLine(100, 50+padding, 100, 150-padding)

drawRect :: (ctx, x, y, w, h) =
ctx
|> Render::drawLine(x, y, x + w, y)
|> Render::drawLine(x, y + h, x + w, y + h)
|> Render::drawLine(x, y, x, y + w)
|> Render::drawLine(x + w, y, x + w, y + h)
Comment on lines +13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the rectangle drawing bug.

There's an error in Line 17 where y + w should be y + h for drawing the left vertical line of the rectangle.

-   |> Render::drawLine(x, y, x, y + w)
+   |> Render::drawLine(x, y, x, y + h)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
drawRect :: (ctx, x, y, w, h) =
ctx
|> Render::drawLine(x, y, x + w, y)
|> Render::drawLine(x, y + h, x + w, y + h)
|> Render::drawLine(x, y, x, y + w)
|> Render::drawLine(x + w, y, x + w, y + h)
drawRect :: (ctx, x, y, w, h) =
ctx
|> Render::drawLine(x, y, x + w, y)
|> Render::drawLine(x, y + h, x + w, y + h)
|> Render::drawLine(x, y, x, y + h)
|> Render::drawLine(x + w, y, x + w, y + h)
🤖 Prompt for AI Agents
In examples/starrect.pics around lines 13 to 18, the rectangle drawing function
uses y + w instead of y + h on line 17, causing the left vertical line to be
drawn incorrectly. Change y + w to y + h in the call to Render::drawLine on line
17 to correctly draw the left vertical edge of the rectangle.


drawDepth :: (ctx) =
ctx
|> Render::drawLine(150, 50, 200, 70)
|> Render::drawLine(150, 150, 200, 170)
|> Render::drawLine(50, 150, 100, 170)

drawBackLines :: (ctx) =
ctx
|> Render::drawLine(100, 170, 200, 170)
|> Render::drawLine(200, 70, 200, 170)

main :: () =
let
ctx := Render::getContext()
in
ctx
|> drawRect(50, 50, 100, 100)
|> drawDepth
|> drawBackLines
|> drawStar(10)




25 changes: 23 additions & 2 deletions piccode/render/context.pics
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@


// Module: Render
// Functions for working with the editor render context
Render :: module {
// Function: getContext
// returns the render context (A handle to the Render window on the screen)
//
// Parameters:
// None
//
// Returns:
// - (Object) an handler to the Graphics2D.
getContext :: () = pic_nat_get_gfx()


// Function: drawLine
// Draws a line inside the specified context, based on the provided coordinates
//
// Parameters:
// ctx - (Object) The graphic context
// startx - (Number) The start x position
// starty - (Number) The start y position
// endx - (Number) The end x position
// endy - (Number) The end y position
//
// Returns:
// - (Object) A modified context with the rendered element.
drawLine :: (ctx, startx, starty, endx, endy) = pic_nat_draw_line(ctx, startx, starty, endx, endy)
}

Loading