File:Pixel vs subpixel precision.gif

From Vigyanwiki

Pixel_vs_subpixel_precision.gif(256 × 128 pixels, file size: 5 KB, MIME type: image/gif, looped, 46 frames, 2.3 s)

This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

Summary

Description
English: This is a simple animation, created with Python, that compares side-by-side pixel precision vs subpixel precision in line rasterization.
Date
Source Own work
Author Drummyfish
Source code
InfoField
# Simple animation showing pixel vs subpixel accuracy.
# by Miloslav Ciz, released under CC0 1.0

from PIL import Image
import math

SCALE = 8

FRAMES = 64

RESOLUTION = (32,16)

img = Image.new("RGB",(RESOLUTION[0] * SCALE,RESOLUTION[1] * SCALE),"white")

pixels = img.load()

def drawLine(p0, p1):
  slope = (p1[1] - p0[1]) / float(p1[0] - p0[0])

  for i in range(int(p1[0] - p0[0] + 1)):
    x = round(p0[0] + i) * SCALE
    y = round(p0[1] + i * slope) * SCALE

    for b in range(SCALE):
      for a in range(SCALE):
        pixels[x + a,y + b] = (0,0,0)

for f in range(FRAMES):
  img.paste((255,255,255),(0,0,img.size[0],img.size[1]))

  t = f / float(FRAMES) * math.pi * 2

  x0 = 3
  x1 = 13

  y0 = 8 + math.sin(t) * 3
  y1 = 7 + math.cos(t)

  x0 += (RESOLUTION[0] / 2)
  x1 += (RESOLUTION[0] / 2)

  drawLine((x0,y0),(x1,y1))

  x0 -= (RESOLUTION[0] / 2)
  x1 -= (RESOLUTION[0] / 2)

  y0 = round(y0)
  y1 = round(y1)

  drawLine((x0,y0),(x1,y1))

  for i in range(RESOLUTION[1] * SCALE):
    pixels[int(RESOLUTION[0] * SCALE / 2),i] = (0,0,0)

  img.save("out" + str(f).zfill(2) + ".png")

Licensing

I, the copyright holder of this work, hereby publish it under the following licence:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighbouring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Captions

Add a one-line explanation of what this file represents
Animation comparing pixel vs subpixel precision.

Items portrayed in this file

depicts

4 July 2019

image/gif

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current05:19, 5 July 2019Thumbnail for version as of 05:19, 5 July 2019256 × 128 (5 KB)wikimediacommons>DrummyfishUser created page with UploadWizard

Metadata