python - How to make dots change color when they land in a box -


this question exact duplicate of:

from turtle import * random import randint speed("fastest")  pendown() goto(200, 0) goto(200, 200) goto(0, 200) goto(0,0) goto(200,200)   area_size = 800  max_coord = area_size / 2  num_dots = 300   setup(area_size, area_size)  _ in range(num_dots):      dots_pos_x = randint(-max_coord, max_coord)     dots_pos_y = randint(-max_coord, max_coord);  if dots_pos_y > dots_pos_x , dots_pos_y <= 200:     elif dots_pos_y <= dots_pos_x <= 200:     else:  hideturtle() done() 

ok code draws square line splitting making 2 equal triangles, , generates 300 randomly places dots on screen. want know how can dots land in 1 half of square turn red , when land in other half of square want them turn blue. , ones don't land in box stay black?

any appreciated.

i suppose if square rectangle, have these properties:

x = 0 y = 0 width = 200 height = 200 

and line consist of these 2 points:

a(0,0) b(200,200) 

supposing x,y coordinates begin upper-left corner then:

if dots_pos_y > dots_pos_x , dots_pos_y <= 200:       # dot landed on lower half of square  elif dots_pos_y <= dots_pos_x , dots_pos_x <= 200:       # dot landed on upper half of square  else:      # dot did not land on square 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -