I'm both new to stack overflow and programming in general. I'm doing a basic python course at university and I've got to hand in a final project soon. I decided to try making some generative art in Python mode in Processing. My plan is to create a basic (abstracted) image of the skyline of a city by using lines of various length, height and color, with some semi-random spacing in between the lines. I've written some code that is able to do it to a degree. However, I am struggling to write it in a way that obeys some of the global variables I define at the start. I do likely get 50 lines but they don't cover the entire image and frequently overlap one another, making it difficult to tell them apart. Plus, I would like to incorporate some code which would specify where the buildings end, to get even blank space on the left and right side of the image. I tried using the building_start and building_end variables for this but clearly my way of adding separation between the buildings is off. Could you help me out with this?
Thanks in advance. The code and its output is shown below.
import random as rd
w, h = 1000, 500
building_start = 25
building_end = 975
n_buildings = 50
building_sep = (building_end - building_start)/(n_buildings*1.2)
roof_style = [ROUND, SQUARE]
def setup():
size(w,h)
background(60, 60, 60)
building_x = building_start
building_y = 500
for i in range(n_buildings):
building_x = building_sep * i
building_top = rd.randrange(50, 370, 10)
line(building_x, building_y, building_x, building_y - building_length)
stroke(rd.randint(200, 255), rd.randint(200, 255), rd.randint(200, 255))
strokeWeight(rd.randrange(10, 28, 2))
strokeCap(rd.choice(roof_style))
noFill()
rect(0, 0, 1000, 500)
stroke(255, 247, 247)
Aucun commentaire:
Enregistrer un commentaire