def draw_objects(self): # global simulation # triangle((0, 0), (0, 200), (350, 100)) background(30, 30, 47) # don't paint obstacles for free run if self.free_run: return fill(50) # shaded are upper quadrant quad((0, 0), (0, 160), (280, 256), (self.shaded_area_x, 0)) quad((0, self.height), (0, 640), (280, 544), (self.shaded_area_x, self.height)) fill(102) triangle((0, 160), (0, 640), (700, 400)) # fishes' start box rect((self.box_left, 335), self.box_width, self.box_width) # replica line for rc in self.replicas_coordinates: line((0, rc[2]), (rc[0], rc[1])) # line((0, 720), (self.replica_x_start, self.replica_y_start)) # shaded area line line((self.shaded_area_x, 0), (self.shaded_area_x, self.height)) # 544 # decision line line((self.decision_x, 0), (self.decision_x, self.height))
def display(self): colour_scale = remap(self.lifespan, (0, self.initial_lifespan), (0, 255)) fill(0, colour_scale, 0, colour_scale) stroke(colour_scale, 0, 0, colour_scale) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate(theta + PI / 2) triangle( (0, -self.size / 2), (-self.size / 4, self.size / 2), (self.size / 4, self.size / 2), ) circle((self.location.x, self.location.y), 5) """ display debug vector lines. Green = acceleration Red = velocity """ # line((self.location.x, self.location.y), # (self.location.x + self.velocity.x * 10, # self.location.y + self.velocity.y * 10)) # stroke(0, 244, 0) # line((self.location.x, self.location.y), # (self.location.x + self.acceleration.x * 100, # self.location.y + self.acceleration.y * 100)) """ Debug end """
def draw(self): if self.frame_rate == 0: p5.background(0, 0, 0) # set initial background to black # action if self.paused: return self.frame_rate += 1 self.update() # MARK: actual drawing p5.background(0, 0, 0, 90) p5.fill(255) p5.stroke(255) p5.rect((self.user.x, self.user.y), self.block_width, self.block_height) p5.rect((self.machine.x, self.machine.y), self.block_width, self.block_height) p5.ellipse((self.ball.x, self.ball.y), 2 * self.ball_radius, 2 * self.ball_radius) if self.draw_prediction and self.last_prediction is not None: p5.no_fill() p5.stroke(220, 0, 0) p5.ellipse((self.width - self.block_width - self.ball_radius, self.last_prediction), 2 * self.ball_radius, 2 * self.ball_radius)
def draw(): global Maps, showGrid p5.background(0) Maps[0].show() if showGrid: p5.stroke(255) p5.no_fill() for x in range(Maps[0].gridWidth+1): x += (width/2)/scl-Maps[0].gridpos.x-0.5 for y in range(Maps[0].gridHeight+1): y += (height/2)/scl-Maps[0].gridpos.y-9/32 p5.begin_shape() p5.vertex(x*scl, y*scl) p5.vertex(x*scl, (y+1)*scl) p5.vertex((x+1)*scl, (y+1)*scl) p5.vertex((x+1)*scl, y*scl) p5.end_shape() if player.walking: Maps[0].move(player) player.walkingAnimation(Maps[0]) if player.walkTimer % player.walkingAnimationTime == 0 and player.stopRequest: player.walking = False player.walkTimer = 0 p5.fill(255, 0, 0, 70) # p5.rect((4*scl+scl*((width/2)/scl-Maps[0].gridpos.x-0.5),4*scl+scl*((height/2)/scl-Maps[0].gridpos.y-9/32)),scl,scl) player.show() print(Maps[0].gridpos.x, Maps[0].gridpos.y)
def graphFunction(): x = xmin while x <= xmax: p.stroke(255, 0, 0) p.fill(0) p.line((x * xscl, f(x) * yscl), ((x + 0.1) * xscl, f(x + 0.1) * yscl)) x += 0.1
def addArrow(self, p1, p2, color=BLACK): p5.stroke(color) self.addLine(p1, p2) to_int = (int(p1[0]), int(p1[1]), int(p2[0]), int(p2[1])) if to_int in ARROW_CACHE: arrow = ARROW_CACHE[to_int] else: p1 = QPoint(*p1) p2 = QPoint(*p2) path = QPainterPath() path.moveTo(p1) path.lineTo(p2) line = QLineF(p1, p2) end = p2 pathlen = path.length() leng = min(10, pathlen / 4.0) arrowbase = path.pointAtPercent(path.percentAtLength(pathlen - leng)) l1 = QLineF(arrowbase, end) l2 = QLineF(arrowbase, end) l1.setAngle(line.angle() - 150) l2.setAngle(line.angle() + 150) l1.setLength(l1.length() / 2.0) l2.setLength(l2.length() / 2.0) arrow = (arrowbase.toTuple(), l1.p2().toTuple(), end.toTuple(), l2.p2().toTuple()) ARROW_CACHE[to_int] = arrow p5.fill(color) p5.quad(*arrow)
def follow(self, path): # calculate future location predicted_location = copy.copy(self.velocity) predicted_location.normalize() predicted_location *= 10 predicted_location += self.location shortest_distance = width # initialise to a large number # check whether future location is on path for i in range(len(path.points) - 1): point_a = path.points[i] point_b = path.points[i + 1] norm = sp.scalar_projection(predicted_location, point_a, point_b) if(norm.x < point_a.x or norm.x > point_b.x): continue distance = Vector.distance(norm, predicted_location) if distance < shortest_distance: shortest_distance = distance direction = point_b - point_a direction.normalize() direction *= 20 target = norm + direction if shortest_distance > path.radius: self.steer(target) if self.debug: line(self._tup(self.location), (self._tup(predicted_location))) fill(255, 0, 0) ellipse((norm.x, norm.y), 10, 10) fill(0, 255, 0) ellipse((target.x, target.y), 10, 10)
def show(self): if (self.blinkCounter > 5): stroke(255, 0, 0) else: stroke(0, 0, 255) fill(0, 0, 255) circle((self.position.x, self.position.y), 10)
def draw(): p.background(0) p.translate(20, 20) for x in range(30): for y in range(30): d = p.dist((30*x, 30*y), (mouse_x, mouse_y)) p.fill(0.5*d, 255, 255) p.rect((30*x, 30*y), 25, 25)
def display(self): """ Display the letter on the window. """ fill(DEFAULT_SENTENCE_COLOR) text_align(DEFAULT_SENTENCE_ALIGNMENT) text_font(self.font) text(self.character, (self.x, self.y))
def draw(): # Arka planı siyah yap p5.background(0) # Orijini pencerenin merkezine taşı p5.translate(width / 2, height / 2) # clock fonsiyonundan gelen değerleri # sırasıyla h, m ve s değişkenlerine ata h, m, s = clock() # Çevre çizgisi çizme p5.no_stroke() # [0, 360) aralığında 6'şar derece aralıklarla değer oluştur # 0, 6, 12, ..., 342, 348, 354 for i in range(0, 360, 6): # Kutupsal koordinat sisteminde # (r_d, i) değerini kartezyen koordinat sistemine dönüştür d_x, d_y = pol2car(r_d, i) # i değeri 30'un tam katıysa, if i % 30 == 0: # saat değerleri için nokta koyacağız p5.fill(255, 0, 0) r = 15 else: # dakika/saniye değerleri için nokta koyacağız p5.fill(255) r = 10 # Belirlenen özelliklerle hesaplanan noktada # bir daire çiz p5.circle((d_x, d_y), r) # Akrep kolunun ucunun konumunu hesala h_x, h_y = pol2car(r_h, h) # Akrep kolunun şekil ayarlarını yap p5.stroke(255) p5.stroke_weight(5) # Akrep konu çiz p5.line((0, 0), (h_x, h_y)) # Yelkovan kolunun ucunun konumunu hesala m_x, m_y = pol2car(r_m, m) # Yelkovan kolunun şekil ayarlarını yap p5.stroke(255) p5.stroke_weight(3) # Yelkovan konu çiz p5.line((0, 0), (m_x, m_y)) # Saniye kolunun ucunun konumunu hesala s_x, s_y = pol2car(r_s, s) # Saniye kolunun şekil ayarlarını yap p5.stroke(255, 0, 0) p5.stroke_weight(1) # Saniye konu çiz p5.line((0, 0), (s_x, s_y))
def display_pointer(self, mass=40): stroke(255) fill(100) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate_z(theta + PI / 2) triangle((0, -mass / 2), (-mass / 4, mass / 2), (mass / 4, mass / 2)) fill(0, 255, 0) circle((self.location.x, self.location.y), 5)
def draw(): global counter counter+=0.01 p5.background(0) p5.fill(0,255,0) p5.stroke(0) #p5.rotate_x(counter) p5.rotate_y(counter) #p5.sphere(300) p5.box(300,300,300)
def draw_midi(t): for i in notes: for j in beats: fill = pg.loc[(j, i), str(t)] if fill == '0': p5.fill(0) else: r, g, b = [int(c) for c in eval(fill)] p5.fill(r, g, b) p5.rect((i * w_scale, j * h_scale), w_scale, h_scale)
def draw(): p.translate(width / 2, height / 2) for x in arange(xmin, xmax, .01): for y in arange(ymin, ymax, .01): z = [x, y] c = [0.285, 0.01] col = julia(z, c, 100) if col == 100: p.fill(0) else: p.fill((3 * col), 255, 255) p.rect((x * xscl, y * yscl), 1, 1)
def draw(): background(250) global point_a global point_b stroke(0) mouse = Vector(mouse_x, mouse_y) line(point_a, mouse) line(point_a, point_b) norm = scalar_projection(mouse, point_a, point_b) fill(255, 0, 0) ellipse((norm.x, norm.y), 10, 10)
def draw(): global sprite p5.background(255) theta = mouse_y # reference shape sprite.draw_pointer() p5.fill(255, 0, 0, 128) # rotate a house shape aboutits centre with p5.push_matrix(): p5.translate(40, 40) p5.rotate(p5.radians(theta)) sprite.draw_house()
def draw_box(qt): no_fill() stroke(255, 0, 0) rect((qt.boundary[0], qt.boundary[1]), qt.boundary[2], qt.boundary[3]) fill(0, 255, 0) stroke(0, 255, 0) if len(qt.points) > 0: for pt in qt.points: ellipse([pt.x, pt.y], 1, 1) if qt.children[0] is not None: for child in qt.children: draw_box(child)
def display(self): stroke(255) fill(255) theta = self.velocity.angle with push_matrix(): translate(self.location.x, self.location.y) rotate_z(theta + PI / 2) triangle( (0, -self.mass / 2), (-self.mass / 4, self.mass / 2), (self.mass / 4, self.mass / 2), ) fill(0, 255, 0) circle((self.location.x, self.location.y), 5)
def draw(self): p5.stroke_weight(0.01) if self.stage > 0: p5.rect((self.bottomLeft.x, self.bottomLeft.y), self.linewidth, -self.height) if self.stage > 1: p5.rect((self.bottomLeft.x, self.bottomLeft.y - self.height), self.width / 2 + self.linewidth / 2, self.linewidth) if self.stage > 2: p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 2, self.bottomLeft.y - self.height), self.linewidth, self.height / 4) if self.stage > 3: p5.no_fill() p5.circle((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 2.5)), self.linewidth * 5, mode="CENTER") if self.stage > 4: p5.fill(255) p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5)), self.linewidth / 2, self.height / 4) if self.stage > 5: p5.rect((self.bottomLeft.x + self.width / 2 - self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + 10), -self.width / 4, self.linewidth / 2) if self.stage > 6: p5.rect((self.bottomLeft.x + self.width / 2 + self.linewidth / 4, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + 10), self.width / 4, self.linewidth / 2) if self.stage > 7: p5.stroke(255) p5.stroke_weight(4) p5.line((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + self.height / 4), (self.bottomLeft.x + self.width - self.width / 4, self.bottomLeft.y - self.height / 12)) if self.stage > 8: p5.line((self.bottomLeft.x + self.width / 2, self.bottomLeft.y - self.height + self.height / 4 + (self.linewidth * 5) + self.height / 4), (self.bottomLeft.x + self.width - self.width * 3 / 4, self.bottomLeft.y - self.height / 12))
def draw(): # pf.image_mode("center") pf.background(255) pf.image(img0,(100,100)) pf.fill(255,0,0) # pf.text_align("LEFT","CENTER") pf.text_size(100) # pf.image_mode("corner") en_str = "hello 你好" pf.text(en_str,(200,200)) pf.rect((100,100), *[100,100])
def draw(): p.translate(width / 2, height / 2) x = xmin while x < xmax: y = ymin while y < ymax: z = [x, y] c = [-0.4, 0.6] col = julia(z, c, 100) if col == 100: p.fill(0) else: p.fill((3 * col), 255, 255) p.rect((x * xscl, y * yscl), 1, 1) y += 0.01 x += 0.01
def rect(self): if self.is_rect: with pf.push_style(): if not self.is_stroke and not self.is_fill: return pf.color_mode("RGB") if self.is_fill: pf.fill(*self.fill_rgb) else: pf.no_fill() if self.is_stroke: pf.stroke_weight(self.stroke_weight) pf.stroke(*self.stroke_rgb) else: pf.no_stroke() pf.rect([self.get_rect_x(), self.get_rect_y()], self.w, self.h)
def draw(): global t, circleList p.background(200) p.translate(width / 4, height / 2) p.no_fill() p.stroke(0) p.ellipse((0, 0), 2 * r1, 2 * r1) p.fill(255, 0, 0) y = r1 * p.sin(t) x = r1 * p.cos(t) circleList = [y] + circleList[:249] p.ellipse((x, y), r2, r2) p.stroke(0, 255, 0) p.line((x, y), (200, y)) p.fill(0, 255, 0) p.ellipse((200, y), 10, 10) for i, c in enumerate(circleList): p.ellipse((200 + i, c), 15, 15) t += 0.1
def displayWord(self, word): self.word = word self.wordLength = len(word) self.spacing = (self.width / (self.wordLength)) / 2 self.offset = (width / 2 - self.width / 2) + self.spacing / 2 self.txt_size = int(self.spacing * 4 / 3) self.GuessFont = p5.create_font("arial.ttf", self.txt_size) p5.text_font(self.GuessFont, self.txt_size) p5.text_align("CENTER", "BASELINE") self.txt_width = p5.text_width("A") for i in range(self.wordLength): p5.fill(255) p5.text(word[i], ((i * 2 * self.spacing) + self.spacing / 2 + self.offset, self.y - (self.txt_width * 4 / 3) - 2)) p5.line((i * 2 * self.spacing + self.offset, self.y), (((i * 2) + 1) * self.spacing + self.offset, self.y))
def draw(): global r1, r2, x1, y1, t, prop, points p.translate(width / 2, height / 2) p.background(255) p.no_fill() p.stroke(0) p.ellipse((x1, y1), 2 * r1, 2 * r1) x2 = (r1 - r2) * p.cos(t) y2 = (r1 - r2) * p.sin(t) p.ellipse((x2, y2), 2 * r2, 2 * r2) x3 = x2 + prop * (r2 - r3) * p.cos(-((r1 - r2) / r2) * t) y3 = y2 + prop * (r2 - r3) * p.sin(-((r1 - r2) / r2) * t) p.fill(255, 0, 0) p.ellipse((x3, y3), 2 * r3, 2 * r3) points = [[x3, y3]] + points[:2000] for i, d in enumerate(points): if i < len(points) - 1: p.stroke(255, 0, 0) p.line((d[0], d[1]), (points[i + 1][0], points[i + 1][1])) t += 0.1
def draw(): # pf.image_mode("center") # pf.tint() # img_size[0]-=1 pf.background(255) # pf.image(img0,(100,100)) pf.text_font(font) # pf.stroke_weight(0) pf.text_align("center", "center") # pf.stroke(255,0,0) # pf.no_fill() pf.text_size(100) en_str = "hello 你好" pf.fill(255, 0, 0) gap = 100 height = 20 pf.text(en_str, (50, height)) pf.stroke(0, 0, 255) pf.stroke_weight(5) height += gap pf.text(en_str, (50, height)) pf.stroke_weight(-5) height += gap pf.text(en_str, (50, height)) pf.no_fill() height += gap pf.stroke_weight(5) pf.text(en_str, (50, height)) height += gap pf.stroke_weight(-5) pf.text(en_str, (50, height))
def draw(): global planet, moon p5.fill(255) if not moon.finished: p5.background(0) p5.scale(1, -1) p5.translate(0, -height) moon.collide(planet) moon.update(planet, G) #planet.update(moon,G) p5.no_fill() p5.stroke(255, 60) #p5.circle((planet.pos.x,planet.pos.y),2*abs(moon.relpos(planet))) p5.fill(10, 173, 73) p5.stroke(0) planet.show() p5.fill(0, 0, 255) p5.stroke(0, 0, 255) moon.show()
def show(self): # find line showing boid direction y_angle = math.atan(self.velocity[1] / self.velocity[0]) x_angle = math.atan(self.velocity[0] / self.velocity[1]) larger = x_angle if x_angle > y_angle else y_angle lsign = -1 if larger < 0 else 1 norm_x = x_angle / (10.0 * lsign) norm_y = y_angle / (10.0 * lsign) x_mult = -1 if self.velocity[0] < 0 else 1 y_mult = -1 if self.velocity[1] < 0 else 1 x_point_coord = self.position[0] + (x_mult * norm_x * 100) y_point_coord = self.position[1] + (y_mult * norm_y * 100) # show the boid on the grid stroke(255) fill(255) circle(self.position, 9) stroke("red") line(self.position, (x_point_coord, y_point_coord))
def draw(): # Arka alanı siyah yap p5.background(0) # Orijini (Yani (0, 0) noktasını) pencerenin ortasına taşı p5.translate(w / 2, h / 2) # Analog saatte, saat değerlerinin olduğu konumlara # kırmızı noktalar koymak için döngü # [0, 360) aralığında 30'ar derece açılarla değer oluştur: # Böylece 0, 30, 60, ..., 270, 300, 330 değerleri elde edilecek for i in range(0, 360, 30): # Her bir açı için x ve y konumlarını hesapla x = r * math.cos(math.radians(i)) y = r * math.sin(math.radians(i)) # Çizilecek nesnenin içini kırmızı renk ile doldur p5.fill(255, 0, 0) # Çizilecek nesne için çevre çizgisi çizme p5.no_stroke() # x ve y konumuna 15 piksel çapında bir daire çiz. p5.circle((x, y), 15) # Analog saatte, dakika değerlerinin olduğu konumlara # beyaz noktalar koymak için döngü # [0, 360) aralığında 6'şar derece açılarla değer oluştur: # Böylece 0, 6, 12, ..., 342, 348, 354 değerleri elde edilecek for u in range(0, 360, 6): # Eğer u açısı 30'a tm bölünebiliyorsa işlemi YAPMA if u % 30: # Her bir açı için x ve y konumlarını hesapla x = r * math.cos(math.radians(u)) y = r * math.sin(math.radians(u)) # Çizilecek nesnenin içini beyaz renk ile doldur p5.fill(255) # Çizilecek nesne için çevre çizgisi çizme p5.no_stroke() # x ve y konumuna 10 piksel çapında bir daire çiz. p5.circle((x, y), 10)