Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
numbers:graphics [2012/11/01 11:26] 127.0.0.1 editor externo |
numbers:graphics [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 283: | Línea 283: | ||
| * [[http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]] | * [[http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]] | ||
| * [[http://devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/2/#top1]] | * [[http://devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/2/#top1]] | ||
| + | |||
| + | ===== Ecuaciones de formas ===== | ||
| + | ==== Elipse ==== | ||
| + | <code python> | ||
| + | import pygame | ||
| + | from pygame.locals import * | ||
| + | import sys | ||
| + | import math | ||
| + | w = 640 | ||
| + | h = 489 | ||
| + | screen = pygame.display.set_mode((w,h)) | ||
| + | |||
| + | sampling = 50 | ||
| + | r1 = 100 | ||
| + | r2 = 160 | ||
| + | |||
| + | def drawPoint (x,y, c=(255,0,0)): | ||
| + | centX = w/2 | ||
| + | centY = h/2 | ||
| + | nx = centX + x | ||
| + | ny = centY + y | ||
| + | pygame.draw.circle(screen, c, (int(nx), int(ny)), 1) | ||
| + | |||
| + | for i in range(sampling): | ||
| + | theta = i * (2. * 3.1421)/sampling | ||
| + | cosTheta = math.cos(theta) | ||
| + | sinTheta = math.sin(theta) | ||
| + | tmp1 = (cosTheta*cosTheta)/(r2*r2) | ||
| + | tmp2 = (sinTheta * sinTheta)/(r1*r1) | ||
| + | tmp = math.sqrt(tmp1+tmp2) | ||
| + | drawPoint(cosTheta/tmp, sinTheta/tmp) | ||
| + | |||
| + | pygame.display.flip() | ||
| + | |||
| + | while True: | ||
| + | for event in pygame.event.get(): | ||
| + | if event.type == QUIT: | ||
| + | sys.exit() | ||
| + | pygame.display.update() | ||
| + | </code> | ||