Skip to content

In classical render loop stroke color changes are ignored when drawing only with lines #796

@weirdnik

Description

@weirdnik

I'm programming a sci-fi HUD animation, which is drawn mostly with lines, code below. When drawing with lines, stroke changes are ignored after the first one, unless there is a ellipse or rectangle drawn with the new stroke color.

The code is below, and three images are attached: the first one is when no ellipses are drawn, the whole HUD is drawn with the color of the first stroke, the second one is when the "useless elipse" is drawn off-scereen but only text is drawn in the "elliptical dots HUD" loop, and the third one is the intended look when both text and ellipses are drawn in that loop.

Image Image Image
def draw(self):
	
	tilt = self.vector - Vec3(*gravity().as_tuple())
	if not abs(tilt):
		tilt = Vec3(random()/10, random()/9, random()/11)
	
	if not self.counter % 50:
		self.tx = tilt.x
	if not self.counter % 5:
		self.tz = tilt.z
	if not self.counter % 2:
		if  abs(tilt.y) * 10 > abs(self.arcvb): self.arcvb = tilt.y * 10

	self.arcvb = self.arcvb * 0.99
	self.posb = self.posb + self.arcvb

	if abs(tilt.x) * 10 > abs(self.arcvy):
		self.arcvy = tilt.x * 10
	self.arcvy = self.arcvy * 0.9
	self.posy = self.posy + self.arcvy
	
	### drawing starts 
				
	translate(*self.half)
	push_matrix()
	
	background ('red')

	#blend_mode(BLEND_ADD)
						
	# static elements
	stroke_weight(2)
	stroke('white')
	#no_fill()
	fill(0,0.2,0.2,0.5)

	dx = min(self.half.w, self.half.h)-20*SCALE
	rect(dx*-1,dx*-1,2*dx,2*dx)	
	txt = str(self.tz).split('.')[-1][:3]
	text(str(txt), 'SF Mono', 20, -1*dx+10, -1*dx+10, 9)	

	# yellow hud

	rotate(self.posy)

	stroke('yellow')  # THIS ONE GETS IGNORED
	stroke_weight(8)

	# useless elipse
	ellipse(-1000,-1000, 10 , 10 ) # without this ellipse changing stroke color to yellow is ignored 

	for _arc in range(12):
		_arc = _arc * 5 + 15
		rotate(_arc)
		r = 200 if IPAD else 125
		r_ = r + 25
		line(r, 0, r_, 0)
	
	# black hud
	
	rotate(self.posb)

	stroke_weight(1)
	stroke('black')
	fill('pink')

	for i in range(6):  # elliptical dots HUD
		text('❮', 'Zapf Dingbats ITC', 10, self.tz*dx, 0, 5)
		ellipse(dx*self.tz,  -2.5, 15, 5).    # stroke changes to black only if those ellpses are drawn
		rotate(60)

	txt = str(self.tx).split('.')[-1][:3]
	text(str(txt), 'SF Mono', 20, 75, 10, 5)

	stroke_weight(4)
	for start, end in self.MODEL:
		line (*(start+end))
	
	self.counter += 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions