Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resulting photos are composed through the application of a stack of Lenses. #4

Open
2 tasks
zspencer opened this issue Aug 24, 2020 · 0 comments
Open
2 tasks
Assignees
Labels
code Hone your programming skills! epic Work that can't be completed in a single session refactor Hone your refactoring and architecture skills test Improvements or additions to test coverage
Milestone

Comments

@zspencer
Copy link
Member

zspencer commented Aug 24, 2020

TODO

  • Move the feature definition into the repository (@zspencer)
  • Wire in the step definitions (@zspencer)

Feature Definition

Feature: Unique Photos
  In order to know my photography is one-of-a-kind
  I want to be able to re-apply a unique set of lenses to a photo

  @built @steps-unimplemented
  Scenario: Taking a Photo applies a unique result
    Given I have opened the Camera
    When I take a Photo
    Then the Photo has a new unique filter applied

  @built @steps-unimplemented
  Scenario: Choosing a Photo applies a unique result
    Given I have opened the Photo Picker
    When I select a Photo
    Then the Photo has a new unique filter applied

  @built  @steps-unimplemented
  Scenario: Tapping a Photo re-applies a new unique result
    Given a Photo has had a unique filter applied
    When I tap the Photo
    Then the Photo has a new unique filter applied

Architecture / Example Code

Q&A:

  • How do I generate the same fingerprint over and over? If we make the fingerprint a seeded random number generator we'll be able to save that seed and it will create the same stack of lenses with the same filters and filter parameters.

  • How do the pieces fit together? Below is an example potential design, sketched in Ruby; so it may not translate directly to Swift.
    Image from iOS(1)

# We generate a new fingerprint every time someone taps on a photo
fingerprint = Fingerprint.new


# The fingerprint is used to pick the filters, and then shuffle them around to build a LensStack.
# Keep in mind, with seeded random number generators, they generate the _same answers in sequence_ not _the same answer every time_; so order of operations (i.e. `random` then `sample` then `shuffle`)  generates different results than `shuffle` then `random` then `sample`)
lens_stack = fingerprint.shuffle(fingerprint.sample(Filter.all, fingerprint.random(4..6))).map do |filter|
  Lens.new(filter.new, fingerprint)
end

# Once we have the lens_stack, we can squeeze a photo through it, and apply each lens to the photo
result  = lens_stack.reduce(photo) do |in_process_photo, lens|
  lens.apply(in_process_photo)
end


class Filter
  def set_parameters(fingerprint)
    raise NotImplementedError('Implement me in child classes')
  end

  def transform(photo)
    raise NotImplementedError('Implement me in child classes')
   end
end

class GaussianBlur < Filter
  attr_accessor :intensity
  def set_parameters(fingerprint)
    this.intensity = fingerprint.rand(0..100)
  end
  def transform(photo)
    wiggle(photo, intensity)
  end
end

class Sepia < Filter
end


# Random Number Seed Generator
class Fingerprint
  def initialize(seed: SecureRandom.uuid)
    self.seed = seed
  end

  def rand(range)
  end
end

class Lens
  attr_accessor :fingerprint, :photo
  def apply(photo)
    filter.set_parameters(fingerprint)
    filter.transform(photo)
  end
end
@zspencer zspencer added code Hone your programming skills! test Improvements or additions to test coverage refactor Hone your refactoring and architecture skills labels Aug 24, 2020
@zspencer zspencer added this to the 3.5.1 milestone Aug 24, 2020
@zspencer zspencer added the epic Work that can't be completed in a single session label Aug 24, 2020
zspencer added a commit that referenced this issue Sep 7, 2020
See: #4

As we learn how to Swift; we're stepping away from the SwiftUI/etc.
system and focusing more on building a library for doing the filtering.

We'll start with downloading a file from the Internet, saving it, then
running it through a LensStack, and saving a copy at each stage.

This way, we can start to diagnose if/how the filters are working
without futzing about with SwiftUI; which adds a confounding factor when
trying to figure things out.
@zspencer zspencer mentioned this issue Sep 7, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Hone your programming skills! epic Work that can't be completed in a single session refactor Hone your refactoring and architecture skills test Improvements or additions to test coverage
Projects
None yet
Development

No branches or pull requests

2 participants