openrndr icon indicating copy to clipboard operation
openrndr copied to clipboard

Batch Mode individual draw style

Open mhaqs opened this issue 5 years ago • 4 comments

Describe the bug The batch mode methods like drawer.circles and drawer.rectangles lock in on the style that was set before the method call. The individual classes should have a way to set them before rendering.

To Reproduce

drawer.circles((0 until 100).map{
drawer.fill = ColorRgba(Random.nextDouble(1.0), Random.nextDouble(1.0), Random.nextDouble(1.0)
Circle(Random.nextDouble(width), Random.nextDouble(height), 10.0)
})

Expected behavior All circles should have a random colour

Context:

  • macOS 10.14.6
  • OpenRNDR 0.3.35
  • 1.8

mhaqs avatar Sep 17 '19 01:09 mhaqs

Hi @mhaqs while I understand the intention and the need for drawing methods that allow a way of working similar to what you propose, it is not exactly a bug. Drawer.circles uses one fill and stroke color for the entire list. Your code changes the fill color while constructing the list (in strict evaluation order), at the time circles is invoked it only sees the last color set and continues to draw with that.

edwinRNDR avatar Sep 25 '19 08:09 edwinRNDR

Thanks for responding @edwinRNDR. I may have made an error in expressing the intent here:

val circles = ArrayList<Circle>
for (i in 0 until 100) {
drawer.fill = ColorRgba(Random.nextDouble(1.0), Random.nextDouble(1.0), Random.nextDouble(1.0)
arrayList.add(Circle(Random.nextDouble(width), Random.nextDouble(height), 10.0))
}
drawer.circles(circles)

I'm not reporting a bug, but a feature request where I want each Circle to have a different color but still use the batch circles method.

I see that circles has overloads for accepting radii for all individual circles in the list. A similar approach for styles could be taken? Although, I see how that would require a bit of work.

mhaqs avatar Sep 28 '19 07:09 mhaqs

@edwinRNDR I believe this has been addressed with drawer.circleBatch?

ricardomatias avatar Nov 30 '20 10:11 ricardomatias

As @ricardomatias mentioned, two examples of circle batches with unique fill and stroke properties:

  • https://github.com/openrndr/orx/blob/master/openrndr-demos/src/demo/kotlin/DemoCircleBatch02.kt
  • https://github.com/openrndr/orx/blob/master/openrndr-demos/src/demo/kotlin/DemoCircleBatch03.kt

There is drawer.circleBatch, drawer.pointBatch and drawer.rectangleBatch.

Issue can be closed?

hamoid avatar Jan 31 '21 15:01 hamoid